From 8b80418ecb2d30fbf64faf4faafb367823f51c41 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 3 Aug 2025 13:51:43 +0200 Subject: [PATCH 1/2] Update build process to current standards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * setup.py → pyproject.toml * use setuptools_scm to retrieve version from Git tags at build time * use importlib.metadata.version to retrieve version at run time * setuptools_scm pulls all files under version control, adapt MANIFEST.in * update years of copyright under doc --- .github/workflows/run-tests.yaml | 2 +- .gitignore | 1 - .readthedocs.yaml | 2 +- .rtd-require | 2 + MANIFEST.in | 15 ++- Makefile | 12 +-- doc/src/conf.py | 10 +- pyproject.toml | 34 +++++++ setup.py | 169 ------------------------------- src/pytest_dependency.py | 2 - 10 files changed, 55 insertions(+), 194 deletions(-) create mode 100644 pyproject.toml delete mode 100755 setup.py diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 253e83f..ec65390 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -36,4 +36,4 @@ jobs: pip install -r .github/requirements.txt - name: Test with pytest run: | - python setup.py test + python -m pytest diff --git a/.gitignore b/.gitignore index 3ccd468..c907287 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ __pycache__/ /.env /MANIFEST -/_meta.py /build/ /dist/ diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 726b61a..8fe6b46 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,7 +11,7 @@ build: post_checkout: - git fetch --unshallow post_install: - - python setup.py build + - python -m pip install -e . sphinx: configuration: doc/src/conf.py diff --git a/.rtd-require b/.rtd-require index 1742889..ade744c 100644 --- a/.rtd-require +++ b/.rtd-require @@ -1,5 +1,7 @@ git-props pytest >=3.7.0 setuptools +build +pip sphinx-copybutton sphinx_rtd_theme diff --git a/MANIFEST.in b/MANIFEST.in index def022d..cc5b23e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,8 @@ -include CHANGES.rst -include LICENSE.txt -include MANIFEST.in -include README.rst -include _meta.py +recursive-exclude .github * +exclude .gitignore +exclude .readthedocs.yaml +exclude .rtd-require +recursive-exclude doc * include doc/examples/*.py -include tests/conftest.py -include tests/pytest.ini -include tests/test_*.py +exclude Makefile +exclude python-pytest-dependency.spec diff --git a/Makefile b/Makefile index 74a5ba7..c098d59 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,13 @@ BUILDLIB = $(CURDIR)/build/lib build: - $(PYTHON) setup.py build + $(PYTHON) -m build test: - $(PYTHON) setup.py test + $(PYTHON) -m pytest sdist: - $(PYTHON) setup.py sdist + $(PYTHON) -m build --sdist doc-html: build $(MAKE) -C doc html PYTHONPATH=$(BUILDLIB) @@ -19,13 +19,9 @@ clean: rm -rf __pycache__ distclean: clean - rm -f MANIFEST _meta.py rm -rf dist rm -rf tests/.pytest_cache $(MAKE) -C doc distclean -meta: - $(PYTHON) setup.py meta - -.PHONY: build test sdist doc-html clean distclean meta +.PHONY: build test sdist doc-html clean distclean diff --git a/doc/src/conf.py b/doc/src/conf.py index 5d517fc..78a4861 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- -# # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/master/config +from importlib.metadata import version, PackageNotFoundError from pathlib import Path import sys @@ -19,11 +18,14 @@ # -- Project information ----------------------------------------------------- project = 'pytest-dependency' -copyright = '2016–2023, Rolf Krahl' +copyright = '2016–2025, Rolf Krahl' author = 'Rolf Krahl' # The full version, including alpha/beta/rc tags -release = pytest_dependency.__version__ +try: + release = version(project) +except PackageNotFoundError: + release = '0.0.0' # The short X.Y version version = ".".join(release.split(".")[0:2]) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ee4d72c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["setuptools>=64", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "pytest-dependency" +description = "Manage dependencies of tests" +authors = [{name = "Rolf Krahl", email = "rolf@rotkraut.de"}] +readme = "README.rst" +requires-python = ">=3.4" +dependencies = [ + "pytest", +] +dynamic = ["version"] +classifiers = [ + "Development Status :: 4 - Beta", + "Framework :: Pytest", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Software Development :: Testing", +] + +[project.urls] +Homepage = "https://github.com/RKrahl/pytest-dependency" +Documentation = "https://pytest-dependency.readthedocs.io" +Source = "https://github.com/RKrahl/pytest-dependency.git" +Download = "https://github.com/RKrahl/pytest-dependency/releases/" +Changelog = "https://pytest-dependency.readthedocs.io/en/latest/changelog.html" + +[project.entry-points.pytest11] +dependency = "pytest_dependency" diff --git a/setup.py b/setup.py deleted file mode 100755 index db3a8db..0000000 --- a/setup.py +++ /dev/null @@ -1,169 +0,0 @@ -"""pytest-dependency - Manage dependencies of tests - -This pytest plugin manages dependencies of tests. It allows to mark -some tests as dependent from other tests. These tests will then be -skipped if any of the dependencies did fail or has been skipped. -""" - -import setuptools -from setuptools import setup -import setuptools.command.build_py -import distutils.command.sdist -import distutils.file_util -from distutils import log -from glob import glob -import os -from pathlib import Path -from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE -import string -try: - import distutils_pytest - cmdclass = distutils_pytest.cmdclass -except (ImportError, AttributeError): - cmdclass = dict() -try: - import gitprops - release = str(gitprops.get_last_release()) - version = str(gitprops.get_version()) -except (ImportError, LookupError): - try: - from _meta import release, version - except ImportError: - log.warn("warning: cannot determine version number") - release = version = "UNKNOWN" - -docstring = __doc__ - -class copy_file_mixin: - """Distutils copy_file() mixin. - - Inject a custom version version of the copy_file() method that - does some substitutions on the fly into distutils command class - hierarchy. - """ - Subst_srcs = {"src/pytest_dependency.py"} - Subst = {'DOC': docstring, 'VERSION': version} - def copy_file(self, infile, outfile, - preserve_mode=1, preserve_times=1, link=None, level=1): - if infile in self.Subst_srcs: - infile = Path(infile) - outfile = Path(outfile) - if outfile.name == infile.name: - log.info("copying (with substitutions) %s -> %s", - infile, outfile.parent) - else: - log.info("copying (with substitutions) %s -> %s", - infile, outfile) - if not self.dry_run: - st = infile.stat() - try: - outfile.unlink() - except FileNotFoundError: - pass - with infile.open("rt") as sf, outfile.open("wt") as df: - df.write(string.Template(sf.read()).substitute(self.Subst)) - if preserve_times: - os.utime(str(outfile), (st[ST_ATIME], st[ST_MTIME])) - if preserve_mode: - outfile.chmod(S_IMODE(st[ST_MODE])) - return (str(outfile), 1) - else: - return distutils.file_util.copy_file(infile, outfile, - preserve_mode, preserve_times, - not self.force, link, - dry_run=self.dry_run) - -class meta(setuptools.Command): - description = "generate meta files" - user_options = [] - meta_template = ''' -release = "%(release)s" -version = "%(version)s" -''' - def initialize_options(self): - pass - def finalize_options(self): - pass - def run(self): - version = self.distribution.get_version() - log.info("version: %s", version) - values = { - 'release': release, - 'version': version, - } - with Path("_meta.py").open("wt") as f: - print(self.meta_template % values, file=f) - -# Note: Do not use setuptools for making the source distribution, -# rather use the good old distutils instead. -# Rationale: https://rhodesmill.org/brandon/2009/eby-magic/ -class sdist(copy_file_mixin, distutils.command.sdist.sdist): - def run(self): - self.run_command('meta') - super().run() - subst = { - "version": self.distribution.get_version(), - "url": self.distribution.get_url(), - "description": docstring.split("\n")[0], - "long_description": docstring.split("\n", maxsplit=2)[2].strip(), - } - for spec in glob("*.spec"): - with Path(spec).open('rt') as inf: - with Path(self.dist_dir, spec).open('wt') as outf: - outf.write(string.Template(inf.read()).substitute(subst)) - -class build_py(copy_file_mixin, setuptools.command.build_py.build_py): - def run(self): - self.run_command('meta') - super().run() - - -with Path("README.rst").open("rt", encoding="utf8") as f: - readme = f.read() - -setup( - name = "pytest-dependency", - version = version, - description = "Manage dependencies of tests", - long_description = readme, - long_description_content_type = "text/x-rst", - url = "https://github.com/RKrahl/pytest-dependency", - author = "Rolf Krahl", - author_email = "rolf@rotkraut.de", - license = "Apache-2.0", - classifiers = [ - "Development Status :: 4 - Beta", - "Framework :: Pytest", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Topic :: Software Development :: Testing", - ], - project_urls = dict( - Documentation="https://pytest-dependency.readthedocs.io/", - Source="https://github.com/RKrahl/pytest-dependency", - Download=("https://github.com/RKrahl/pytest-dependency/releases/%s/" - % release), - Changes="https://pytest-dependency.readthedocs.io/en/latest/changelog.html", - ), - package_dir = {"": "src"}, - python_requires = ">=3.4", - py_modules = ["pytest_dependency"], - install_requires = ["setuptools", "pytest >= 3.7.0"], - entry_points = { - "pytest11": [ - "dependency = pytest_dependency", - ], - }, - cmdclass = dict(cmdclass, build_py=build_py, sdist=sdist, meta=meta), -) diff --git a/src/pytest_dependency.py b/src/pytest_dependency.py index 9aea0c7..fc6eef5 100644 --- a/src/pytest_dependency.py +++ b/src/pytest_dependency.py @@ -1,7 +1,5 @@ """$DOC""" -__version__ = "$VERSION" - import logging import pytest From dc42fbe205a65ec1fdf28e0e92a751149195fefe Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:52:03 +0200 Subject: [PATCH 2/2] pytest>=3.7.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ee4d72c..2ce61f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = [{name = "Rolf Krahl", email = "rolf@rotkraut.de"}] readme = "README.rst" requires-python = ">=3.4" dependencies = [ - "pytest", + "pytest>=3.7.0", ] dynamic = ["version"] classifiers = [