From 1a9d671f07b7c08882840b765b98fbbf39dc92fe Mon Sep 17 00:00:00 2001 From: Steve Bachmeier Date: Tue, 24 Oct 2023 11:11:44 -0700 Subject: [PATCH] implement setuptools-scm --- .gitignore | 3 +++ docs/source/conf.py | 6 ++---- pyproject.toml | 3 +++ setup.py | 25 ++++++++++++++++++------- src/pseudopeople/__about__.py | 3 --- src/pseudopeople/__init__.py | 2 +- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ffed45ea..b8e81b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,6 @@ notebooks/ # Mac OS stuff .DS_Store + +# Version +src/pseudopeople/_version.py diff --git a/docs/source/conf.py b/docs/source/conf.py index 53ba3a08..4188b052 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -36,10 +36,8 @@ copyright = f'2023, {about["__author__"]}' author = about["__author__"] -# The short X.Y version. -version = about["__version__"] -# The full version, including alpha/beta/rc tags. -release = about["__version__"] +version = pseudopeople.__version__ +release = pseudopeople.__version__ # -- General configuration ------------------------------------------------ diff --git a/pyproject.toml b/pyproject.toml index 547d27bc..edf2eecc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ +[build-system] +requires = ["packaging", "setuptools"] + [tool.black] line_length = 94 diff --git a/setup.py b/setup.py index ec138a00..46a3172f 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,23 @@ import sys from pathlib import Path +from packaging.version import parse from setuptools import find_packages, setup -min_version, max_version = ((3, 9), "3.9"), ((3, 11), "3.11") +min_version, max_version = ("3.9", "3.11") -if not (min_version[0] <= sys.version_info[:2] <= max_version[0]): +min_version = parse(min_version) +max_version = parse(max_version) + +if not ( + min_version <= parse(".".join([str(v) for v in sys.version_info[:2]])) <= max_version +): # Python 3.5 does not support f-strings py_version = ".".join([str(v) for v in sys.version_info[:3]]) error = ( "\n----------------------------------------\n" - "Error: Pseudopeople runs under python {min_version}-{max_version}.\n" - "You are running python {py_version}".format( - min_version=min_version[1], max_version=max_version[1], py_version=py_version - ) + f"Error: Pseudopeople runs under python {min_version.base_version}-{max_version.base_version}.\n" + f"You are running python {py_version}" ) print(error, file=sys.stderr) sys.exit(1) @@ -38,6 +42,8 @@ "tqdm", ] + setup_requires = ["setuptools_scm"] + interactive_requirements = [ "IPython", "ipywidgets", @@ -59,7 +65,6 @@ setup( name=about["__title__"], - version=about["__version__"], description=about["__summary__"], long_description=long_description, license=about["__license__"], @@ -101,4 +106,10 @@ # simulate=pseudopeople.interface.cli:simulate # """, zip_safe=False, + use_scm_version={ + "write_to": "src/pseudopeople/_version.py", + "write_to_template": '__version__ = "{version}"\n', + "tag_regex": r"^(?Pv)?(?P[^\+]+)(?P.*)?$", + }, + setup_requires=setup_requires, ) diff --git a/src/pseudopeople/__about__.py b/src/pseudopeople/__about__.py index 5c03873f..114a8e2b 100644 --- a/src/pseudopeople/__about__.py +++ b/src/pseudopeople/__about__.py @@ -2,7 +2,6 @@ "__title__", "__summary__", "__uri__", - "__version__", "__author__", "__email__", "__license__", @@ -13,8 +12,6 @@ __summary__ = "pseudopeople is package which adds noise to simulated census-scale data using standard scientific Python tools." __uri__ = "https://github.com/ihmeuw/pseudopeople" -__version__ = "0.8.0" - __author__ = "The pseudopeople developers" __email__ = "vivarium.dev@gmail.com" diff --git a/src/pseudopeople/__init__.py b/src/pseudopeople/__init__.py index eb25aad5..2ee3a295 100644 --- a/src/pseudopeople/__init__.py +++ b/src/pseudopeople/__init__.py @@ -6,8 +6,8 @@ __summary__, __title__, __uri__, - __version__, ) +from pseudopeople._version import __version__ from pseudopeople.configuration.entities import NO_NOISE from pseudopeople.configuration.interface import get_config from pseudopeople.interface import (