From 26e51aaeb8abf14cf9ca929b2b4a3e3803e37fe4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 18:50:44 +0000 Subject: [PATCH 1/7] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.1.0 → 23.3.0](https://github.com/psf/black/compare/23.1.0...23.3.0) - [github.com/charliermarsh/ruff-pre-commit: v0.0.254 → v0.0.260](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.254...v0.0.260) - [github.com/nbQA-dev/nbQA: 1.6.3 → 1.7.0](https://github.com/nbQA-dev/nbQA/compare/1.6.3...1.7.0) - [github.com/MarcoGorelli/cython-lint: v0.12.5 → v0.15.0](https://github.com/MarcoGorelli/cython-lint/compare/v0.12.5...v0.15.0) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 934229ed31a..45ba371defd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: - id: check-yaml - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.3.0 hooks: - id: black-jupyter @@ -39,13 +39,13 @@ repos: additional_dependencies: [black==23.1.0] - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.254 + rev: v0.0.260 hooks: - id: ruff args: [--fix] - repo: https://github.com/nbQA-dev/nbQA - rev: 1.6.3 + rev: 1.7.0 hooks: - id: nbqa-ruff args: [--fix, --extend-ignore=E402] @@ -56,7 +56,7 @@ repos: - id: rst-backticks - repo: https://github.com/MarcoGorelli/cython-lint - rev: v0.12.5 + rev: v0.15.0 hooks: - id: cython-lint args: [--no-pycodestyle] From 26ca605c03e135b664956b4fa75b46f5badab30e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 18:52:43 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- yt/funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/funcs.py b/yt/funcs.py index 3f48268a063..cbbc30c96ec 100644 --- a/yt/funcs.py +++ b/yt/funcs.py @@ -607,7 +607,7 @@ def fancy_download_file(url, filename, requests=None): iterations = int(float(total_length) / float(blocksize)) pbar = get_pbar( - "Downloading %s to %s " % os.path.split(filename)[::-1], iterations + "Downloading {} to {} ".format(*os.path.split(filename)[::-1]), iterations ) iteration = 0 for chunk in response.iter_content(chunk_size=blocksize): From ecdf8ced3f5e9b684b8c3dc25fcc0d98684f00a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Mon, 3 Apr 2023 21:02:50 +0200 Subject: [PATCH 3/7] MNT: cleanup unused target-version option in ruff --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6ae9b5ee205..da45de8149c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -265,7 +265,6 @@ exclude = ''' ''' [tool.ruff] -target-version = "py38" # https://github.com/charliermarsh/ruff/issues/2039 exclude = [ "doc", "benchmarks", From 8b539cc3bb1ecaaaf89af212be77402e26b8e2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Mon, 3 Apr 2023 21:29:17 +0200 Subject: [PATCH 4/7] STY: add explicit stacklevel argument to warnings.warn calls (B028) --- yt/data_objects/construction_data_containers.py | 1 + yt/data_objects/static_output.py | 3 ++- yt/frontends/amrvac/data_structures.py | 1 + yt/loaders.py | 3 ++- yt/utilities/answer_testing/framework.py | 3 ++- yt/utilities/configure.py | 7 +++++-- yt/visualization/_commons.py | 3 ++- yt/visualization/base_plot_types.py | 3 ++- yt/visualization/plot_container.py | 3 ++- yt/visualization/plot_modifications.py | 5 +++-- 10 files changed, 22 insertions(+), 10 deletions(-) diff --git a/yt/data_objects/construction_data_containers.py b/yt/data_objects/construction_data_containers.py index e8cb0486663..016ca47f246 100644 --- a/yt/data_objects/construction_data_containers.py +++ b/yt/data_objects/construction_data_containers.py @@ -1490,6 +1490,7 @@ def _fill_fields(self, fields): "This is likely due to missing ghost-zones support " f"in class {type(self.ds)}", category=RuntimeWarning, + stacklevel=1, ) mylog.debug("Caught %d runtime errors.", runtime_errors_count) for field, v in zip(fields, ls.fields): diff --git a/yt/data_objects/static_output.py b/yt/data_objects/static_output.py index 39b66ff254f..7ce7f8f1c5c 100644 --- a/yt/data_objects/static_output.py +++ b/yt/data_objects/static_output.py @@ -236,7 +236,8 @@ def __init_subclass__(cls, *args, **kwargs): warnings.warn( f"Overwritting {cls.__name__}, which was previously registered. " "This is expected if you're importing a yt extension with a " - "frontend that was already migrated to the main code base." + "frontend that was already migrated to the main code base.", + stacklevel=2, ) output_type_registry[cls.__name__] = cls mylog.debug("Registering: %s as %s", cls.__name__, cls) diff --git a/yt/frontends/amrvac/data_structures.py b/yt/frontends/amrvac/data_structures.py index 4ddbd0289da..d5c66bda339 100644 --- a/yt/frontends/amrvac/data_structures.py +++ b/yt/frontends/amrvac/data_structures.py @@ -97,6 +97,7 @@ def retrieve_ghost_zones(self, n_zones, fields, all_levels=False, smoothed=False "ghost-zones interpolation/smoothing is not " "currently supported for AMRVAC data.", category=RuntimeWarning, + stacklevel=2, ) smoothed = False return super().retrieve_ghost_zones( diff --git a/yt/loaders.py b/yt/loaders.py index 0974abef632..57cffd81b5c 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -1678,7 +1678,8 @@ def load_archive( """ warnings.warn( - "The 'load_archive' function is still experimental and may be unstable." + "The 'load_archive' function is still experimental and may be unstable.", + stacklevel=2, ) fn = os.path.expanduser(fn) diff --git a/yt/utilities/answer_testing/framework.py b/yt/utilities/answer_testing/framework.py index 0e72ffe6b90..c738b408baf 100644 --- a/yt/utilities/answer_testing/framework.py +++ b/yt/utilities/answer_testing/framework.py @@ -797,7 +797,8 @@ def ensure_image_comparability(a, b): warnings.warn( f"Images have different shapes {a.shape} and {b.shape}. " - "Padding nans to make them comparable." + "Padding nans to make them comparable.", + stacklevel=2, ) smallest_containing_shape = ( max(a.shape[0], b.shape[0]), diff --git a/yt/utilities/configure.py b/yt/utilities/configure.py index adcf9d262b3..7894b63314f 100644 --- a/yt/utilities/configure.py +++ b/yt/utilities/configure.py @@ -94,7 +94,8 @@ def read(self, file_names): data = tomllib.load(fh) except tomllib.TOMLDecodeError as exc: warnings.warn( - f"Could not load configuration file {fname} (invalid TOML: {exc})" + f"Could not load configuration file {fname} (invalid TOML: {exc})", + stacklevel=2, ) else: self.update(data, metadata=metadata) @@ -117,7 +118,9 @@ def write(self, file_handler): else: pdir = file_path.parent if not pdir.exists(): - warnings.warn(f"{pdir!s} does not exist, creating it (recursively)") + warnings.warn( + f"{pdir!s} does not exist, creating it (recursively)", stacklevel=2 + ) os.makedirs(pdir) file_path.write_text(config_as_str) diff --git a/yt/visualization/_commons.py b/yt/visualization/_commons.py index f07484cf9a9..6f87f949cba 100644 --- a/yt/visualization/_commons.py +++ b/yt/visualization/_commons.py @@ -96,7 +96,8 @@ def validate_image_name(filename, suffix: Optional[str] = None) -> str: if suffix in _get_supported_image_file_formats() and suffix != psuffix: warnings.warn( f"Received two valid image formats {psuffix!r} (from filename) " - f"and {suffix!r} (from suffix). The former is ignored." + f"and {suffix!r} (from suffix). The former is ignored.", + stacklevel=2, ) return f"{name}.{suffix}" return str(filename) diff --git a/yt/visualization/base_plot_types.py b/yt/visualization/base_plot_types.py index a4e782eb228..7e6d8b6893e 100644 --- a/yt/visualization/base_plot_types.py +++ b/yt/visualization/base_plot_types.py @@ -337,7 +337,8 @@ def _set_axes(self, norm: Normalize) -> None: "with matplotlib versions older than 3.5\n" "Please try upgrading matplotlib to a more recent version. " "If the problem persists, please file a report to " - "https://github.com/yt-project/yt/issues/new" + "https://github.com/yt-project/yt/issues/new", + stacklevel=2, ) else: raise exc diff --git a/yt/visualization/plot_container.py b/yt/visualization/plot_container.py index eb2b307445f..6b5198ba28a 100644 --- a/yt/visualization/plot_container.py +++ b/yt/visualization/plot_container.py @@ -532,7 +532,8 @@ def save( if new_suffix != suffix: warnings.warn( f"Overriding suffix {suffix!r} with mpl_kwargs['format'] = {new_suffix!r}. " - "Use the `suffix` argument directly to suppress this warning." + "Use the `suffix` argument directly to suppress this warning.", + stacklevel=2, ) suffix = new_suffix diff --git a/yt/visualization/plot_modifications.py b/yt/visualization/plot_modifications.py index c050e35e928..2adb5487dac 100644 --- a/yt/visualization/plot_modifications.py +++ b/yt/visualization/plot_modifications.py @@ -1714,7 +1714,7 @@ def __call__(self, plot): dy = (yy1 - yy0) * 2 ** (0.5) * self.length # If the arrow is 0 length if dx == dy == 0: - warnings.warn("The arrow has zero length. Not annotating.") + warnings.warn("The arrow has zero length. Not annotating.", stacklevel=2) return x, y, dx, dy = self._sanitize_xy_order(plot, x, y, dx, dy) @@ -2586,7 +2586,8 @@ def __call__(self, plot): if self.redshift and not hasattr(plot.data.ds, "current_redshift"): warnings.warn( f"dataset {plot.data.ds} does not have current_redshift attribute. " - "Set redshift=False to silence this warning." + "Set redshift=False to silence this warning.", + stacklevel=2, ) self.redshift = False From 317a22c189c8547ad0a3987e635185d786b21e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Mon, 3 Apr 2023 21:34:41 +0200 Subject: [PATCH 5/7] STY: disable spurious linter warning (B018) --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index da45de8149c..62aea0b84d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -292,6 +292,7 @@ select = [ ignore = [ "E501", # line too long "E741", # Do not use variables named 'I', 'O', or 'l' + "B018", # Found useless expression. # disabled because ds.index is idiomatic ] From 5ccbc32e9c9c11f99f5262d07c0281807f8cd53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 5 Apr 2023 10:30:23 +0200 Subject: [PATCH 6/7] MNT: upgrade ruff (get by false positives with B030) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45ba371defd..0943441ed39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: additional_dependencies: [black==23.1.0] - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.260 + rev: v0.0.261 hooks: - id: ruff args: [--fix] From b3fe5fc095f68ad0836fbf9dd3b3508b0cd34fce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Apr 2023 08:37:07 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- yt/funcs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yt/funcs.py b/yt/funcs.py index cbbc30c96ec..6be779b9257 100644 --- a/yt/funcs.py +++ b/yt/funcs.py @@ -607,7 +607,8 @@ def fancy_download_file(url, filename, requests=None): iterations = int(float(total_length) / float(blocksize)) pbar = get_pbar( - "Downloading {} to {} ".format(*os.path.split(filename)[::-1]), iterations + "Downloading {} to {} ".format(*os.path.split(filename)[::-1]), + iterations, ) iteration = 0 for chunk in response.iter_content(chunk_size=blocksize):