Skip to content

Commit 2d6d461

Browse files
authored
fix: ignore warnings when accessing __version__ (#118)
1 parent 4c2b057 commit 2d6d461

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
JUPYTER_PLATFORM_DIRS: '1'
1111

1212
jobs:
13-
linux:
13+
test:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
@@ -20,16 +20,16 @@ jobs:
2020
- python-version: '3.13'
2121
extras: min
2222
steps:
23-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v5
2424
with:
2525
fetch-depth: 0
2626
filter: blob:none
2727
- uses: actions/setup-python@v5
2828
with:
2929
python-version: ${{ matrix.python-version }}
30-
- uses: hynek/setup-cached-uv@v2
30+
- uses: astral-sh/setup-uv@v6
3131
with:
32-
cache-dependency-path: pyproject.toml
32+
enable-cache: true
3333
- run: uv pip install --system -e .[${{ matrix.extras == 'min' && 'test' || 'test,jupyter' }}]
3434
- uses: pavelzw/pytest-action@v2
3535
with:
@@ -38,3 +38,12 @@ jobs:
3838
verbose: true
3939
job-summary: true
4040
emoji: false
41+
check:
42+
if: always()
43+
needs:
44+
- test
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: re-actors/alls-green@release/v1
48+
with:
49+
jobs: ${{ toJSON(needs) }}

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
permissions:
1212
id-token: write # to authenticate as Trusted Publisher to pypi.org
1313
steps:
14-
- uses: actions/checkout@v4
15-
- uses: actions/setup-python@v4
14+
- uses: actions/checkout@v5
15+
- uses: actions/setup-python@v5
1616
with:
1717
python-version: "3.x"
1818
cache: pip

src/session_info2/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from importlib.metadata import version
1313
from types import MappingProxyType, ModuleType
1414
from typing import TYPE_CHECKING, Any, Literal, TypeAlias
15+
from warnings import catch_warnings, filterwarnings
1516

1617
from . import _pu
1718
from ._dists import packages_distributions
@@ -118,12 +119,15 @@ def __hash__(self) -> int:
118119
def _version(self, dist: str) -> str:
119120
"""Get version(s) of imported distribution."""
120121
v_meta = version(dist)
121-
vs_attr = {
122-
pkg_name: v
123-
for pkg_name in self.dist2pkgs[dist]
124-
if (pkg := sys.modules.get(pkg_name))
125-
and (v := getattr(pkg, "__version__", None))
126-
}
122+
with catch_warnings():
123+
filterwarnings("ignore", category=DeprecationWarning)
124+
filterwarnings("ignore", category=FutureWarning)
125+
vs_attr = {
126+
pkg_name: v
127+
for pkg_name in self.dist2pkgs[dist]
128+
if (pkg := sys.modules.get(pkg_name))
129+
and (v := getattr(pkg, "__version__", None))
130+
}
127131
if all(v_attr == v_meta for v_attr in vs_attr.values()):
128132
# This branch is also hit if there are no __version__ attributes
129133
return v_meta

0 commit comments

Comments
 (0)