Skip to content

Commit 3eeef98

Browse files
committed
feat: switch to ruff
Some lint and typing fixes to make ruff and mypy.
1 parent 06f22f5 commit 3eeef98

12 files changed

+59
-40
lines changed

.github/workflows/continuous-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
with:
4141
token: ${{ secrets.CODECOV_TOKEN }}
4242
file: ./coverage.xml
43-
fail_ci_if_error: false
43+
fail_ci_if_error: false

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,3 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161-

.pre-commit-config.yaml

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22
# Please run `pre-commit run --all-files` when adding or changing entries.
33

44
repos:
5-
- repo: https://github.com/psf/black
6-
rev: 23.7.0
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.5.0
77
hooks:
8-
- id: black
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: check-yaml
11+
- id: check-added-large-files
912
- repo: https://github.com/codespell-project/codespell
10-
rev: v2.2.5
13+
rev: v2.2.6
1114
hooks:
1215
- id: codespell
1316
args: [--ignore-words=.codespellignore]
1417
types_or: [jupyter, markdown, python, shell]
15-
- repo: https://github.com/PyCQA/flake8
16-
rev: 6.1.0
17-
hooks:
18-
- id: flake8
19-
- repo: https://github.com/pycqa/isort
20-
rev: 5.12.0
18+
- repo: https://github.com/psf/black
19+
rev: 23.9.1
2120
hooks:
22-
- id: isort
23-
args: ["--profile", "black"]
21+
- id: black
2422
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v1.5.0
23+
rev: v1.6.0
2624
hooks:
2725
- id: mypy
2826
additional_dependencies:
2927
- pytest
3028
- types-setuptools == 65.7.0.3
29+
- repo: https://github.com/astral-sh/ruff-pre-commit
30+
rev: v0.0.292
31+
hooks:
32+
- id: ruff

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,4 @@
199199
distributed under the License is distributed on an "AS IS" BASIS,
200200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201201
See the License for the specific language governing permissions and
202-
limitations under the License.
202+
limitations under the License.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class MyTask(Task):
2222

2323
def process(self, **kwargs: Any) -> List[Dict[str, Any]]:
2424
item = self.items[0]
25-
25+
2626
# download a datafile
2727
item = self.download_item_assets(item, assets=['data'])
28-
28+
2929
# operate on the local file to create a new asset
3030
item = self.upload_item_assets_to_s3(item)
3131

pyproject.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "stactask"
33
version = "0.1.1"
44
authors = [{ name = "Matthew Hanson", email = "[email protected]" }]
5+
maintainers = [{ name = "Pete Gadomski", email = "[email protected]" }]
56
description = "Class interface for running custom algorithms and workflows on STAC Items"
67
readme = "README.md"
78
requires-python = ">=3.8"
@@ -32,12 +33,11 @@ dependencies = [
3233
dev = [
3334
"black~=23.9.1",
3435
"codespell~=2.2.5",
35-
"flake8~=6.1.0",
36-
"isort~=5.12.0",
3736
"mypy~=1.5.0",
3837
"pre-commit~=3.4.0",
39-
"pytest~=7.4.0",
4038
"pytest-cov~=4.1.0",
39+
"pytest~=7.4.0",
40+
"ruff==0.0.292",
4141
"types-setuptools~=68.2.0",
4242
]
4343

@@ -52,3 +52,6 @@ strict = true
5252
[[tool.mypy.overrides]]
5353
module = ["boto3utils", "jsonpath_ng.ext", "fsspec"]
5454
ignore_missing_imports = true
55+
56+
[tool.ruff]
57+
select = ["F", "E", "W", "I", "ERA", "RUF"]

scripts/test

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
2929
pytest --cov=stactask tests
3030
coverage xml
3131
fi
32-
fi
32+
fi

stactask/asset_io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def upload_item_assets_to_s3(
118118
if public_assets is None:
119119
public_assets = []
120120
# determine which assets should be public
121-
elif type(public_assets) is str:
121+
elif isinstance(public_assets, str):
122122
if public_assets == "ALL":
123123
public_assets = list(_item["assets"].keys())
124124
else:

stactask/task.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ def __del__(self) -> None:
9595

9696
@property
9797
def process_definition(self) -> Dict[str, Any]:
98-
return self._payload.get("process", {})
98+
process = self._payload.get("process", {})
99+
if isinstance(process, dict):
100+
return process
101+
else:
102+
raise ValueError(f"process is not a dict: {type(process)}")
99103

100104
@property
101105
def parameters(self) -> Dict[str, Any]:
@@ -111,19 +115,37 @@ def parameters(self) -> Dict[str, Any]:
111115
return {}
112116
else:
113117
task_config: Dict[str, Any] = task_config_list[0]
114-
return task_config.get("parameters", {})
118+
parameters = task_config.get("parameters", {})
119+
if isinstance(parameters, dict):
120+
return parameters
121+
else:
122+
raise ValueError(f"parameters is not a dict: {type(parameters)}")
115123
elif isinstance(task_configs, Dict):
116-
return task_configs.get(self.name, {})
124+
config = task_configs.get(self.name, {})
125+
if isinstance(config, dict):
126+
return config
127+
else:
128+
raise ValueError(
129+
f"task config for {self.name} is not a dict: {type(config)}"
130+
)
117131
else:
118132
raise ValueError(f"unexpected value for 'tasks': {task_configs}")
119133

120134
@property
121135
def upload_options(self) -> Dict[str, Any]:
122-
return self.process_definition.get("upload_options", {})
136+
upload_options = self.process_definition.get("upload_options", {})
137+
if isinstance(upload_options, dict):
138+
return upload_options
139+
else:
140+
raise ValueError(f"upload_options is not a dict: {type(upload_options)}")
123141

124142
@property
125143
def items_as_dicts(self) -> List[Dict[str, Any]]:
126-
return self._payload.get("features", [])
144+
features = self._payload.get("features", [])
145+
if isinstance(features, list):
146+
return features
147+
else:
148+
raise ValueError(f"features is not a list: {type(features)}")
127149

128150
@property
129151
def items(self) -> ItemCollection:
@@ -251,9 +273,7 @@ def process(self, **kwargs: Any) -> List[Dict[str, Any]]:
251273
[type]: [description]
252274
"""
253275
# download assets of interest, this will update self.items
254-
# self.download_assets(['key1', 'key2'])
255276
# do some stuff
256-
# self.upload_assets(['key1', 'key2'])
257277
pass
258278

259279
def post_process_item(self, item: Dict[str, Any]) -> Dict[str, Any]:

tests/fixtures/sentinel2-l2a-j2k-payload.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1595,4 +1595,4 @@
15951595
"collection": "sentinel-2-l2a"
15961596
}
15971597
]
1598-
}
1598+
}

tests/test_task.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
from .tasks import DerivedItemTask, FailValidateTask, NothingTask
1212

13-
# import vcr
14-
15-
1613
testpath = Path(__file__).parent
1714
cassettepath = testpath / "fixtures" / "cassettes"
1815

@@ -115,16 +112,16 @@ def test_derived_item(derived_item_task: Task) -> None:
115112
items = derived_item_task.process(**derived_item_task.parameters)
116113
links = [lk for lk in items[0]["links"] if lk["rel"] == "derived_from"]
117114
assert len(links) == 1
118-
self_link = [lk for lk in items[0]["links"] if lk["rel"] == "self"][0]
115+
self_link = next(lk for lk in items[0]["links"] if lk["rel"] == "self")
119116
assert links[0]["href"] == self_link["href"]
120117

121118

122119
def test_task_handler(items: Dict[str, Any]) -> None:
123-
self_link = [lk for lk in items["features"][0]["links"] if lk["rel"] == "self"][0]
120+
self_link = next(lk for lk in items["features"][0]["links"] if lk["rel"] == "self")
124121
output_items = DerivedItemTask.handler(items)
125-
derived_link = [
122+
derived_link = next(
126123
lk for lk in output_items["features"][0]["links"] if lk["rel"] == "derived_from"
127-
][0]
124+
)
128125
assert derived_link["href"] == self_link["href"]
129126
assert (
130127
"derived-item-task"

tests/test_task_download.py

-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,4 @@ def test_download_large_asset(tmp_path: Path, item_collection: Dict[str, Any]) -
8080
).to_dict()
8181
filename = Path(item["assets"]["red"]["href"])
8282
assert filename.is_file() is True
83-
# t._save_workdir = False
8483
del t
85-
# assert (filename.is_file() is False)

0 commit comments

Comments
 (0)