Skip to content

Commit 8f91045

Browse files
author
Rasmus Oscar Welander
committed
Adapted CI to build and install the package
1 parent 50ac90b commit 8f91045

File tree

4 files changed

+54
-40
lines changed

4 files changed

+54
-40
lines changed

.github/workflows/ci-tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ jobs:
3232
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3333
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide, we further relax this
3434
flake8 . --count --exit-zero --max-complexity=30 --max-line-length=130 --statistics
35-
35+
- name: Build
36+
run: |
37+
pip install build
38+
python -m build
39+
- name: Install
40+
run: |
41+
pip install .
3642
- name: Test with pytest
3743
run: |
3844
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi

README.md

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ Alternatively, you can clone this repository and install manually:
3737
```bash
3838
git clone [email protected]:cs3org/cs3-python-client.git
3939
cd cs3-python-client
40-
pip install -e .
41-
export PYTHONPATH="path/to/cs3-python-client/:$PYTHONPATH"
40+
pip install .
4241
```
4342

4443

@@ -112,129 +111,136 @@ lock_expiration = 1800
112111

113112
To use `cs3client`, you first need to import and configure it. Here's a simple example of how to set up and start using the client. For configuration see [Configuration](#configuration). For more in depth examples see `cs3-python-client/examples/`.
114113

115-
### Initilization
114+
### Initilization and Authentication
116115
```python
117116
import logging
118117
import configparser
119-
from cs3client import CS3Client
120-
from cs3resource import Resource
118+
from cs3client.cs3client import CS3Client
121119

122120
config = configparser.ConfigParser()
123121
with open("default.conf") as fdef:
124122
config.read_file(fdef)
125-
126123
log = logging.getLogger(__name__)
127124

128125
client = CS3Client(config, "cs3client", log)
129-
# client.auth.set_token("<your_token_here>")
130-
# OR
126+
127+
# Set client secret
131128
client.auth.set_client_secret("<your_client_secret_here>")
129+
# Checks if token is expired if not return ('x-access-token', <token>)
130+
# if expired, request a new token from reva
131+
auth_token = client.auth.get_token()
132+
133+
# OR if you already have a reva token
134+
# Checks if token is expired if not return (x-access-token', <token>)
135+
# if expired, throws an AuthenticationException (so you can refresh your reva token)
136+
token = "<your_reva_token>"
137+
auth_token = client.auth.check_token(token)
132138
```
133139

134140
### File Example
135141
```python
136142
# mkdir
137143
directory_resource = Resource.from_file_ref_and_endpoint(f"/eos/user/r/rwelande/test_directory")
138-
res = client.file.make_dir(directory_resource)
144+
res = client.file.make_dir(client.auth.get_token(), directory_resource)
139145

140146
# touchfile
141147
touch_resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande/touch_file.txt")
142-
res = client.file.touch_file(touch_resource)
148+
res = client.file.touch_file(client.auth.get_token(), touch_resource)
143149

144150
# setxattr
145151
resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande/text_file.txt")
146-
res = client.file.set_xattr(resource, "iop.wopi.lastwritetime", str(1720696124))
152+
res = client.file.set_xattr(client.auth.get_token(), resource, "iop.wopi.lastwritetime", str(1720696124))
147153

148154
# rmxattr
149-
res = client.file.remove_xattr(resource, "iop.wopi.lastwritetime")
155+
res = client.file.remove_xattr(client.auth.get_token(), resource, "iop.wopi.lastwritetime")
150156

151157
# stat
152-
res = client.file.stat(resource)
158+
res = client.file.stat(client.auth.get_token(), resource)
153159

154160
# removefile
155-
res = client.file.remove_file(touch_resource)
161+
res = client.file.remove_file(client.auth.get_token(), touch_resource)
156162

157163
# rename
158164
rename_resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande/rename_file.txt")
159-
res = client.file.rename_file(resource, rename_resource)
165+
res = client.file.rename_file(client.auth.get_token(), resource, rename_resource)
160166

161167
# writefile
162168
content = b"Hello World"
163169
size = len(content)
164-
res = client.file.write_file(rename_resource, content, size)
170+
res = client.file.write_file(client.auth.get_token(), rename_resource, content, size)
165171

166172
# listdir
167173
list_directory_resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande")
168-
res = client.file.list_dir(list_directory_resource)
174+
res = client.file.list_dir(client.auth.get_token(), list_directory_resource)
169175

170176

171177
# readfile
172-
file_res = client.file.read_file(rename_resource)
178+
file_res = client.file.read_file(client.auth.get_token(), rename_resource)
173179
```
174180

175181
### Share Example
176182
```python
177183
# Create share #
178184
resource = Resource.from_file_ref_and_endpoint("/eos/user/r/<some_username>/text.txt")
179-
resource_info = client.file.stat(resource)
185+
resource_info = client.file.stat(client.auth.get_token(), resource)
180186
user = client.user.get_user_by_claim("username", "<some_username>")
181-
res = client.share.create_share(resource_info, user.id.opaque_id, user.id.idp, "EDITOR", "USER")
187+
res = client.share.create_share(client.auth.get_token(), resource_info, user.id.opaque_id, user.id.idp, "EDITOR", "USER")
182188

183189
# List existing shares #
184190
filter_list = []
185191
filter = client.share.create_share_filter(resource_id=resource_info.id, filter_type="TYPE_RESOURCE_ID")
186192
filter_list.append(filter)
187193
filter = client.share.create_share_filter(share_state="SHARE_STATE_PENDING", filter_type="TYPE_STATE")
188194
filter_list.append(filter)
189-
res, _ = client.share.list_existing_shares()
195+
res, _ = client.share.list_existing_shares(client.auth.get_token(), )
190196

191197
# Get share #
192198
share_id = "58"
193-
res = client.share.get_share(opaque_id=share_id)
199+
res = client.share.get_share(client.auth.get_token(), opaque_id=share_id)
194200

195201
# update share #
196-
res = client.share.update_share(opaque_id=share_id, role="VIEWER")
202+
res = client.share.update_share(client.auth.get_token(), opaque_id=share_id, role="VIEWER")
197203

198204
# remove share #
199-
res = client.share.remove_share(opaque_id=share_id)
205+
res = client.share.remove_share(client.auth.get_token(), opaque_id=share_id)
200206

201207
# List existing received shares #
202208
filter_list = []
203209
filter = client.share.create_share_filter(share_state="SHARE_STATE_ACCEPTED", filter_type="TYPE_STATE")
204210
filter_list.append(filter)
205-
res, _ = client.share.list_received_existing_shares()
211+
res, _ = client.share.list_received_existing_shares(client.auth.get_token())
206212

207213
# get received share #
208-
received_share = client.share.get_received_share(opaque_id=share_id)
214+
received_share = client.share.get_received_share(client.auth.get_token(), opaque_id=share_id)
209215

210216
# update recieved share #
211-
res = client.share.update_received_share(received_share=received_share, state="SHARE_STATE_ACCEPTED")
217+
res = client.share.update_received_share(client.auth.get_token(), received_share=received_share, state="SHARE_STATE_ACCEPTED")
212218

213219
# create public share #
214-
res = client.share.create_public_share(resource_info, role="VIEWER")
220+
res = client.share.create_public_share(client.auth.get_token(), resource_info, role="VIEWER")
215221

216222
# list existing public shares #
217223
filter_list = []
218224
filter = client.share.create_public_share_filter(resource_id=resource_info.id, filter_type="TYPE_RESOURCE_ID")
219225
filter_list.append(filter)
220226
res, _ = client.share.list_existing_public_shares(filter_list=filter_list)
221227

222-
res = client.share.get_public_share(opaque_id=share_id, sign=True)
228+
res = client.share.get_public_share(client.auth.get_token(), opaque_id=share_id, sign=True)
223229
# OR token = "<token>"
224230
# res = client.share.get_public_share(token=token, sign=True)
225231

226232
# update public share #
227-
res = client.share.update_public_share(type="TYPE_PASSWORD", token=token, role="VIEWER", password="hello")
233+
res = client.share.update_public_share(client.auth.get_token(), type="TYPE_PASSWORD", token=token, role="VIEWER", password="hello")
228234

229235
# remove public share #
230-
res = client.share.remove_public_share(token=token)
236+
res = client.share.remove_public_share(client.auth.get_token(), token=token)
231237

232238
```
233239

234240
### User Example
235241
```python
236242
# find_user
237-
res = client.user.find_users("rwel")
243+
res = client.user.find_users(client.auth.get_token(), "rwel")
238244

239245
# get_user
240246
res = client.user.get_user("https://auth.cern.ch/auth/realms/cern", "asdoiqwe")
@@ -253,21 +259,21 @@ res = client.user.get_user_by_claim("username", "rwelande")
253259
### App Example
254260
```python
255261
# list_app_providers
256-
res = client.app.list_app_providers()
262+
res = client.app.list_app_providers(client.auth.get_token())
257263

258264
# open_in_app
259265
resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande/collabora.odt")
260-
res = client.app.open_in_app(resource)
266+
res = client.app.open_in_app(client.auth.get_token(), resource)
261267
```
262268

263269
### Checkpoint Example
264270
```python
265271
# list file versions
266272
resource = Resource.from_file_ref_and_endpoint("/eos/user/r/rwelande/test.md")
267-
res = client.checkpoint.list_file_versions(resource)
273+
res = client.checkpoint.list_file_versions(client.auth.get_token(), resource)
268274

269275
# restore file version
270-
res = client.checkpoint.restore_file_version(resource, "1722936250.0569fa2f")
276+
res = client.checkpoint.restore_file_version(client.auth.get_token(), resource, "1722936250.0569fa2f")
271277
```
272278

273279
## Documentation
@@ -282,6 +288,9 @@ make html
282288
## Unit tests
283289

284290
```bash
291+
# install library
292+
pip install .
293+
# run unit tests
285294
pytest --cov-report term --cov=serc tests/
286295
```
287296

docs/.DS_Store

-6 KB
Binary file not shown.

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
name="cs3client",
2121
version=version,
2222
author="Rasmus Welander, Diogo Castro, Giuseppe Lo Presti",
23-
package_dir={"": "src"},
24-
packages=find_packages(where="src"),
25-
py_modules=["cs3client"],
23+
packages=find_packages(),
2624
description="CS3 client for Python",
25+
package_dir={"cs3client": "cs3client"},
2726
long_description=long_description,
2827
long_description_content_type="text/markdown",
2928
url="https://github.com/cs3org/cs3-python-client",

0 commit comments

Comments
 (0)