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

[StepSecurity] Apply security best practices #1606

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
400cc49
[StepSecurity] Apply security best practices
step-security-bot Jan 18, 2024
3ba08da
Update .pre-commit-config.yaml
Zeitsperre Jan 18, 2024
1b1ada7
convert testdata_version to trigger on pull_request_target
Zeitsperre Jan 18, 2024
41f34fb
configure pylint with toml support, address some small errors
Zeitsperre Jan 18, 2024
47609cb
update target config
Zeitsperre Jan 18, 2024
74f63e9
ignore .pylintrc.toml
Zeitsperre Jan 18, 2024
91381b2
fix logging
Zeitsperre Jan 18, 2024
529f656
undo regression
Zeitsperre Jan 18, 2024
9d1cd10
more tuning
Zeitsperre Jan 18, 2024
195ea42
reconfigure pylint for pre-commit, adjust formatting and exceptions
Zeitsperre Jan 18, 2024
b039e8a
pylint adjustments
Zeitsperre Jan 19, 2024
e593786
disable pylint checks that are incompatible with mapblocks
Zeitsperre Jan 19, 2024
a8e8bfa
update dependabot.yml configuration, add job concerning workflow chan…
Zeitsperre Jan 19, 2024
1d5e7e9
security-related changes
Zeitsperre Jan 19, 2024
10291a8
rename some workflows for consistency
Zeitsperre Jan 19, 2024
80c1742
run on pull_request_target
Zeitsperre Jan 19, 2024
6a80c00
deactivate actions-versions-updater.yml (handled by dependabot now), …
Zeitsperre Jan 19, 2024
a63f9a2
small adjustments
Zeitsperre Jan 19, 2024
ca2ca17
remove some pylint warnings, mark map_groups as modifying call signat…
Zeitsperre Jan 19, 2024
d7a50dc
remove pylint statements
Zeitsperre Jan 19, 2024
90f78fb
treat xclim.indicators as a module with run-time submodules
Zeitsperre Jan 19, 2024
9320f63
re-add pragma: no cover
Zeitsperre Jan 19, 2024
380210b
noqa adjustment
Zeitsperre Jan 19, 2024
65fc23c
update CHANGES.rst
Zeitsperre Jan 19, 2024
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
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ repos:
hooks:
- id: toml-sort-fix
exclude: '.pylintrc.toml'
- repo: https://github.com/pylint-dev/pylint
rev: v3.0.3
hooks:
- id: pylint
args: [ '--rcfile=.pylintrc.toml', '--errors-only', '--jobs=0', '--disable=import-error' ]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.33.0
hooks:
Expand All @@ -49,6 +44,11 @@ repos:
rev: v0.1.13
hooks:
- id: ruff
- repo: https://github.com/pylint-dev/pylint
rev: v3.0.3
hooks:
- id: pylint
args: [ '--rcfile=.pylintrc.toml', '--errors-only', '--jobs=0', '--disable=import-error' ]
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
Expand Down
3 changes: 2 additions & 1 deletion .pylintrc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ disable = [
"invalid-unary-operand-type",
"locally-disabled",
"missing-module-docstring",
"no-member",
"protected-access",
"raw-checker-failed",
"redefined-outer-name",
Expand Down Expand Up @@ -521,7 +522,7 @@ missing-member-max-choices = 1
mixin-class-rgx = ".*[Mm]ixin"

# List of decorators that change the signature of a decorated function.
# signature-mutators =
signature-mutators = ["xclim.sdba.base.map_groups"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't adding "numba.guvectorize" solve the issues in xclim/indices/fire/_ffdi.py and xclim/sdba/nbutils.py ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, that doesn't work. Maybe one day this will be resolved.


[tool.pylint.variables]
# List of additional names supposed to be defined in builtins. Remember that you
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ lines-after-imports = 1
no-lines-before = ["future", "standard-library"]

[tool.ruff.mccabe]
max-complexity = 15
max-complexity = 20

[tool.ruff.per-file-ignores]
"docs/*.py" = ["D100", "D101", "D102", "D103"]
Expand Down
19 changes: 5 additions & 14 deletions tests/test_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ def test_attrs(tas_series):
assert f"xclim version: {__version__}" in txm.attrs["history"]
assert txm.name == "tmin5 degC"
assert uniIndTemp.standard_name == "{freq} mean temperature"
# fmt: off
assert (
uniIndTemp.cf_attrs[0]["another_attr"] == "With a value." # pylint: disable=unsubscriptable-object
uniIndTemp.cf_attrs[0]["another_attr"] # pylint: disable=unsubscriptable-object
== "With a value."
)
# fmt: on

thresh = xr.DataArray(
[1],
Expand Down Expand Up @@ -247,14 +246,8 @@ def test_module():
"""Translations are keyed according to the module where the indicators are defined."""
assert atmos.tg_mean.__module__.split(".")[2] == "atmos"
# Virtual module also are stored under xclim.indicators
# fmt: off
assert (
xclim.indicators.cf.fg.__module__ == "xclim.indicators.cf" # pylint: disable=no-member
)
assert (
xclim.indicators.icclim.GD4.__module__ == "xclim.indicators.icclim" # pylint: disable=no-member
)
# fmt: on
assert xclim.indicators.cf.fg.__module__ == "xclim.indicators.cf"
assert xclim.indicators.icclim.GD4.__module__ == "xclim.indicators.icclim"


def test_temp_unit_conversion(tas_series):
Expand All @@ -267,9 +260,7 @@ def test_temp_unit_conversion(tas_series):
with pytest.raises(AssertionError):
np.testing.assert_array_almost_equal(txk, txc + 273.15)

uniIndTemp.cf_attrs[0][ # noqa; # pylint: disable=unsubscriptable-object
"units"
] = "degC"
uniIndTemp.cf_attrs[0]["units"] = "degC" # pylint: disable=unsubscriptable-object
txc = uniIndTemp(a, freq="YS")
np.testing.assert_array_almost_equal(txk, txc + 273.15)

Expand Down
6 changes: 2 additions & 4 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# pylint: disable=unsubscriptable-object
# Tests for `xclim.locales`
from __future__ import annotations

Expand Down Expand Up @@ -159,13 +159,11 @@ def test_xclim_translations(locale, official_indicators):


@pytest.mark.parametrize(
# fmt: off
"initeng,expected",
[
(False, ""),
(True, atmos.tg_mean.cf_attrs[0]["long_name"]), # pylint: disable=unsubscriptable-object
(True, atmos.tg_mean.cf_attrs[0]["long_name"]),
],
# fmt: on
)
def test_local_dict_generation(initeng, expected):
dic = generate_local_dict("tlh", init_english=initeng)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_sdba/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-kwoa
from __future__ import annotations

import jsonpickle
Expand Down Expand Up @@ -193,7 +194,7 @@ def func(ds, *, dim):
d = ds.tas.mean(dim)
return d.rename("data").to_dataset()

data = func( # pylint: disable=missing-kwoa
data = func(
xr.Dataset(dict(tas=tas)),
group="time.dayofyear",
window=5,
Expand All @@ -212,7 +213,7 @@ def func(ds, *, dim):
return data.rename("data").to_dataset()

# with a scalar aux coord
data = func( # pylint: disable=missing-kwoa
data = func(
xr.Dataset(dict(tas=tas.isel(lat=0, drop=True)), coords=dict(leftover=1)),
group="time.dayofyear",
).load()
Expand Down
4 changes: 2 additions & 2 deletions xclim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ def cli(ctx, **kwargs):
ctx.obj = kwargs


@cli.result_callback() # noqa
@cli.result_callback()
@click.pass_context
def write_file(ctx, *args, **kwargs): # noqa: W0613
def write_file(ctx, *args, **kwargs):
"""Write the output dataset to file."""
if ctx.obj["output"] is not None:
if ctx.obj["verbose"]:
Expand Down
2 changes: 1 addition & 1 deletion xclim/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def run_check(*args, **kwargs):
return run_check


class set_options: # noqa: C0103
class set_options:
"""Set options for xclim in a controlled context.

Attributes
Expand Down
15 changes: 4 additions & 11 deletions xclim/indices/fire/_ffdi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=no-value-for-parameter
r"""
McArthur Forest Fire Danger (Mark 5) System
===========================================
Expand Down Expand Up @@ -97,7 +98,7 @@ def _keetch_byram_drought_index(p, t, pa, kbdi0, kbdi: float): # pragma: no cov
nopython=True,
cache=True,
)
def _griffiths_drought_factor(p, smd, lim, df): # pragma: no cover # noqa: C901
def _griffiths_drought_factor(p, smd, lim, df):
"""Compute the Griffiths drought factor.

Parameters
Expand Down Expand Up @@ -248,11 +249,7 @@ def _keetch_byram_drought_index_pass(pr, tasmax, pr_annual, kbdi0):
--------
DO NOT CALL DIRECTLY, use `keetch_byram_drought_index` instead.
"""
# fmt: off
return _keetch_byram_drought_index( # pylint: disable=no-value-for-parameter
pr, tasmax, pr_annual, kbdi0
)
# fmt: on
return _keetch_byram_drought_index(pr, tasmax, pr_annual, kbdi0)

pr = convert_units_to(pr, "mm/day", context="hydro")
tasmax = convert_units_to(tasmax, "C")
Expand Down Expand Up @@ -330,11 +327,7 @@ def _griffiths_drought_factor_pass(pr, smd, lim):
--------
DO NOT CALL DIRECTLY, use `griffiths_drought_factor` instead.
"""
# fmt: off
return _griffiths_drought_factor( # pylint: disable=no-value-for-parameter
pr, smd, lim
)
# fmt: on
return _griffiths_drought_factor(pr, smd, lim)

pr = convert_units_to(pr, "mm/day", context="hydro")
smd = convert_units_to(smd, "mm/day")
Expand Down
10 changes: 3 additions & 7 deletions xclim/sdba/nbutils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=no-value-for-parameter
"""
Numba-accelerated Utilities
===========================
Expand Down Expand Up @@ -34,7 +35,7 @@ def vecquantiles(da: DataArray, rnk: DataArray, dim: str | DataArray.dims) -> Da
da = da.transpose(*rnk.dims, tem)

res = DataArray(
_vecquantiles(da.values, rnk.values), # pylint: disable=no-value-for-parameter
_vecquantiles(da.values, rnk.values),
dims=rnk.dims,
coords=rnk.coords,
attrs=da.attrs,
Expand Down Expand Up @@ -184,12 +185,7 @@ def _first_and_last_nonnull(arr):


@njit
def _extrapolate_on_quantiles(
# fmt: off
interp, oldx, oldg, oldy, newx, newg, method="constant"
# noqa
# fmt: on
):
def _extrapolate_on_quantiles(interp, oldx, oldg, oldy, newx, newg, method="constant"):
"""Apply extrapolation to the output of interpolation on quantiles with a given grouping.

Arguments are the same as _interp_on_quantiles_2D.
Expand Down
3 changes: 2 additions & 1 deletion xclim/testing/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=no-member,missing-kwoa
"""
SDBA Diagnostic Testing Module
==============================
Expand Down Expand Up @@ -128,7 +129,7 @@ def adapt_freq_graph():
x = series(synth_rainfall(2, 2, wet_freq=0.25, size=n), "pr") # sim
y = series(synth_rainfall(2, 2, wet_freq=0.5, size=n), "pr") # ref

xp = adapt_freq(x, y, thresh=0).sim_ad # pylint: disable=no-member,missing-kwoa
xp = adapt_freq(x, y, thresh=0).sim_ad # noqa

fig, (ax1, ax2) = plt.subplots(2, 1)
sx = x.sortby(x)
Expand Down
Loading