Skip to content

Commit 107c8f4

Browse files
committed
Blacking…
Signed-off-by: Cédric Foellmi <cedric@onekiloparsec.dev>
1 parent 86d78d1 commit 107c8f4

23 files changed

Lines changed: 200 additions & 146 deletions

arcsecond/api/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
class ArcsecondConfig(object):
1313
def __init__(self, **kwargs):
14-
self.__api_name = kwargs.get('api_name', 'cloud') or 'cloud'
14+
self.__api_name = kwargs.get("api_name", "cloud") or "cloud"
1515
self.__verbose = kwargs.get("verbose", 0) or 0
16-
if 'config' in kwargs.keys():
17-
self.__config = kwargs.get('config')
16+
if "config" in kwargs.keys():
17+
self.__config = kwargs.get("config")
1818
else:
1919
self.__config = ConfigParser()
2020
self.__config.read(str(ArcsecondConfig.file_path()))

arcsecond/api/endpoint.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def path(self):
2828

2929
def _get_base_url(self):
3030
if not self.__config.api_server:
31-
raise ArcsecondError(f"API server address for name \'{self.__config.api_name}\' is unknown/invalid.")
31+
raise ArcsecondError(
32+
f"API server address for name '{self.__config.api_name}' is unknown/invalid."
33+
)
3234
url = self.__config.api_server
3335
if not url.endswith("/"):
3436
url += "/"
@@ -65,11 +67,7 @@ def read(self, id_name_uuid, headers=None):
6567

6668
def create(self, json=None, files=None, headers=None):
6769
return self._perform_request(
68-
self._list_url(),
69-
"post",
70-
json=json,
71-
files=files,
72-
headers=headers
70+
self._list_url(), "post", json=json, files=files, headers=headers
7371
)
7472

7573
def update(self, id_name_uuid, json=None, files=None, headers=None):
@@ -91,14 +89,14 @@ def _perform_request(self, url, method_name, json=None, files=None, headers=None
9189
headers = self._check_and_set_auth_key(headers or {}, url)
9290
method = getattr(httpx, method_name.lower())
9391

94-
kwargs = {'headers': headers, 'timeout': 60}
92+
kwargs = {"headers": headers, "timeout": 60}
9593
if files and json:
9694
# Do NOT set json=json, keep data=json, to avoid overriding Content-Type with `application/json`.
9795
kwargs.update(files=files, data=json)
9896
elif json and not files:
9997
kwargs.update(json=json)
10098
elif files and not json:
101-
raise ArcsecondError('Files but no json?')
99+
raise ArcsecondError("Files but no json?")
102100

103101
try:
104102
response = method(url, **kwargs)

arcsecond/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def main(ctx, version=False, v=False, h=False):
3535
def version():
3636
click.echo(__version__.__version__)
3737

38+
3839
# Read/set API server to use.
3940
main.add_command(api)
4041

arcsecond/cloud/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def me(state):
110110
if not username:
111111
msg = f"Invalid/missing username: {username}. Make sure to login first: $ arcsecond login"
112112
raise ArcsecondError(msg)
113-
response, error = ArcsecondAPI(ArcsecondConfig.from_state(state)).profiles.read(username)
113+
response, error = ArcsecondAPI(ArcsecondConfig.from_state(state)).profiles.read(
114+
username
115+
)
114116
if error:
115117
click.echo(str(error))
116118
else:

arcsecond/cloud/uploader/allskycameraimages/context.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class AllSkyCameraImageUploadContext(BaseUploadContext):
1010
"""Upload context for all-sky camera image uploads"""
1111

1212
def __init__(
13-
self,
14-
config,
15-
input_camera_uuid,
16-
org_subdomain=None,
17-
custom_tags=None,
13+
self,
14+
config,
15+
input_camera_uuid,
16+
org_subdomain=None,
17+
custom_tags=None,
1818
):
1919
super().__init__(config, org_subdomain, custom_tags)
2020
self._input_camera_uuid = str(input_camera_uuid) if input_camera_uuid else None
@@ -23,7 +23,9 @@ def __init__(
2323
@property
2424
def upload_api_endpoint(self):
2525
return ArcsecondAPIEndpoint(
26-
self.config, f"allskycameras/{self._input_camera_uuid}/images", self.subdomain
26+
self.config,
27+
f"allskycameras/{self._input_camera_uuid}/images",
28+
self.subdomain,
2729
)
2830

2931
def _validate_context_specific(self):

arcsecond/cloud/uploader/allskycameraimages/uploader.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ def _prepare_upload(self):
1313
pass
1414

1515
def _get_upload_data(self, **kwargs):
16-
fields = {
17-
"camera": self._context.camera_uuid
18-
}
19-
clean_kwargs = {k: kwargs[k] for k in ('timestamp', 'camera') if k in kwargs}
16+
fields = {"camera": self._context.camera_uuid}
17+
clean_kwargs = {k: kwargs[k] for k in ("timestamp", "camera") if k in kwargs}
2018
fields.update(**clean_kwargs)
21-
if 'timestamp' not in clean_kwargs:
22-
raise ArcsecondError('Missing timestamp.')
19+
if "timestamp" not in clean_kwargs:
20+
raise ArcsecondError("Missing timestamp.")
2321
return fields
2422

2523
def upload_file(self, timestamp, **kwargs):

arcsecond/cloud/uploader/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def _validate_local_astronomer_credentials(self):
8585

8686
def _validate_remote_organisation(self):
8787
click.echo(f" • Fetching details of organisation {self._subdomain}...")
88-
_, error = ArcsecondAPI(self._config, self._subdomain).organisations.read(self._subdomain)
88+
_, error = ArcsecondAPI(self._config, self._subdomain).organisations.read(
89+
self._subdomain
90+
)
8991
if error is not None:
9092
raise UnknownOrganisationError(self._subdomain, str(error))
9193

arcsecond/cloud/uploader/datafiles/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def _validate_input_dataset_uuid_or_name(self):
5050
click.echo(
5151
f" • Looking for a dataset with name {self._input_dataset_uuid_or_name}..."
5252
)
53-
datasets_list, error = endpoint.list(**{"name": self._input_dataset_uuid_or_name})
53+
datasets_list, error = endpoint.list(
54+
**{"name": self._input_dataset_uuid_or_name}
55+
)
5456
if len(datasets_list) == 0:
5557
click.echo(
5658
f" • No dataset with name {self._input_dataset_uuid_or_name} found. It will be created."

arcsecond/cloud/uploader/datafiles/uploader.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def _prepare_upload(self):
2222
self._logger.info(
2323
f"{self.log_prefix} Creating dataset with name {dataset_name}..."
2424
)
25-
endpoint = ArcsecondAPIEndpoint(self._context.config, 'datasets', self._context.subdomain)
25+
endpoint = ArcsecondAPIEndpoint(
26+
self._context.config, "datasets", self._context.subdomain
27+
)
2628
dataset, error = endpoint.create(json=data)
2729

2830
if error:
@@ -41,13 +43,18 @@ def _get_upload_data(self, **kwargs):
4143
"is_raw": str(self._context.is_raw_data),
4244
}
4345
if self._context.custom_tags and len(self._context.custom_tags) > 0:
44-
raw_tags = self._context.custom_tags if isinstance(self._context.custom_tags, list) \
45-
else self._context.custom_tags.split(',')
46+
raw_tags = (
47+
self._context.custom_tags
48+
if isinstance(self._context.custom_tags, list)
49+
else self._context.custom_tags.split(",")
50+
)
4651
tags = [t.strip() for t in raw_tags if len(t.strip()) > 0]
4752
fields["tags"] = ",".join(tags)
48-
clean_kwargs = {k: kwargs[k] for k in ('is_raw', 'tags', 'dataset') if k in kwargs}
49-
if 'tags' in clean_kwargs and not clean_kwargs['tags']:
53+
clean_kwargs = {
54+
k: kwargs[k] for k in ("is_raw", "tags", "dataset") if k in kwargs
55+
}
56+
if "tags" in clean_kwargs and not clean_kwargs["tags"]:
5057
# Tags must really be provided only when non-blank/null/empty
51-
del clean_kwargs['tags']
58+
del clean_kwargs["tags"]
5259
fields.update(**clean_kwargs)
5360
return fields

arcsecond/cloud/uploader/uploader.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class BaseFileUploader(Generic[ContextT], ABC):
5555
"""Abstract base class for uploaders"""
5656

5757
def __init__(
58-
self,
59-
context: ContextT,
60-
file_path: str | Path,
61-
display_progress=False,
58+
self,
59+
context: ContextT,
60+
file_path: str | Path,
61+
display_progress=False,
6262
):
6363
self._context = context
6464
self._file_path = Path(file_path)
@@ -96,7 +96,9 @@ def _prepare_upload(self):
9696

9797
def _get_upload_files(self, **kwargs):
9898
filename = os.path.basename(self._file_path)
99-
self._file = UploadFileWithProgress(self._file_path, display_progress=self._display_progress)
99+
self._file = UploadFileWithProgress(
100+
self._file_path, display_progress=self._display_progress
101+
)
100102
self._cleanup_resources.append(self._file)
101103
return {
102104
"file": (filename, self._file, "application/octet-stream"),
@@ -118,7 +120,9 @@ def _perform_upload(self, **kwargs):
118120

119121
files = self._get_upload_files(**kwargs)
120122
data = self._get_upload_data(**kwargs)
121-
self._uploaded_file, error = self._context.upload_api_endpoint.create(files=files, json=data)
123+
self._uploaded_file, error = self._context.upload_api_endpoint.create(
124+
files=files, json=data
125+
)
122126

123127
if not error:
124128
seconds = (datetime.now() - self._started).total_seconds()
@@ -128,7 +132,7 @@ def _perform_upload(self, **kwargs):
128132
return
129133

130134
if "already exists in dataset" in str(
131-
error
135+
error
132136
): # VERY WEAK!!! But solution with HTTP 409 isn't nice either.
133137
self._status = [Status.SKIPPED, Substatus.ALREADY_SYNCED, None]
134138
else:
@@ -141,8 +145,9 @@ def _perform_upload(self, **kwargs):
141145
def _cleanup(self):
142146
for resource in self._cleanup_resources:
143147
try:
144-
if hasattr(resource, "close") and \
145-
not getattr(resource, "closed", False):
148+
if hasattr(resource, "close") and not getattr(
149+
resource, "closed", False
150+
):
146151
resource.close()
147152
except Exception as e:
148153
self._logger.error(f"{self.log_prefix} {str(e)}.")
@@ -159,7 +164,9 @@ def upload_file(self, **kwargs):
159164
try:
160165
self._prepare_upload()
161166
except Exception:
162-
self._logger.info(f"{self.log_prefix} Upload preparation error. Trying again automatically in 1 second.")
167+
self._logger.info(
168+
f"{self.log_prefix} Upload preparation error. Trying again automatically in 1 second."
169+
)
163170
# Just try again
164171
time.sleep(1)
165172
self._prepare_upload()
@@ -170,7 +177,9 @@ def upload_file(self, **kwargs):
170177
self._perform_upload(**kwargs)
171178
except UploadRemoteFileError:
172179
# Just try again
173-
self._logger.info(f"{self.log_prefix} Upload error. Trying again automatically in 1 second.")
180+
self._logger.info(
181+
f"{self.log_prefix} Upload error. Trying again automatically in 1 second."
182+
)
174183
time.sleep(1)
175184
self._perform_upload(**kwargs_copy)
176185
finally:

0 commit comments

Comments
 (0)