Skip to content

Commit 931bcb5

Browse files
AnasNaouchiAnas Naouchi
andauthored
Fix deprecated pkg (#78)
## Description Replaced deprecated `pkg_resources` with `importlib.metadata` to prevent warnings in Python 3.12+. closes #77 --------- Co-authored-by: Anas Naouchi <anas.n@AnasN-MacBook-Pro-M1.local>
1 parent 2851e6a commit 931bcb5

5 files changed

Lines changed: 26 additions & 4 deletions

File tree

.github/workflows/publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ jobs:
1818
python-version: 3.9
1919

2020
- name: Build and Upload
21+
env:
22+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
2123
run: |
2224
python -m venv venv
2325
source venv/bin/activate
2426
pip install --upgrade pip twine wheel
2527
python setup.py sdist bdist_wheel
26-
twine upload dist/* --verbose --username __token__ --password ${{ secrets.PYPI_TOKEN }}
28+
twine upload dist/* --username __token__ --password "$PYPI_TOKEN"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.15.1] - 2025-10-28
4+
5+
- [Fixed] Replaced deprecated `pkg_resources` with `importlib.metadata` to prevent warnings in Python 3.12+ (https://github.com/omise/omise-python/pull/77)
6+
37
## [0.15.0] - 2025-02-06
48

59
* [Added] Add date filtering for charge list (https://github.com/omise/omise-python/pull/75)

omise/test/test_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
from unittest import mock
3+
4+
class VersionTest(unittest.TestCase):
5+
@mock.patch("importlib.metadata.version", side_effect=__import__("importlib").metadata.PackageNotFoundError)
6+
def test_version_package_not_found(self, mock_version):
7+
"""Ensure that PackageNotFoundError sets version to 'unknown'."""
8+
from importlib import reload
9+
import omise.version as omise_version
10+
11+
# Reload module so the import runs again and triggers our mock
12+
reload(omise_version)
13+
self.assertEqual(omise_version.__VERSION__, "unknown")

omise/version.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
import pkg_resources
2-
__VERSION__ = pkg_resources.require('omise')[0].version
1+
from importlib.metadata import version, PackageNotFoundError
2+
try:
3+
__VERSION__ = version("omise")
4+
except PackageNotFoundError:
5+
__VERSION__ = "unknown"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
setup(name='omise',
1919
long_description=long_description,
2020
long_description_content_type='text/markdown',
21-
version='0.15.0',
21+
version='0.15.1',
2222
description='Omise Python client',
2323
author='Omise',
2424
author_email='support@omise.co',

0 commit comments

Comments
 (0)