From b497a6bfe6b02640db8abf306154ff9b31f6d6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Mon, 9 Sep 2024 09:58:52 +0100 Subject: [PATCH 1/9] Release 1.1.1 Release PR for 1.1.1 * hotfix for package name change - fixes #1664 * version number bump * changelog --- CHANGELOG.md | 7 +++++++ pyproject.toml | 4 ++-- pytorch_forecasting/__init__.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec41bcbe..2980ed99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Release Notes +## v1.1.1 + +Hotfix for accidental package name change in `pyproject.toml`. + +The package name is now corrected to `pytorch-forecasting`. + + ## v1.1.0 Maintenance update widening compatibility ranges and consolidating dependencies: diff --git a/pyproject.toml b/pyproject.toml index a9973227..7bcb0096 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,9 +27,9 @@ isort = 1 black = 1 [project] -name = "pytorch_forecasting" +name = "pytorch-forecasting" readme = "README.md" # Markdown files are supported -version = "1.1.0" # is being replaced automatically +version = "1.1.1" # is being replaced automatically authors = [ {name = "Jan Beitner"}, diff --git a/pytorch_forecasting/__init__.py b/pytorch_forecasting/__init__.py index 05ef9575..693dce3c 100644 --- a/pytorch_forecasting/__init__.py +++ b/pytorch_forecasting/__init__.py @@ -112,4 +112,4 @@ "unpack_sequence", ] -__version__ = "1.1.0" +__version__ = "1.1.1" From f233d9294a056d4a24d1a660d810425782cbeeb2 Mon Sep 17 00:00:00 2001 From: Felix Hirwa Nshuti Date: Fri, 13 Sep 2024 21:35:45 +0530 Subject: [PATCH 2/9] [MNT] handle `mps backend` for lower versions of pytorch and fix `mps` failure on `macOS-latest` runner (#1648) ### Description This PR handles the issue that may result when setting the device to `mps` if the torch version doesn't support `mps backend` Depends on https://github.com/jdb78/pytorch-forecasting/pull/1633 I used `pytest.MonkeyPatch()` to disable the discovery of the `mps` accelerator. The tests run on CPU for `macOS-latest` fixes https://github.com/jdb78/pytorch-forecasting/issues/1596 --- .github/workflows/test.yml | 2 +- pytorch_forecasting/utils/_utils.py | 9 ++++++++- tests/conftest.py | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c307f487..df77fd42 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -79,7 +79,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-13, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: diff --git a/pytorch_forecasting/utils/_utils.py b/pytorch_forecasting/utils/_utils.py index e6c6dcf4..1236ca66 100644 --- a/pytorch_forecasting/utils/_utils.py +++ b/pytorch_forecasting/utils/_utils.py @@ -429,7 +429,14 @@ def move_to_device( x on targeted device """ if isinstance(device, str): - device = torch.device(device) + if device == "mps": + if hasattr(torch.backends, device): + if torch.backends.mps.is_available() and torch.backends.mps.is_built(): + device = torch.device("mps") + else: + device = torch.device("cpu") + else: + device = torch.device(device) if isinstance(x, dict): for name in x.keys(): x[name] = move_to_device(x[name], device=device) diff --git a/tests/conftest.py b/tests/conftest.py index fae78848..58dd0189 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -69,3 +69,9 @@ def test_dataset(test_data): randomize_length=None, ) return training + + +@pytest.fixture(autouse=True) +def disable_mps(monkeypatch): + """Disable MPS for all tests""" + monkeypatch.setattr("torch._C._mps_is_available", lambda: False) From 588d10eb0d11be405f45ec9d8b3c5ecd5fb7a94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Fri, 20 Sep 2024 19:14:17 +0100 Subject: [PATCH 3/9] [MNT] updates the actions in the doc build CI (#1673) Fixes #1672 --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index df77fd42..c424361c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -137,15 +137,15 @@ jobs: shell: bash steps: - name: Check out Git repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: python-version: 3.11 - name: Cache pip - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }} @@ -162,7 +162,7 @@ jobs: run: make html --debug --jobs 2 SPHINXOPTS="-W" - name: Upload built docs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: docs-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }} path: docs/build/html/ From 623c150e2aa6a01a7496700d3a1ec58593fcacc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Fri, 20 Sep 2024 19:22:32 +0100 Subject: [PATCH 4/9] Update .readthedocs.yml --- .readthedocs.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 82fc2f91..3ccfba15 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -19,8 +19,11 @@ sphinx: formats: - htmlzip +build: + os: ubuntu-22.04 + # Optionally set the version of Python and requirements required to build your docs python: - version: 3.11 + version: 3.12 install: - requirements: docs/requirements.txt From 491462a04586d5dc25dc45cf858d1e7506b48ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Fri, 20 Sep 2024 19:34:21 +0100 Subject: [PATCH 5/9] [MNT] Add `build` config in `readthedocs.yml` --- .readthedocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index 3ccfba15..3fe3ed82 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -21,6 +21,8 @@ formats: build: os: ubuntu-22.04 + tools: + python: "3.12" # Optionally set the version of Python and requirements required to build your docs python: From 94f9897735a541096098eba971a0df146bec3a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Fri, 20 Sep 2024 19:51:19 +0100 Subject: [PATCH 6/9] [MNT] fixes to `readthedocs.yml` (#1676) Fixes `readthedocs.yml`, closes #1675 --- .readthedocs.yml | 7 ++++--- pyproject.toml | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 3fe3ed82..c633039a 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -24,8 +24,9 @@ build: tools: python: "3.12" -# Optionally set the version of Python and requirements required to build your docs python: - version: 3.12 install: - - requirements: docs/requirements.txt + - method: pip + path: . + extra_requirements: + - docs diff --git a/pyproject.toml b/pyproject.toml index 7bcb0096..3e52005c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,6 +133,17 @@ dev = [ "pandoc>=2.3,<3.0.0", ] +# docs - dependencies for building the documentation +docs = [ + "sphinx>3.2", + "pydata-sphinx-theme", + "nbsphinx", + "pandoc", + "nbconvert", + "recommonmark", + "docutils", +] + github-actions = ["pytest-github-actions-annotate-failures"] [tool.setuptools.packages.find] From 94a2467221d974be3f9dc0acbac76d09a9cb92d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Fri, 20 Sep 2024 20:14:21 +0100 Subject: [PATCH 7/9] [MNT] updates references in CI and doc locations to `main` (#1677) This updates references to the main branch in CI and doc locations to `main` --- .github/workflows/lint.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- README.md | 6 +++--- docs/source/conf.py | 2 +- docs/source/tutorials.rst | 2 +- pytorch_forecasting/data/examples.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f05e5211..9b91811b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,9 +2,9 @@ name: Lint on: push: - branches: [master] + branches: [main] pull_request: - branches: [master] + branches: [main] jobs: pre-commit-hooks: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c424361c..2a39eb2d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,9 +5,9 @@ name: Test on: push: - branches: [master] + branches: [main] pull_request: - branches: [master] + branches: [main] concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/README.md b/README.md index cf4a356e..17794bf6 100755 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ _PyTorch Forecasting_ is a PyTorch-based package for forecasting with state-of-t | | **[Documentation](https://pytorch-forecasting.readthedocs.io)** · **[Tutorials](https://pytorch-forecasting.readthedocs.io/en/latest/tutorials.html)** · **[Release Notes](https://pytorch-forecasting.readthedocs.io/en/latest/CHANGELOG.html)** | |---|---| -| **Open Source** | [![MIT](https://img.shields.io/github/license/jdb78/pytorch-forecasting)](https://github.com/jdb78/pytorch-forecasting/blob/master/LICENSE) | +| **Open Source** | [![MIT](https://img.shields.io/github/license/jdb78/pytorch-forecasting)](https://github.com/jdb78/pytorch-forecasting/blob/main/LICENSE) | | **Community** | [![!discord](https://img.shields.io/static/v1?logo=discord&label=discord&message=chat&color=lightgreen)](https://discord.com/invite/54ACzaFsn7) [![!slack](https://img.shields.io/static/v1?logo=linkedin&label=LinkedIn&message=news&color=lightblue)](https://www.linkedin.com/company/scikit-time/) | | **CI/CD** | [![github-actions](https://img.shields.io/github/actions/workflow/status/jdb78/pytorch-forecasting/pypi_release.yml?logo=github)](https://github.com/jdb78/pytorch-forecasting/actions/workflows/pypi_release.yml) [![readthedocs](https://img.shields.io/readthedocs/pytorch-forecasting?logo=readthedocs)](https://pytorch-forecasting.readthedocs.io) [![platform](https://img.shields.io/conda/pn/conda-forge/pytorch-forecasting)](https://github.com/jdb78/pytorch-forecasting) [![Code Coverage][coverage-image]][coverage-url] | | **Code** | [![!pypi](https://img.shields.io/pypi/v/pytorch-forecasting?color=orange)](https://pypi.org/project/pytorch-forecasting/) [![!conda](https://img.shields.io/conda/vn/conda-forge/pytorch-forecasting)](https://anaconda.org/conda-forge/pytorch-forecasting) [![!python-versions](https://img.shields.io/pypi/pyversions/pytorch-forecasting)](https://www.python.org/) [![!black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | -[coverage-image]: https://codecov.io/gh/jdb78/pytorch-forecasting/branch/master/graph/badge.svg -[coverage-url]: https://codecov.io/github/jdb78/pytorch-forecasting?branch=master +[coverage-image]: https://codecov.io/gh/jdb78/pytorch-forecasting/branch/main/graph/badge.svg +[coverage-url]: https://codecov.io/github/jdb78/pytorch-forecasting?branch=main --- diff --git a/docs/source/conf.py b/docs/source/conf.py index 60128395..afce813c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -2,7 +2,7 @@ # # This file only contains a selection of the most common options. For a full # list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html +# https://www.sphinx-doc.org/en/main/usage/configuration.html # -- Path setup -------------------------------------------------------------- diff --git a/docs/source/tutorials.rst b/docs/source/tutorials.rst index d85a2c23..c8282719 100644 --- a/docs/source/tutorials.rst +++ b/docs/source/tutorials.rst @@ -3,7 +3,7 @@ Tutorials .. _tutorials: -The following tutorials can be also found as `notebooks on GitHub `_. +The following tutorials can be also found as `notebooks on GitHub `_. .. toctree:: :titlesonly: diff --git a/pytorch_forecasting/data/examples.py b/pytorch_forecasting/data/examples.py index 03ae566a..79b7cb52 100644 --- a/pytorch_forecasting/data/examples.py +++ b/pytorch_forecasting/data/examples.py @@ -8,7 +8,7 @@ import numpy as np import pandas as pd -BASE_URL = "https://github.com/jdb78/pytorch-forecasting/raw/master/examples/data/" +BASE_URL = "https://github.com/sktime/pytorch-forecasting/raw/main/examples/data/" DATA_PATH = Path(__file__).parent From 199c0b48440e3e123b35260482affe6a55c745f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Sat, 21 Sep 2024 07:05:03 +0100 Subject: [PATCH 8/9] [DOC] update URLs to `sktime` org (#1674) This PR updatse URLs to the `sktime` GH org. There should not be any failures at the moment since GH remembers the old org and forwards. In essence a bulk-replace with exceptions where references to the old org and @jdb78 still make sense, e.g., the old org in changelogs, or @jdb78 referenced as individual contributor. --- README.md | 8 ++++---- docs/source/_static/custom.css | 2 +- docs/source/conf.py | 4 ++-- docs/source/index.rst | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) mode change 100755 => 100644 README.md diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 17794bf6..b3b162c7 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ _PyTorch Forecasting_ is a PyTorch-based package for forecasting with state-of-t | | **[Documentation](https://pytorch-forecasting.readthedocs.io)** · **[Tutorials](https://pytorch-forecasting.readthedocs.io/en/latest/tutorials.html)** · **[Release Notes](https://pytorch-forecasting.readthedocs.io/en/latest/CHANGELOG.html)** | |---|---| -| **Open Source** | [![MIT](https://img.shields.io/github/license/jdb78/pytorch-forecasting)](https://github.com/jdb78/pytorch-forecasting/blob/main/LICENSE) | +| **Open Source** | [![MIT](https://img.shields.io/github/license/sktime/pytorch-forecasting)](https://github.com/sktime/pytorch-forecasting/blob/master/LICENSE) | | **Community** | [![!discord](https://img.shields.io/static/v1?logo=discord&label=discord&message=chat&color=lightgreen)](https://discord.com/invite/54ACzaFsn7) [![!slack](https://img.shields.io/static/v1?logo=linkedin&label=LinkedIn&message=news&color=lightblue)](https://www.linkedin.com/company/scikit-time/) | -| **CI/CD** | [![github-actions](https://img.shields.io/github/actions/workflow/status/jdb78/pytorch-forecasting/pypi_release.yml?logo=github)](https://github.com/jdb78/pytorch-forecasting/actions/workflows/pypi_release.yml) [![readthedocs](https://img.shields.io/readthedocs/pytorch-forecasting?logo=readthedocs)](https://pytorch-forecasting.readthedocs.io) [![platform](https://img.shields.io/conda/pn/conda-forge/pytorch-forecasting)](https://github.com/jdb78/pytorch-forecasting) [![Code Coverage][coverage-image]][coverage-url] | +| **CI/CD** | [![github-actions](https://img.shields.io/github/actions/workflow/status/sktime/pytorch-forecasting/pypi_release.yml?logo=github)](https://github.com/sktime/pytorch-forecasting/actions/workflows/pypi_release.yml) [![readthedocs](https://img.shields.io/readthedocs/pytorch-forecasting?logo=readthedocs)](https://pytorch-forecasting.readthedocs.io) [![platform](https://img.shields.io/conda/pn/conda-forge/pytorch-forecasting)](https://github.com/sktime/pytorch-forecasting) [![Code Coverage][coverage-image]][coverage-url] | | **Code** | [![!pypi](https://img.shields.io/pypi/v/pytorch-forecasting?color=orange)](https://pypi.org/project/pytorch-forecasting/) [![!conda](https://img.shields.io/conda/vn/conda-forge/pytorch-forecasting)](https://anaconda.org/conda-forge/pytorch-forecasting) [![!python-versions](https://img.shields.io/pypi/pyversions/pytorch-forecasting)](https://www.python.org/) [![!black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | -[coverage-image]: https://codecov.io/gh/jdb78/pytorch-forecasting/branch/main/graph/badge.svg -[coverage-url]: https://codecov.io/github/jdb78/pytorch-forecasting?branch=main +[coverage-image]: https://codecov.io/gh/sktime/pytorch-forecasting/branch/main/graph/badge.svg +[coverage-url]: https://codecov.io/github/sktime/pytorch-forecasting?branch=main --- diff --git a/docs/source/_static/custom.css b/docs/source/_static/custom.css index 45ed7dbb..70b848a1 100644 --- a/docs/source/_static/custom.css +++ b/docs/source/_static/custom.css @@ -25,7 +25,7 @@ a.nav-link color: #647db6 !important; } -a.nav-link[href="https://github.com/jdb78/pytorch-forecasting"] +a.nav-link[href="https://github.com/sktime/pytorch-forecasting"] { color: #ee4c2c !important; } diff --git a/docs/source/conf.py b/docs/source/conf.py index afce813c..4c6b40ff 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -141,11 +141,11 @@ def setup(app: Sphinx): # theme options html_theme_options = { - "github_url": "https://github.com/jdb78/pytorch-forecasting", + "github_url": "https://github.com/sktime/pytorch-forecasting", "navbar_end": ["navbar-icon-links.html", "search-field.html"], "show_nav_level": 2, "header_links_before_dropdown": 10, - "external_links": [{"name": "GitHub", "url": "https://github.com/jdb78/pytorch-forecasting"}], + "external_links": [{"name": "GitHub", "url": "https://github.com/sktime/pytorch-forecasting"}], } html_sidebars = { diff --git a/docs/source/index.rst b/docs/source/index.rst index 24cf93d7..8b833f4b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -8,7 +8,7 @@ PyTorch Forecasting Documentation .. raw:: html - GitHub + GitHub Our article on `Towards Data Science `_ From fdf8a7fa5dfd5c3d5dda3e31683a90e990c2d7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Kir=C3=A1ly?= Date: Mon, 30 Sep 2024 12:53:45 +0100 Subject: [PATCH 9/9] [MNT] `show_versions` utility (#1688) Adds a `show_versions` utility for users to easily share version information in bug reports or questions. Adapted from `sktime`, which in turn is an evolution of the `sklearn` utility of the same name. --- pytorch_forecasting/__init__.py | 6 +- pytorch_forecasting/utils/_maint/__init__.py | 0 .../utils/_maint/_show_versions.py | 142 ++++++++++++++++++ tests/test_utils/test_show_versions.py | 42 ++++++ 4 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 pytorch_forecasting/utils/_maint/__init__.py create mode 100644 pytorch_forecasting/utils/_maint/_show_versions.py create mode 100644 tests/test_utils/test_show_versions.py diff --git a/pytorch_forecasting/__init__.py b/pytorch_forecasting/__init__.py index 693dce3c..47f92761 100644 --- a/pytorch_forecasting/__init__.py +++ b/pytorch_forecasting/__init__.py @@ -2,6 +2,8 @@ PyTorch Forecasting package for timeseries forecasting with PyTorch. """ +__version__ = "1.1.1" + from pytorch_forecasting.data import ( EncoderNormalizer, GroupNormalizer, @@ -59,6 +61,7 @@ to_list, unpack_sequence, ) +from pytorch_forecasting.utils._maint._show_versions import show_versions __all__ = [ "TimeSeriesDataSet", @@ -109,7 +112,6 @@ "integer_histogram", "groupby_apply", "profile", + "show_versions", "unpack_sequence", ] - -__version__ = "1.1.1" diff --git a/pytorch_forecasting/utils/_maint/__init__.py b/pytorch_forecasting/utils/_maint/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pytorch_forecasting/utils/_maint/_show_versions.py b/pytorch_forecasting/utils/_maint/_show_versions.py new file mode 100644 index 00000000..1d8a803f --- /dev/null +++ b/pytorch_forecasting/utils/_maint/_show_versions.py @@ -0,0 +1,142 @@ +# License: BSD 3 clause +"""Utility methods to print system info for debugging. + +adapted from +:func: `sklearn.show_versions` and `sktime.show_versions` +""" + +__all__ = ["show_versions"] + +import importlib +import platform +import sys + + +def _get_sys_info(): + """System information. + + Return + ------ + sys_info : dict + system and Python version information + """ + python = sys.version.replace("\n", " ") + + blob = [ + ("python", python), + ("executable", sys.executable), + ("machine", platform.platform()), + ] + + return dict(blob) + + +# dependencies to print versions of, by default +DEFAULT_DEPS_TO_SHOW = [ + "pip", + "pytorch-forecasting", + "torch", + "lightning", + "numpy", + "scipy", + "pandas", + "cpflows", + "matplotlib", + "optuna", + "optuna-integration", + "pytorch_optimizer", + "scikit-learn", + "scikit-base", + "statsmodels", +] + + +def _get_deps_info(deps=None, source="distributions"): + """Overview of the installed version of main dependencies. + + Parameters + ---------- + deps : optional, list of strings with package names + if None, behaves as deps = ["sktime"]. + + source : str, optional one of "distributions" (default) or "import" + source of version information + + * "distributions" - uses importlib.distributions. In this case, + strings in deps are assumed to be PEP 440 package strings, + e.g., scikit-learn, not sklearn. + * "import" - uses the __version__ attribute of the module. + In this case, strings in deps are assumed to be import names, + e.g., sklearn, not scikit-learn. + + Returns + ------- + deps_info: dict + version information on libraries in `deps` + keys are package names, import names if source is "import", + and PEP 440 package strings if source is "distributions"; + values are PEP 440 version strings + of the import as present in the current python environment + """ + if deps is None: + deps = ["pytorch-forecasting"] + + if source == "distributions": + from pytorch_forecasting.utils._dependencies import _get_installed_packages + + KEY_ALIAS = {"sklearn": "scikit-learn", "skbase": "scikit-base"} + + pkgs = _get_installed_packages() + + deps_info = {} + for modname in deps: + pkg_name = KEY_ALIAS.get(modname, modname) + deps_info[modname] = pkgs.get(pkg_name, None) + + return deps_info + + def get_version(module): + return getattr(module, "__version__", None) + + deps_info = {} + + for modname in deps: + try: + if modname in sys.modules: + mod = sys.modules[modname] + else: + mod = importlib.import_module(modname) + except ImportError: + deps_info[modname] = None + else: + ver = get_version(mod) + deps_info[modname] = ver + + return deps_info + + +def show_versions(): + """Print python version, OS version, sktime version, selected dependency versions. + + Pretty prints: + + * python version of environment + * python executable location + * OS version + * list of import name and version number for selected python dependencies + + Developer note: + Python version/executable and OS version are from `_get_sys_info` + Package versions are retrieved by `_get_deps_info` + Selected dependencies are as in the DEFAULT_DEPS_TO_SHOW variable + """ + sys_info = _get_sys_info() + deps_info = _get_deps_info(deps=DEFAULT_DEPS_TO_SHOW) + + print("\nSystem:") # noqa: T001, T201 + for k, stat in sys_info.items(): + print(f"{k:>10}: {stat}") # noqa: T001, T201 + + print("\nPython dependencies:") # noqa: T001, T201 + for k, stat in deps_info.items(): + print(f"{k:>13}: {stat}") # noqa: T001, T201 diff --git a/tests/test_utils/test_show_versions.py b/tests/test_utils/test_show_versions.py new file mode 100644 index 00000000..7fa3626f --- /dev/null +++ b/tests/test_utils/test_show_versions.py @@ -0,0 +1,42 @@ +"""Tests for the show_versions utility.""" + +import pathlib +import uuid + +from pytorch_forecasting.utils._maint._show_versions import DEFAULT_DEPS_TO_SHOW, _get_deps_info, show_versions + + +def test_show_versions_runs(): + """Test that show_versions runs without exceptions.""" + # only prints, should return None + assert show_versions() is None + + +def test_show_versions_import_loc(): + """Test that show_version can be imported from root.""" + from pytorch_forecasting import show_versions as show_versions_imported + + assert show_versions == show_versions_imported + + +def test_deps_info(): + """Test that _get_deps_info returns package/version dict as per contract.""" + deps_info = _get_deps_info() + assert isinstance(deps_info, dict) + assert set(deps_info.keys()) == {"pytorch-forecasting"} + + deps_info_default = _get_deps_info(DEFAULT_DEPS_TO_SHOW) + assert isinstance(deps_info_default, dict) + assert set(deps_info_default.keys()) == set(DEFAULT_DEPS_TO_SHOW) + + +def test_deps_info_deps_missing_package_present_directory(): + """Test that _get_deps_info does not fail if a dependency is missing.""" + dummy_package_name = uuid.uuid4().hex + + dummy_folder_path = pathlib.Path(dummy_package_name) + dummy_folder_path.mkdir() + + assert _get_deps_info([dummy_package_name]) == {dummy_package_name: None} + + dummy_folder_path.rmdir()