From add6308e870ca5e3afdf271840e5ffa0ab487216 Mon Sep 17 00:00:00 2001 From: Abdul-Muqadim-Arbisoft Date: Mon, 24 Feb 2025 08:12:07 +0500 Subject: [PATCH] feat: migrate from setup.py/setuptools to pyproject.toml/hatch --- .github/workflows/test.yml | 2 - .hatch_build.py | 20 ++++++ MANIFEST.in | 2 - ...1051_abdul.muqadim_migrate_to_pyproject.md | 2 + pyproject.toml | 69 ++++++++++++++++++- setup.py | 63 ----------------- 6 files changed, 90 insertions(+), 68 deletions(-) create mode 100644 .hatch_build.py delete mode 100644 MANIFEST.in create mode 100644 changelog.d/20250224_081051_abdul.muqadim_migrate_to_pyproject.md delete mode 100644 setup.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23ecece..ba2d0be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,8 +18,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Upgrade pip - run: python -m pip install --upgrade pip setuptools - name: Install dependencies run: | pip install .[dev] diff --git a/.hatch_build.py b/.hatch_build.py new file mode 100644 index 0000000..1f0d426 --- /dev/null +++ b/.hatch_build.py @@ -0,0 +1,20 @@ +# 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, "tutorjupyter", "__about__.py"), "rt", encoding="utf-8" + ) as f: + exec(f.read(), about) # pylint: disable=exec-used + return about diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index fedb5a7..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include tutorjupyter/patches * -recursive-include tutorjupyter/templates * diff --git a/changelog.d/20250224_081051_abdul.muqadim_migrate_to_pyproject.md b/changelog.d/20250224_081051_abdul.muqadim_migrate_to_pyproject.md new file mode 100644 index 0000000..5f75f96 --- /dev/null +++ b/changelog.d/20250224_081051_abdul.muqadim_migrate_to_pyproject.md @@ -0,0 +1,2 @@ +- [Improvement] Migrate packaging from setup.py/setuptools to pyproject.toml/hatch. (by @Abdul-Muqadim-Arbisoft) + - For more details view tutor core PR: https://github.com/overhangio/tutor/pull/1163 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d1e6ae6..6c5b57a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,69 @@ +# https://packaging.python.org/en/latest/tutorials/packaging-projects/ +# https://hatch.pypa.io/latest/config/build/ + +[project] +name = "tutor-jupyter" +license = { text = "AGPL-3.0-only" } +authors = [ + { name = "Edly" }, + { email = "hello@edly.io" } +] +maintainers = [ + { name = "Abdu-Muqadim" }, + { email = "abdul.muqadim@arbisoft.com" } +] +description = "Jupyter Notebook 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>=19.0.0,<20.0.0", + "tutor-mfe>=19.0.0,<20.0.0" +] +# these fields will be set by hatch_build.py +dynamic = ["version"] + +[project.optional-dependencies] +dev = [ + "tutor[dev]>=19.0.0,<20.0.0", + "pylint", + "black" +] + +[project.entry-points."tutor.plugin.v1"] +jupyter = "tutorjupyter.plugin" + +# Project URLs +[project.urls] +Homepage = "https://docs.tutor.edly.io/" +Code = "https://github.com/overhangio/tutor-jupyter" +Issues = "https://github.com/overhangio/tutor-jupyter/issues" +Changelog = "https://github.com/overhangio/tutor-jupyter/blob/release/CHANGELOG.md" +Community = "https://discuss.openedx.org/tag/tutor" + +# 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 = ["/tutorjupyter"] +exclude = ["tests*"] + +[tool.hatch.build.targets.wheel] +packages = ["tutorjupyter"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 0c7f520..0000000 --- a/setup.py +++ /dev/null @@ -1,63 +0,0 @@ -import io -import os -from setuptools import setup, find_packages - -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, "tutorjupyter", "__about__.py"), - "rt", - encoding="utf-8", - ) as f: - exec(f.read(), about) # pylint: disable=exec-used - return about - - -ABOUT = load_about() - - -setup( - name="tutor-jupyter", - version=ABOUT["__version__"], - url="https://github.com/overhangio/tutor-jupyter", - project_urls={ - "Code": "https://github.com/overhangio/tutor-jupyter", - "Issue tracker": "https://github.com/overhangio/tutor-jupyter/issues", - }, - license="AGPLv3", - author="Edly", - maintainer="Edly", - maintainer_email="abdul.muqadim@arbisoft.com", - description="Jupyter Notebook plugin for Tutor", - long_description=load_readme(), - long_description_content_type="text/x-rst", - packages=find_packages(exclude=["tests*"]), - include_package_data=True, - python_requires=">=3.9", - install_requires=["tutor>=19.0.0,<20.0.0", "tutor-mfe>=19.0.0,<20.0.0"], - extras_require={"dev": "tutor[dev]>=19.0.0,<20.0.0"}, - entry_points={ - "tutor.plugin.v1": [ - "jupyter = tutorjupyter.plugin" - ] - }, - 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", - ], -)