Skip to content

Commit 649f64c

Browse files
committed
add precommit setup and run across files, fix dockerfile again
1 parent 72832c3 commit 649f64c

File tree

205 files changed

+1142
-924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+1142
-924
lines changed

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: check-added-large-files
9+
- id: check-merge-conflict
10+
- id: debug-statements
11+
- id: check-docstring-first
12+
- repo: https://github.com/pre-commit/mirrors-autopep8
13+
rev: v2.0.4
14+
hooks:
15+
- id: autopep8
16+
args: [--in-place, --aggressive, --aggressive, --max-line-length=88]
17+
- repo: https://github.com/psf/black
18+
rev: 23.12.1
19+
hooks:
20+
- id: black
21+
language_version: python3
22+
args: [--line-length=88]
23+
- repo: https://github.com/pycqa/isort
24+
rev: 5.13.2
25+
hooks:
26+
- id: isort
27+
args: [--profile=black, --line-length=88]
28+
- repo: https://github.com/pycqa/flake8
29+
rev: 7.0.0
30+
hooks:
31+
- id: flake8
32+
args: [--max-line-length=88, --ignore=E203,W503]
33+
exclude: ^(archive/|docker/dummy/)

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to HyDroForM (WIP)
1+
# Contributing to HyDroForM
22

33
First off, thanks for taking the time to contribute! ❤️
44

@@ -39,7 +39,7 @@ We will then take care of the issue as soon as possible.
3939

4040
## I Want To Contribute
4141

42-
> ### Legal Notice
42+
> ### Legal Notice
4343
> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
4444
4545
### Reporting Bugs
@@ -101,7 +101,7 @@ Enhancement suggestions are tracked as [GitHub issues](/issues).
101101
- Use a **clear and descriptive title** for the issue to identify the suggestion.
102102
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
103103
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
104-
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
104+
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
105105
- **Explain why this enhancement would be useful** to most CONTRIBUTING.md users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
106106

107107

OSCAR/examples/old/oscar.py

Lines changed: 70 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import argparse
22
import json
33
import os
4-
import sys
54
import subprocess
6-
from minio import Minio
7-
from oscar_python.client import Client
8-
import oscar_python._utils as utils
5+
import sys
96
import tarfile
107
import uuid
11-
import requests
8+
129
import openeo
13-
import subprocess
10+
import oscar_python._utils as utils
11+
import requests
12+
from minio import Minio
13+
from oscar_python.client import Client
14+
1415

1516
def parse_arguments():
1617
# parser = argparse.ArgumentParser()
@@ -38,20 +39,24 @@ def parse_arguments():
3839
# service_config = variables['service_config'] # os.path.abspath(
3940
# output = variables['output']
4041

41-
conn = openeo.connect("https://openeo.intertwin.fedcloud.eu/1.1.0").authenticate_oidc()
42+
conn = openeo.connect(
43+
"https://openeo.intertwin.fedcloud.eu/1.1.0"
44+
).authenticate_oidc()
4245

4346
TOKEN = "/home/jzvolensky/.local/share/openeo-python-client/refresh-tokens.json"
4447
with open(TOKEN) as f:
4548
token_data = json.load(f)
46-
refresh_token = token_data["https://aai.egi.eu/auth/realms/egi"]["openeo-platform-default-client"]["refresh_token"].strip()
49+
refresh_token = token_data["https://aai.egi.eu/auth/realms/egi"][
50+
"openeo-platform-default-client"
51+
]["refresh_token"].strip()
4752
print(refresh_token)
4853

4954
token = get_access_token(refresh_token)
5055

5156
endpoint = "https://oscar-grnet.intertwin.fedcloud.eu"
5257
user = ""
5358
password = ""
54-
token = f'{token}'
59+
token = f"{token}"
5560
service = "hydroform"
5661
service_config = "oscar_services/hydroform_oscar_svc.yaml"
5762
output = "output"
@@ -67,11 +72,10 @@ def parse_arguments():
6772

6873
def get_access_token(refresh_token):
6974
url = "https://aai.egi.eu/auth/realms/egi/protocol/openid-connect/token"
70-
data = f"grant_type=refresh_token&refresh_token={refresh_token}&client_id=openeo-platform-default-client&scope=openid%20email%20offline_access%20eduperson_scoped_affiliation%20eduperson_entitlement"
75+
data = f"grant_type=refresh_token&refresh_token={
76+
refresh_token}&client_id=openeo-platform-default-client&scope=openid%20email%20offline_access%20eduperson_scoped_affiliation%20eduperson_entitlement"
7177
result = subprocess.run(
72-
["curl", "-X", "POST", url, "-d", data],
73-
stdout=subprocess.PIPE,
74-
text=True
78+
["curl", "-X", "POST", url, "-d", data], stdout=subprocess.PIPE, text=True
7579
)
7680
if result.returncode == 0:
7781
token_info = json.loads(result.stdout)
@@ -80,22 +84,27 @@ def get_access_token(refresh_token):
8084
print(f"Failed to get access token: {result.returncode}")
8185

8286
return token_info["access_token"]
83-
87+
88+
8489
def check_oscar_connection():
8590
# Check the service or create it
8691
print("Checking OSCAR connection status")
8792
if user and password:
88-
options_basic_auth = {'cluster_id': 'cluster-id',
89-
'endpoint': endpoint,
90-
'user': user,
91-
'password': password,
92-
'ssl': 'True'}
93+
options_basic_auth = {
94+
"cluster_id": "cluster-id",
95+
"endpoint": endpoint,
96+
"user": user,
97+
"password": password,
98+
"ssl": "True",
99+
}
93100
print("Using credentials user/password")
94101
elif token:
95-
options_basic_auth = {'cluster_id': 'cluster-id',
96-
'endpoint': endpoint,
97-
'oidc_token': token,
98-
'ssl': 'True'}
102+
options_basic_auth = {
103+
"cluster_id": "cluster-id",
104+
"endpoint": endpoint,
105+
"oidc_token": token,
106+
"ssl": "True",
107+
}
99108
print("Using credentials token")
100109
else:
101110
print("Introduce the credentials user/password or token")
@@ -133,7 +142,9 @@ def check_service(client, service, service_config):
133142
exit(1)
134143
try:
135144
service_info = client.get_service(service)
136-
minio_info = json.loads(service_info.text)["storage_providers"]["minio"]["default"]
145+
minio_info = json.loads(service_info.text)["storage_providers"]["minio"][
146+
"default"
147+
]
137148
input_info = json.loads(service_info.text)["input"][0]
138149
output_info = json.loads(service_info.text)["output"][0]
139150
print("OSCAR Service " + service + " created")
@@ -147,9 +158,11 @@ def check_service(client, service, service_config):
147158
def connect_minio(minio_info):
148159
# Create client with access and secret key.
149160
print("Creating connection with MinIO")
150-
client = Minio(minio_info["endpoint"].split("//")[1],
151-
minio_info["access_key"],
152-
minio_info["secret_key"])
161+
client = Minio(
162+
minio_info["endpoint"].split("//")[1],
163+
minio_info["access_key"],
164+
minio_info["secret_key"],
165+
)
153166
return client
154167

155168

@@ -159,7 +172,7 @@ def upload_file_minio(client, input_info, input_file):
159172
random = uuid.uuid4().hex + "_" + input_file.split("/")[-1]
160173
client.fput_object(
161174
input_info["path"].split("/")[0],
162-
'/'.join(input_info["path"].split("/")[1:]) + "/" + random,
175+
"/".join(input_info["path"].split("/")[1:]) + "/" + random,
163176
input_file,
164177
)
165178
return random.split("_")[0]
@@ -170,7 +183,7 @@ def wait_output_and_download(client, output_info, output):
170183
print("Waiting the output")
171184
with client.listen_bucket_notification(
172185
output_info["path"].split("/")[0],
173-
prefix='/'.join(output_info["path"].split("/")[1:]),
186+
prefix="/".join(output_info["path"].split("/")[1:]),
174187
events=["s3:ObjectCreated:*", "s3:ObjectRemoved:*"],
175188
) as events:
176189
for event in events:
@@ -179,9 +192,11 @@ def wait_output_and_download(client, output_info, output):
179192
break
180193
# Download the file
181194
print("Downloading the file")
182-
client.fget_object(output_info["path"].split("/")[0],
183-
outputfile,
184-
output + "/" + outputfile.split("/")[-1])
195+
client.fget_object(
196+
output_info["path"].split("/")[0],
197+
outputfile,
198+
output + "/" + outputfile.split("/")[-1],
199+
)
185200
return output + "/" + outputfile.split("/")[-1]
186201

187202

@@ -197,31 +212,45 @@ def compress(filename):
197212

198213
def extract(output_file):
199214
print("Decompressing output")
200-
with tarfile.open(output_file, 'r') as tar:
215+
with tarfile.open(output_file, "r") as tar:
201216
for member in tar.getmembers():
202217
tar.extract(member, path=output)
203218

204219

205220
def run_service(client, service, token, output):
206-
print(f'Running {service} service')
221+
print(f"Running {service} service")
207222
response = None
208223
try:
209224
data = {
210225
"Records": [
211226
{
212227
"requestParameters": {
213228
"principalId": "uid",
214-
"sourceIPAddress": "ip"
229+
"sourceIPAddress": "ip",
215230
},
216231
}
217232
]
218233
}
219-
json_data = json.dumps(data).encode('utf-8')
234+
json_data = json.dumps(data).encode("utf-8")
220235
if token:
221236
headers = utils.get_headers_with_token(token)
222-
response = requests.request("post", endpoint + "/job/" + service, headers=headers, verify=client.ssl, data=json_data, timeout=1500)
237+
response = requests.request(
238+
"post",
239+
endpoint + "/job/" + service,
240+
headers=headers,
241+
verify=client.ssl,
242+
data=json_data,
243+
timeout=1500,
244+
)
223245
elif user and password:
224-
response = requests.request("post", endpoint + "/job/" + service, auth=(user, password), verify=client.ssl, data=json_data, timeout=1500)
246+
response = requests.request(
247+
"post",
248+
endpoint + "/job/" + service,
249+
auth=(user, password),
250+
verify=client.ssl,
251+
data=json_data,
252+
timeout=1500,
253+
)
225254
else:
226255
raise ValueError("Either token or user/password must be provided")
227256
except Exception as err:
@@ -236,5 +265,7 @@ def run_service(client, service, token, output):
236265
minio_info, input_info, output_info = check_service(client, service, service_config)
237266
print(minio_info, input_info, output_info)
238267
response = run_service(client, service, token, output)
239-
output_file = wait_output_and_download(connect_minio(minio_info), output_info, output)
268+
output_file = wait_output_and_download(
269+
connect_minio(minio_info), output_info, output
270+
)
240271
extract(output_file)

OSCAR/examples/old/oscar_services/hydroform_oscar_svc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ functions:
1313
path: hydroform/in
1414
output:
1515
- storage_provider: minio
16-
path: hydroform/out
16+
path: hydroform/out

OSCAR/examples/old/oscar_services/script.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ echo "catalog: $catalog"
1616
hydromt build wflow model \
1717
-r "$region" \
1818
-d "$catalog" \
19-
-i "$setupconfig" -vvv
19+
-i "$setupconfig" -vvv
2020
echo "Finished running hydromt build wflow model"
2121

2222
echo "Wrapping output files"
@@ -27,4 +27,4 @@ echo "Finished wrapping output files"
2727
tar -czvf output.tar.gz model/stac
2828
mv output.tar.gz $TMP_OUTPUT_DIR/output.tar.gz
2929

30-
echo "End of script"
30+
echo "End of script"

0 commit comments

Comments
 (0)