]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: get package version from metadata
authorstengah <deepsghimire1@gmail.com>
Wed, 21 Dec 2022 16:00:33 +0000 (21:45 +0545)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 28 Dec 2022 20:20:45 +0000 (20:20 +0000)
psycopg/psycopg/_compat.py
psycopg/psycopg/version.py
psycopg/setup.cfg
psycopg/setup.py
psycopg_c/setup.py

index 7dbae79686d961bbb6992a4482a7cc49d1277e88..27dc5254f15cc58dd4e03196c71cba0589188875 100644 (file)
@@ -59,6 +59,11 @@ if sys.version_info >= (3, 11):
 else:
     from typing_extensions import LiteralString
 
+if sys.version_info < (3, 8):
+    import importlib_metadata as metadata
+else:
+    from importlib import metadata
+
 __all__ = [
     "Counter",
     "Deque",
@@ -69,4 +74,5 @@ __all__ = [
     "cache",
     "create_task",
     "prod",
+    "metadata",
 ]
index 74226eb522d0ce8f92a5d84f7b02284775623f55..c985316be659db596fbfd27915fdc5b7aaf2143e 100644 (file)
@@ -1,14 +1,14 @@
 """
 psycopg distribution version file.
 """
+from ._compat import metadata
 
 # Copyright (C) 2020 The Psycopg Team
 
 # Use a versioning scheme as defined in
 # https://www.python.org/dev/peps/pep-0440/
 
-# STOP AND READ! if you change:
-__version__ = "3.1.8.dev1"
-# also change:
-# - `docs/news.rst` to declare this as the current version or an unreleased one
-# - `psycopg_c/psycopg_c/version.py` to the same version.
+try:
+    __version__ = metadata.version("psycopg")
+except metadata.PackageNotFoundError:
+    __version__ = "0.0.0.0"
index fdcb6127f10d29ade211f3833f16d6476119a10f..284d463281f76aae41fb27d30732a807897f6b8f 100644 (file)
@@ -5,6 +5,7 @@ url = https://psycopg.org/psycopg3/
 author = Daniele Varrazzo
 author_email = daniele.varrazzo@gmail.com
 license = GNU Lesser General Public License v3 (LGPLv3)
+version = 3.2.0.dev1
 
 project_urls =
     Homepage = https://psycopg.org/
@@ -42,6 +43,34 @@ install_requires =
     backports.zoneinfo >= 0.2.0; python_version < "3.9"
     typing-extensions >= 4.1
     tzdata; sys_platform == "win32"
+    importlib-metadata >= 1.4; python_version < "3.8"
+
+[options.extras_require]
+c =
+    psycopg-c == 3.2.0.dev1
+binary =
+    psycopg-binary == 3.2.0.dev1
+pool =
+    psycopg-pool
+test =
+    mypy >= 0.990
+    pproxy >= 2.7
+    pytest >= 6.2.5
+    pytest-asyncio >= 0.17
+    pytest-cov >= 3.0
+    pytest-randomly >= 3.10
+dev =
+    black >= 22.3.0
+    dnspython >= 2.1
+    flake8 >= 4.0
+    mypy >= 0.990
+    types-setuptools >= 57.4
+    wheel >= 0.37
+docs =
+    Sphinx >= 5.0
+    furo == 2022.6.21
+    sphinx-autobuild >= 2021.3.14
+    sphinx-autodoc-typehints >= 1.12
 
 [options.package_data]
 psycopg = py.typed
index edb2b3501af9fd15f8afe3995791fa86063fc5a3..2dad83cdcdfd98ce10e72e22ece86e55c72dc4ff 100644 (file)
@@ -5,64 +5,6 @@ PostgreSQL database adapter for Python - pure Python package
 
 # Copyright (C) 2020 The Psycopg Team
 
-import re
-import os
 from setuptools import setup
 
-# Move to the directory of setup.py: executing this file from another location
-# (e.g. from the project root) will fail
-here = os.path.abspath(os.path.dirname(__file__))
-if os.path.abspath(os.getcwd()) != here:
-    os.chdir(here)
-
-with open("psycopg/version.py") as f:
-    data = f.read()
-    m = re.search(r"""(?m)^__version__\s*=\s*['"]([^'"]+)['"]""", data)
-    if not m:
-        raise Exception(f"cannot find version in {f.name}")
-    version = m.group(1)
-
-extras_require = {
-    # Install the C extension module (requires dev tools)
-    "c": [
-        f"psycopg-c == {version}",
-    ],
-    # Install the stand-alone C extension module
-    "binary": [
-        f"psycopg-binary == {version}",
-    ],
-    # Install the connection pool
-    "pool": [
-        "psycopg-pool",
-    ],
-    # Requirements to run the test suite
-    "test": [
-        "mypy >= 0.990",
-        "pproxy >= 2.7",
-        "pytest >= 6.2.5",
-        "pytest-asyncio >= 0.17",
-        "pytest-cov >= 3.0",
-        "pytest-randomly >= 3.10",
-    ],
-    # Requirements needed for development
-    "dev": [
-        "black >= 22.3.0",
-        "dnspython >= 2.1",
-        "flake8 >= 4.0",
-        "mypy >= 0.990",
-        "types-setuptools >= 57.4",
-        "wheel >= 0.37",
-    ],
-    # Requirements needed to build the documentation
-    "docs": [
-        "Sphinx >= 5.0",
-        "furo == 2022.6.21",
-        "sphinx-autobuild >= 2021.3.14",
-        "sphinx-autodoc-typehints >= 1.12",
-    ],
-}
-
-setup(
-    version=version,
-    extras_require=extras_require,
-)
+setup()
index c6da3a1591d8263919b84110cae2cea8e67ba11b..3c8baef37d0fe2a6f98932aa507412fbb75584be 100644 (file)
@@ -28,6 +28,7 @@ with open("psycopg_c/version.py") as f:
     version = m.group(1)
 
 
+
 def get_config(what: str) -> str:
     pg_config = "pg_config"
     try: