diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1dec62..bb7ed34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,11 +27,8 @@ jobs: with: python-version: 3.9 cache: "pip" - - name: Upgrade pip and setuptools - # https://pypi.org/project/pip/ - # https://pypi.org/project/setuptools/ - # https://pypi.org/project/wheel/ - run: python -m pip install --upgrade pip setuptools==65.6.3 wheel + - name: Install Hatch + uses: pypa/hatch@install - name: Print info about the current python installation run: make ci-info - name: Install requirements diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31fcb21..92d1648 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.12'] + python-version: ['3.9', '3.12'] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | if [ "${{ matrix.python-version }}" = "3.7" ]; then - pip install "tutor==15.0.0" pylint black mypy types-setuptools + pip install "tutor==15.0.0" pylint black mypy else pip install -U tutor fi diff --git a/.hatch_build.py b/.hatch_build.py new file mode 100644 index 0000000..56ccde8 --- /dev/null +++ b/.hatch_build.py @@ -0,0 +1,22 @@ +# https://hatch.pypa.io/latest/how-to/config/dynamic-metadata/ +import os +import typing as t + +from hatchling.metadata.plugin.interface import MetadataHookInterface + +HERE = os.path.dirname(__file__) + + +class MetaDataHook(MetadataHookInterface): + def update(self, metadata: dict[str, t.Any]) -> None: + about = load_about() + metadata["version"] = about["__version__"] + + +def load_about() -> dict[str, str]: + about: dict[str, str] = {} + with open( + os.path.join(HERE, "tutorwordpress", "__about__.py"), "rt", encoding="utf-8" + ) as f: + exec(f.read(), about) # pylint: disable=exec-used + return about \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 3ebf0f2..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include tutorwordpress/patches * -recursive-include tutorwordpress/templates * diff --git a/Makefile b/Makefile index 7948267..327a933 100644 --- a/Makefile +++ b/Makefile @@ -34,13 +34,12 @@ ci-info: ## Print info about environment bootstrap-dev: ## Install dev requirements pip install .[dev] -build-pythonpackage: ## Build Python package ready to upload to pypi - python setup.py sdist - for f in dist/tutor_contrib_wordpress-*.tar.gz; do mv "$$f" "dist/tutor-contrib-wordpress-$(shell make version).tar.gz"; done +build-pythonpackage: ## Build the python package for upload to pypi + find . -type d -name "dist" -exec rm -rf {} + + hatch build push-pythonpackage: ## Push python package to pypi - twine check dist/tutor-contrib-wordpress-$(shell make version).tar.gz - twine upload --skip-existing dist/tutor-contrib-wordpress-$(shell make version).tar.gz + hatch publish version: ## Print the current tutor version @python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutorwordpress", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])' diff --git a/changelog.d/20250225_110231_codewithemad_migrate_to_pyproject.md b/changelog.d/20250225_110231_codewithemad_migrate_to_pyproject.md new file mode 100644 index 0000000..7223b7a --- /dev/null +++ b/changelog.d/20250225_110231_codewithemad_migrate_to_pyproject.md @@ -0,0 +1,2 @@ +- [Improvement] Migrate packaging from setup.py/setuptools to pyproject.toml/hatch. (by @CodeWithEmad) +- [Improvement] Support for tutor v19 added. (by @CodeWithEmad) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d1e6ae6..e00353a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,62 @@ +# https://packaging.python.org/en/latest/tutorials/packaging-projects/ +# https://hatch.pypa.io/latest/config/build/ + +[project] +name = "tutor-contrib-wordpress" +license = { text = "AGPL-3.0-only" } +authors = [ + {name = "Emad Rad"}, {email = "codewithemad@gmail.com"}, +] +description = "wordpress plugin for Tutor" +readme = {file = "README.rst", content-type = "text/x-rst"} +requires-python = ">= 3.9" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +dependencies = [ + "tutor>=15.0.0,<20.0.0", + "importlib_resources" +] +# these fields will be set by hatch_build.py +dynamic = ["version"] + +[project.optional-dependencies] +dev = [ + "tutor[dev]>=15.0.0,<20.0.0", + "pylint", + "black" +] + +[project.entry-points."tutor.plugin.v1"] +wordpress = "tutorwordpress.plugin" + +# https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels +[project.urls] +Code = "https://github.com/CodeWithEmad/tutor-contrib-wordpress" +Issues = "https://github.com/CodeWithEmad/tutor-contrib-wordpress/issues" +Changelog = "https://github.com/CodeWithEmad/tutor-contrib-wordpress/blob/master/CHANGELOG.md" + +# hatch-specific configuration +[tool.hatch.metadata.hooks.custom] +path = ".hatch_build.py" + [build-system] -requires = ["setuptools", "wheel"] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.sdist] +# Disable strict naming, otherwise twine is not able to detect name/version +strict-naming = false +include = [ "/tutorwordpress"] +exclude = ["tests*"] + +[tool.hatch.build.targets.wheel] +packages = ["tutorwordpress"] \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index c3e2feb..0000000 --- a/setup.py +++ /dev/null @@ -1,68 +0,0 @@ -import io -import os - -from setuptools import find_packages, setup - -HERE = os.path.abspath(os.path.dirname(__file__)) - - -def load_readme(): - with io.open(os.path.join(HERE, "README.rst"), "rt", encoding="utf8") as f: - return f.read() - - -def load_about(): - about = {} - with io.open( - os.path.join(HERE, "tutorwordpress", "__about__.py"), - "rt", - encoding="utf-8", - ) as f: - exec(f.read(), about) # pylint: disable=exec-used - return about - - -ABOUT = load_about() - - -setup( - name="tutor-contrib-wordpress", - version=ABOUT["__version__"], - url="https://github.com/codewithemad/tutor-contrib-wordpress", - project_urls={ - "Code": "https://github.com/codewithemad/tutor-contrib-wordpress", - "Issue tracker": "https://github.com/codewithemad/tutor-contrib-wordpress/issues", - }, - license="AGPLv3", - author="Emad Rad", - author_email="codewithemad@gmail.com", - description="Tutor plugin for WordPress.", - long_description=load_readme(), - long_description_content_type="text/x-rst", - packages=find_packages(exclude=["tests*"]), - include_package_data=True, - python_requires=">=3.7", - install_requires=[ - "tutor>=15.0.0,<19.0.0", - "importlib_resources", # for older versions of tutor - ], - extras_require={ - "dev": [ - "tutor[dev]>=15.0.0,<19.0.0", - ] - }, - entry_points={"tutor.plugin.v1": ["wordpress = tutorwordpress.plugin"]}, - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU Affero General Public License v3", - "Operating System :: OS Independent", - "Programming Language :: Python", - "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", - ], -)