From 648e52d26421b665a964e69bb5808352490d184b Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 6 Aug 2022 09:53:24 -0700 Subject: [PATCH 1/2] dev: switch to hatch to build hamcrest I've switched our build to use [Hatch](https://hatch.pypa.io) for wheel/sdist creation. This removes `setup.py` and moves us to entirely declarative project metadata. Next steps: * publish using hatch * add CI publication on tags * possibly get our version metadata from VCS --- .gitignore | 5 +++ pyproject.toml | 99 ++++++++++++++++++++++++++++++++++++++++++- setup.py | 111 ------------------------------------------------- tox.ini | 2 +- 4 files changed, 103 insertions(+), 114 deletions(-) delete mode 100755 setup.py diff --git a/.gitignore b/.gitignore index ceb92eab..001bac4f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,10 @@ dist/ *~ .python-version .mypy_cache/ +.pytest_cache/ requirements.txt requirements.in +.envrc +.direnv/ +doc/_build/ +htmlcov/ diff --git a/pyproject.toml b/pyproject.toml index 859a8e26..a2fce537 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,102 @@ [build-system] -requires = ["setuptools>=40.6.0", "wheel"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" +[project] +name = "PyHamcrest" +description = "Hamcrest framework for matcher objects" +readme = "README.rst" +requires-python = ">= 3.6" +license = { file = "LICENSE.txt" } +keywords = [ + "hamcrest", + "matchers", + "pyunit", + "unit", + "test", + "testing", + "unittest", + "unittesting", +] +authors = [ + { name = "Chris Rose", email="offline@offby1.net" }, + { name = "Simon Brunning" }, + { name = "Jon Reid" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "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 :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: Jython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Software Development", + "Topic :: Software Development :: Quality Assurance", + "Topic :: Software Development :: Testing", +] +dynamic = ["version"] + +[project.optional-dependencies] +docs = ["sphinx~=4.0", "alabaster~=0.7"] +tests = [ + "pytest>=5.0", + "pytest-sugar", + "pytest-xdist", + "coverage[toml]", + # No point on Pypy thanks to https://github.com/python/typed_ast/issues/111 + "pytest-mypy-plugins; platform_python_implementation != 'PyPy'", + # Can't use 0.940: https://github.com/python/mypy/issues/12339 + "mypy!=0.940; platform_python_implementation != 'PyPy'", + "types-mock", + "dataclasses; python_version<'3.7'", + "types-dataclasses; python_version<'3.7'", +] +tests-numpy = [ + "PyHamcrest[tests]", + "numpy", +] +dev = [ + "PyHamcrest[docs,tests]", + "towncrier", + "twine", + "pytest-mypy", + "flake8", + "black", + "tox", + "tox-asdf", +] + +[project.urls] +History = "https://github.com/hamcrest/PyHamcrest/blob/main/CHANGELOG.rst" +Source = "https://github.com/hamcrest/PyHamcrest/" +Issues = "https://github.com/hamcrest/PyHamcrest/issues" + +[tool.hatch.version] +path = "src/hamcrest/__init__.py" + +[tool.hatch.build.targets.sdist] +exclude = [ + "/changelog.d/*.rst", + "/release.sh", + "/.github", +] +[tool.hatch.build.targets.wheel] +exclude = [ + "/examples", +] +packages = [ + "src/hamcrest", +] [tool.coverage.run] parallel = true diff --git a/setup.py b/setup.py deleted file mode 100755 index 97057a9c..00000000 --- a/setup.py +++ /dev/null @@ -1,111 +0,0 @@ -import os -import re - -from setuptools import find_packages, setup - -# need to kill off link if we're in docker builds -if os.environ.get("PYTHON_BUILD_DOCKER", None) == "true": - del os.link - -os.chdir(os.path.dirname(os.path.realpath(__file__))) - - -def read(fname): - return open(fname).read() - - -# On Python 3, we can't "from hamcrest import __version__" (get ImportError), -# so we extract the variable assignment and execute it ourselves. -fh = open("src/hamcrest/__init__.py") - -# this will be overridden -__version__ = None -try: - for line in fh: - if re.match("__version__.*", line): - exec(line) - -finally: - if fh: - fh.close() - -assert __version__ is not None - -REQUIREMENTS_DOCS = ["sphinx~=4.0", "alabaster~=0.7"] -TESTS_BASIC = [ - "pytest>=5.0", - "pytest-sugar", - "pytest-xdist", - "coverage[toml]", - # No point on Pypy thanks to https://github.com/python/typed_ast/issues/111 - "pytest-mypy-plugins; platform_python_implementation != 'PyPy'", - # Can't use 0.940: https://github.com/python/mypy/issues/12339 - "mypy!=0.940; platform_python_implementation != 'PyPy'", - "types-mock", - "dataclasses; python_version<'3.7'", - "types-dataclasses; python_version<'3.7'", -] -TESTS_NUMPY = ["numpy"] -DEV_TOOLS = [ - "towncrier", - "twine", - "pytest-mypy", - "flake8", - "black", - "tox", - "tox-pyenv", - "tox-asdf", -] - - -params = dict( - name="PyHamcrest", - version=__version__, # flake8:noqa - author="Chris Rose", - author_email="offline@offby1.net", - description="Hamcrest framework for matcher objects", - license="New BSD", - platforms=["All"], - keywords="hamcrest matchers pyunit unit test testing unittest unittesting", - url="https://github.com/hamcrest/PyHamcrest", - download_url="http://pypi.python.org/packages/source/P/PyHamcrest/PyHamcrest-%s.tar.gz" - % __version__, - packages=find_packages("src"), - package_dir={"": "src"}, - package_data={"hamcrest": ["py.typed"]}, - provides=["hamcrest"], - long_description=read("README.rst"), - long_description_content_type="text/x-rst", - python_requires=">=3.6", - install_requires=[], - extras_require={ - "docs": REQUIREMENTS_DOCS, - "tests": TESTS_BASIC, - "tests-numpy": TESTS_BASIC + TESTS_NUMPY, - "dev": REQUIREMENTS_DOCS + TESTS_BASIC + DEV_TOOLS, - }, - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Natural Language :: English", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3", - "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 :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: Jython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Software Development", - "Topic :: Software Development :: Quality Assurance", - "Topic :: Software Development :: Testing", - ], -) - -all_params = dict(params.items()) -setup(**all_params) diff --git a/tox.ini b/tox.ini index 83f20a4c..b85c4d65 100644 --- a/tox.ini +++ b/tox.ini @@ -100,7 +100,7 @@ commands = coverage run -m pytest {posargs} [testenv:py311] # Python 3.6+ has a number of compile-time warnings on invalid string escapes. # PYTHONWARNINGS=d and --no-compile below make them visible during the Tox run. -basepython = python3.10 +basepython = python3.11 install_command = pip install --no-compile {opts} {packages} setenv = PYTHONWARNINGS=d From 9c81a386f26119554d2135949f34d644e322cab4 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 6 Aug 2022 10:16:52 -0700 Subject: [PATCH 2/2] add hatch-vcs for versioning --- .github/workflows/main.yml | 30 ++++++++++++++++++------------ .gitignore | 2 ++ pyproject.toml | 7 +++++-- src/hamcrest/__init__.py | 3 ++- tox.ini | 7 ++++--- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 182a2d91..0a446399 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,16 +29,18 @@ jobs: - "3.8" - "3.9" - "3.10" - - "3.11.0-beta.4" - - "pypy2" - - "pypy-3.7" + - "3.11.0-beta.5" + - "pypy3.9" exclude: - os: macos-latest python-version: pypy3 steps: - - uses: "actions/checkout@v2" - - uses: "actions/setup-python@v2" + - uses: "actions/checkout@v3" + with: + # We want our tags here + fetch-depth: 0 + - uses: "actions/setup-python@v4" with: python-version: "${{ matrix.python-version }}" - name: "Install dependencies" @@ -63,8 +65,8 @@ jobs: - tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: "3.10" @@ -98,8 +100,11 @@ jobs: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v2" - - uses: "actions/setup-python@v1" + - uses: "actions/checkout@v3" + with: + # We want our tags here + fetch-depth: 0 + - uses: "actions/setup-python@v4" with: python-version: "3.10" @@ -109,6 +114,7 @@ jobs: if: "${{ env.TEST_PYPI_API_TOKEN != '' }}" run: | echo "DO_PUBLISH=yes" >> $GITHUB_ENV + echo "SETUPTOOLS_SCM_PRETEND_VERSION=0.0.1" >> $GITHUB_ENV - name: "Install pep517 and twine" run: "python -m pip install pep517 twine" @@ -136,10 +142,10 @@ jobs: runs-on: "${{ matrix.os }}" steps: - - uses: "actions/checkout@v2" - - uses: "actions/setup-python@v2" + - uses: "actions/checkout@v3" + - uses: "actions/setup-python@v4" with: - python-version: "3.9" + python-version: "3.10" - name: "Install in dev mode" run: "python -m pip install -e .[dev]" - name: "Import package" diff --git a/.gitignore b/.gitignore index 001bac4f..ed9dbb44 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ requirements.in .direnv/ doc/_build/ htmlcov/ +src/hamcrest/_version.py +.tool-versions diff --git a/pyproject.toml b/pyproject.toml index a2fce537..076db3aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] @@ -82,7 +82,10 @@ Source = "https://github.com/hamcrest/PyHamcrest/" Issues = "https://github.com/hamcrest/PyHamcrest/issues" [tool.hatch.version] -path = "src/hamcrest/__init__.py" +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "src/hamcrest/_version.py" [tool.hatch.build.targets.sdist] exclude = [ diff --git a/src/hamcrest/__init__.py b/src/hamcrest/__init__.py index 90573fe3..b40f7011 100644 --- a/src/hamcrest/__init__.py +++ b/src/hamcrest/__init__.py @@ -1,8 +1,9 @@ from hamcrest.core import * from hamcrest.library import * from hamcrest import core, library +from hamcrest._version import version -__version__ = "2.0.4" +__version__ = version __author__ = "Chris Rose" __copyright__ = "Copyright 2020 hamcrest.org" __license__ = "BSD, see License.txt" diff --git a/tox.ini b/tox.ini index b85c4d65..6c0c1fd9 100644 --- a/tox.ini +++ b/tox.ini @@ -115,7 +115,6 @@ commands = coverage combine coverage report - [testenv:lint] basepython = python3.9 skip_install = true @@ -136,9 +135,11 @@ commands = [testenv:manifest] basepython = python3.9 -deps = check-manifest +deps = + check-manifest + setuptools-scm skip_install = true -commands = check-manifest +commands = check-manifest --ignore src/hamcrest/_version.py [testenv:pypi-description]