Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update isort and flake in cicd to fix pre-commit #206

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: check-yaml
# isort should run before black as black sometimes tweaks the isort output
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
# https://github.com/python/black#version-control-integration
Expand All @@ -17,10 +17,10 @@ repos:
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
rev: v0.3.4
rev: v0.3.9
hooks:
- id: blackdoc
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
rev: 6.1.0
hooks:
- id: flake8
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
- add Zenodo integration and add citation file
[\#195](https://github.com/EUREC4A-UK/lagtraj/pull/195) @leifdenby

- update versions of flake8, black and isort in pre-commit config and resolve
linting issues arising from these updates
[\#206](https://github.com/EUREC4A-UK/lagtraj/pull/206), @leifdenby


## [v0.1.2](https://github.com/EUREC4A-UK/lagtraj/tree/v0.1.2)

Expand Down
4 changes: 2 additions & 2 deletions lagtraj/domain/sources/era5/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _extra_var(self, v):
return da_combined

def __getitem__(self, item):
requested_vars = type(item) == set and item or set(item)
requested_vars = set(item)
available_vars = self._selected_vars or self.data_vars
missing_vars = requested_vars.difference(available_vars)
if len(missing_vars) > 0:
Expand Down Expand Up @@ -292,7 +292,7 @@ def interp(self, kwargs, method="linear", **interp_to):
if np.array(interp_to[d]) in d_vals_array:
slices[d] = interp_to[d]
continue
if type(interp_to[d]) == xr.core.dataarray.DataArray:
if isinstance(interp_to[d], xr.core.dataarray.DataArray):
d_interp_val = interp_to[d].values
else:
d_interp_val = interp_to[d]
Expand Down
8 changes: 5 additions & 3 deletions lagtraj/input_definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _check_field(f_name, f_option):
# with the fields `requires` and `choices` can be provided. `requires`
# indicate other validations that must pass and choices are the valid
# choices if they pass
if type(f_option) == dict:
if isinstance(f_option, dict):
if "requires" in f_option and "choices" in f_option:
requirements = f_option["requires"]
satisfied_requirements = {}
Expand Down Expand Up @@ -122,7 +122,9 @@ def _check_field(f_name, f_option):

# here we check whether the parameter was prescribed to have a specific
# type and in that case whether the value provided has the correct type
if type(f_option) == type and type(input_params[f_name]) != f_option:
if isinstance(f_option, type) and not isinstance(
input_params[f_name], f_option
):
raise InvalidInputDefinition(
"Field `{}` should have type {}, but has type `{}`".format(
f_name, f_option, type(input_params[f_name])
Expand All @@ -138,7 +140,7 @@ def _check_field(f_name, f_option):

# choices a given as a list or tuple, so we call `_check_field`
# recursively to see if one of the options fit
if type(f_option) == list or type(f_option) == tuple:
if isinstance(f_option, list) or isinstance(f_option, tuple):
f_options = f_option
exceptions = []
new_val = None
Expand Down
2 changes: 1 addition & 1 deletion lagtraj/trajectory/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main(data_path, trajectory_name):
da_times = _get_times_from_domain(
trajectory_definition=traj_definition, root_data_path=data_path
)
elif type(traj_definition.timestep) == datetime.timedelta:
elif isinstance(traj_definition.timestep, datetime.timedelta):
da_times = _build_times_dataarray(
origin=traj_definition.origin,
duration=traj_definition.duration,
Expand Down
10 changes: 6 additions & 4 deletions lagtraj/utils/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_attributes_dictionary(*args, **kwargs):
"""

def _serialize_item(item, prefix=""):
if type(item) == str:
if isinstance(item, str):
yield (prefix, item)
elif isinstance(item, float) or isinstance(item, int):
yield (prefix, str(item))
Expand All @@ -24,17 +24,17 @@ def _serialize_item(item, prefix=""):
yield (prefix, item.isoformat())
else:
sub_items = []
if type(item) == dict:
if isinstance(item, dict):
sub_items = item.items()
elif (
isinstance(item, xr.Dataset)
or isinstance(item, xr.DataArray)
or isinstance(item, ERA5DataSet)
):
sub_items = item.attrs.items()
# can use isinstance because namedtuple is a kind of tuple and we
# can't use isinstance because namedtuple is a kind of tuple and we
# want to save the tuple keys in that case
elif isinstance(item, list) or type(item) == tuple:
elif isinstance(item, list) or type(item) is tuple:
sub_items = zip(range(len(item)), item)
else:
# collections.named_tuple has a `_asdict` method to turn it into a dictionary
Expand Down Expand Up @@ -64,5 +64,7 @@ def _serialize_item(item, prefix=""):
]
for item in items:
for (label, value) in _serialize_item(item=item):
if not isinstance(label, str):
raise ValueError(f"Expected string, got {type(label)}")
attrs[label] = value
return attrs
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ dev =

[flake8]
max-line-length = 88
extend-ignore = E203
extend-ignore = E203, E713, E501, E701
select = C,E,F,W,B,B950
ignore = E203, E501, W503
ignore = E203, E501, W503, W604

[isort]
profile=black
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _parse_readme_cli_commands():

lines = [line.replace("$>", "").strip() for line in lines]

cli_commands = list(filter(lambda l: "python -m lagtraj" in l, lines))
cli_commands = list(filter(lambda line: "python -m lagtraj" in line, lines))

return cli_commands

Expand Down
Loading