Skip to content

Commit

Permalink
[MRG+1] Change how we implement show_versions() (#551)
Browse files Browse the repository at this point in the history
* Change how we implement show_versions()

* Lil fix for scikit

* Make it work on 3.7 too

* Properly handle versions

* Fix?

* Lint

* Import setuptools before pip

* Lil cleanup and lint
  • Loading branch information
aaronreidsmith authored Jul 3, 2023
1 parent b43d419 commit 1bb0ef5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nightly_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
schedule:
- cron: '0 7 * * *' # Every day at 07:00 UTC (1AM CST or 2AM CDT)

# Allows us to run manually
workflow_dispatch:

# Cancel older runs of the same workflow on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
42 changes: 30 additions & 12 deletions pmdarima/utils/_show_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import platform
import sys
import importlib

_pmdarima_deps = (
"pip",
# setuptools needs to be before pip: https://github.com/pypa/setuptools/issues/3044#issuecomment-1024972548 # noqa:E501
"setuptools",
"pip",
"sklearn",
"statsmodels",
"numpy",
Expand All @@ -23,6 +23,11 @@
"pmdarima",
)

# Packages that have a different import name than name on PyPI
_install_mapping = {
"sklearn": "scikit-learn"
}


def _get_sys_info():
"""System information
Expand Down Expand Up @@ -57,16 +62,29 @@ def get_version(module):

deps_info = {}

for modname in deps:
try:
if modname in sys.modules:
mod = sys.modules[modname]
else:
mod = importlib.import_module(modname)
ver = get_version(mod)
deps_info[modname] = ver
except ImportError:
deps_info[modname] = None
# TODO: We can get rid of this when we deprecate 3.7
if sys.version_info.minor <= 7:
import importlib

for modname in deps:
try:
if modname in sys.modules:
mod = sys.modules[modname]
else:
mod = importlib.import_module(modname)
ver = get_version(mod)
deps_info[modname] = ver
except ImportError:
deps_info[modname] = None

else:
from importlib.metadata import PackageNotFoundError, version

for modname in deps:
try:
deps_info[modname] = version(_install_mapping.get(modname, modname)) # noqa:E501
except PackageNotFoundError:
deps_info[modname] = None

return deps_info

Expand Down

0 comments on commit 1bb0ef5

Please sign in to comment.