From 4b7be858e7fba6b0b1f6f07fcd6347ede40e323f Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Tue, 25 Apr 2023 21:01:43 +0400 Subject: [PATCH] Removed usage of deprecated pkg_resources Define version instead in polymorphic/__init__.py file. --- polymorphic/__init__.py | 7 +------ setup.cfg | 1 - setup.py | 12 +++++++++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/polymorphic/__init__.py b/polymorphic/__init__.py index 128269f9..bb57871c 100644 --- a/polymorphic/__init__.py +++ b/polymorphic/__init__.py @@ -6,9 +6,4 @@ Please see LICENSE and AUTHORS for more information. """ -import pkg_resources - -try: - __version__ = pkg_resources.require("django-polymorphic")[0].version -except pkg_resources.DistributionNotFound: - __version__ = None # for RTD among others +__version__ = "3.1.0" diff --git a/setup.cfg b/setup.cfg index 09ff55a5..a3d7c9c7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [metadata] name = django-polymorphic -version = 3.1.0 description = Seamless polymorphic inheritance for Django models long_description = file:README.rst author = Bert Constantin diff --git a/setup.py b/setup.py index a8677b14..ebb91708 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import os +import re import sys from setuptools import find_packages, setup @@ -19,4 +20,13 @@ from setuptools import setup -setup() +def get_version(package): + """ + Return package version as listed in `__version__` in `init.py`. + """ + init_py = open(os.path.join(package, "__init__.py")).read() + return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) + +setup( + version=get_version("polymorphic"), +)