From 9a7df1aa6085696996a225956de794602cfc57b4 Mon Sep 17 00:00:00 2001 From: Jan Pieter Waagmeester Date: Mon, 23 Dec 2024 12:24:15 +0100 Subject: [PATCH] Use hatch for packaging --- MANIFEST.in | 10 ---------- maintenance.py | 41 ++++++++++++++++++---------------------- pyproject.toml | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 45 -------------------------------------------- 4 files changed, 69 insertions(+), 78 deletions(-) delete mode 100644 MANIFEST.in delete mode 100755 setup.py diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 18171174..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,10 +0,0 @@ -include README.md -include CHANGELOG.md -include LICENSE -exclude docs/pages/CHANGELOG.md -recursive-exclude docs/_build * -recursive-include django_tables2/templates * -recursive-include django_tables2/static * -recursive-include django_tables2/locale * -recursive-include example/app/fixtures * -recursive-include example/templates * diff --git a/maintenance.py b/maintenance.py index 75e7e253..2e8982b8 100755 --- a/maintenance.py +++ b/maintenance.py @@ -1,35 +1,30 @@ #!/usr/bin/env python3 import os -import re import subprocess import sys import time -# get version without importing -with open("django_tables2/__init__.py", "rb") as f: - VERSION = str(re.search('__version__ = "(.+?)"', f.read().decode()).group(1)) - -if sys.argv[-1] == "publish": - try: - import twine # noqa - import wheel # noqa - except ImportError: - print("Required to publish: pip install wheel twine") - os.system("python setup.py clean --all") - os.system("python setup.py sdist bdist_wheel --universal") - os.system( - f"twine upload dist/django-tables2-{VERSION}.tar.gz" - f" dist/django_tables2-{VERSION}-py2.py3-none-any.whl" - ) - print(f"\nreleased [{VERSION}](https://pypi.org/project/django-tables2/{VERSION}/)") +try: + import hatch # noqa +except ImportError: + print("Package `hatch` is required: pip install hatch") sys.exit() -if sys.argv[-1] == "tag": +VERSION = subprocess.check_output(["hatch version"], shell=True).decode() + +if sys.argv[-1] == "bump": + os.system("hatch version patch") + +elif sys.argv[-1] == "publish": + + os.system("hatch publish") + +elif sys.argv[-1] == "tag": + os.system("hatch build") os.system(f"git tag -a v{VERSION} -m 'tagging v{VERSION}'") os.system("git push --tags && git push origin master") - sys.exit() -if sys.argv[-1] == "screenshots": +elif sys.argv[-1] == "screenshots": def screenshot(url, filename="screenshot.png", delay=2): print(f"Making screenshot of url: {url}") @@ -56,5 +51,5 @@ def screenshot(url, filename="screenshot.png", delay=2): for url, dest in images.items(): screenshot(url.format(url="http://localhost:8000"), dest) - - sys.exit() +else: + print(f"Current version: {VERSION}") diff --git a/pyproject.toml b/pyproject.toml index aa4949aa..075bdf2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,53 @@ +[build-system] +build-backend = "hatchling.build" +requires = ["hatchling"] + +[project] +name="django-tables2" +description="Table/data-grid framework for Django" +readme = "README.md" +authors = [ + {name="Bradley Ayers",email="bradley.ayers@gmail.com"}, + {name="Jan Pieter Waagmeester", email="jieter@jieter.nl"}, +] +license = {file = "LICENSE"} +dynamic = ["version"] +url="https://github.com/jieter/django-tables2/" +install_requires=["Django>=4.2"] +extras_require={tablib = ["tablib"]} +python_requires = ">=3.9,<=3.12" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Web Environment", + "Framework :: Django", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", + "Framework :: Django :: 5.1", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Software Development :: Libraries", +] + +[tool.hatch.version] +path = "django_tables2/__init__.py" + +[tool.hatch.build.targets.sdist] +exclude = ["docs"] + +[tool.hatch.build.targets.wheel] +packages = ["django_tables2"] + +[tool.setuptools.dynamic] +version = {attr = "django_tables2.__version__"} + [tool.black] line-length = 100 diff --git a/setup.py b/setup.py deleted file mode 100755 index df19fe08..00000000 --- a/setup.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python3 -import re - -from setuptools import find_packages, setup - -# get version without importing -with open("django_tables2/__init__.py", "rb") as f: - VERSION = str(re.search('__version__ = "(.+?)"', f.read().decode()).group(1)) - -setup( - name="django-tables2", - version=VERSION, - description="Table/data-grid framework for Django", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - author="Bradley Ayers", - author_email="bradley.ayers@gmail.com", - license="BSD-2-Clause", - url="https://github.com/jieter/django-tables2/", - packages=find_packages(exclude=["tests.*", "tests", "example.*", "example", "docs"]), - include_package_data=True, # declarations in MANIFEST.in - install_requires=["Django>=4.2"], - extras_require={"tablib": ["tablib"]}, - python_requires=">=3.9,<=3.12", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Web Environment", - "Framework :: Django", - "Framework :: Django :: 4.2", - "Framework :: Django :: 5.0", - "Framework :: Django :: 5.1", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Software Development :: Libraries", - ], -)