Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate from setup.py/setuptools to pyproject.toml/hatch #1163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ jobs:
python-version: 3.9
cache: 'pip'
cache-dependency-path: requirements/dev.txt
- 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
run: make bootstrap-dev-plugins
run: make bootstrap-dev

##### Run tests, generate bundle
# - name: Run tests
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: requirements/dev.txt
- name: Upgrade pip
run: python -m pip install --upgrade pip setuptools
- name: Install dependencies
run: pip install -r requirements/dev.txt
run: pip install -e .[dev]
- name: Static code analysis
run: make test-lint
- name: Python unit tests
Expand Down
37 changes: 37 additions & 0 deletions .hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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["__package_version__"]
metadata["dependencies"] = load_requirements("base.in")
metadata["optional-dependencies"] = {
"dev": load_requirements("dev.txt"),
"full": load_requirements("plugins.txt"),
}


def load_about() -> dict[str, str]:
about: dict[str, str] = {}
with open(os.path.join(HERE, "tutor", "__about__.py"), "rt", encoding="utf-8") as f:
exec(f.read(), about) # pylint: disable=exec-used
return about


def load_requirements(filename: str) -> list[str]:
requirements = []
with open(
os.path.join(HERE, "requirements", filename), "rt", encoding="utf-8"
) as f:
for line in f:
line = line.strip()
if line != "" and not line.startswith("#"):
requirements.append(line)
return requirements
5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

24 changes: 8 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ docs: ## Build HTML documentation
$(MAKE) -C docs

compile-requirements: ## Compile requirements files
pip-compile requirements/base.in
pip-compile requirements/dev.in
pip-compile requirements/docs.in
pip-compile ${COMPILE_OPTS} requirements/base.in
pip-compile ${COMPILE_OPTS} requirements/dev.in
pip-compile ${COMPILE_OPTS} requirements/docs.in
Comment on lines +12 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for having COMPILE_OPTS? What values can it have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a technique that I also used in edx-platform to de-duplicate the list of *.in files in the Makefile.


upgrade-requirements: ## Upgrade requirements files
pip-compile --upgrade requirements/base.in
pip-compile --upgrade requirements/dev.in
pip-compile --upgrade requirements/docs.in
$(MAKE) compile-requirements COMPILE_OPTS="--upgrade"

build-pythonpackage: build-pythonpackage-tutor ## Build Python packages ready to upload to pypi

build-pythonpackage-tutor: ## Build the "tutor" python package for upload to pypi
python setup.py sdist
build-pythonpackage: ## Build the "tutor" python package for upload to pypi
python -m build --sdist

push-pythonpackage: ## Push python package to pypi
twine upload --skip-existing dist/tutor-$(shell make version).tar.gz
Expand Down Expand Up @@ -82,12 +78,8 @@ coverage-browse-report: coverage-html ## Open the HTML report in the browser
bundle: ## Bundle the tutor package in a single "dist/tutor" executable
pyinstaller tutor.spec

bootstrap-dev: ## Install dev requirements
pip install .
pip install -r requirements/dev.txt

bootstrap-dev-plugins: bootstrap-dev ## Install dev requirements and all supported plugins
Copy link
Contributor

@DawoudSheraz DawoudSheraz Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reasons for merging this? I get this is being made part of full, just thinking if someone was using this in their automation and can break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The make are not supposed to be part of the Tutor API, so I think it's OK to make breaking changes here. The goal of this change is to get rid of an unused command.

pip install -r requirements/plugins.txt
bootstrap-dev: ## Install dev requirements and all supported plugins
pip install .[full,dev]

pull-base-images: # Manually pull base images
docker image pull docker.io/ubuntu:20.04
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Features

.. _readme_intro_end:

.. image:: ./docs/img/launch.webp
.. image:: https://github.com/overhangio/tutor/raw/master/docs/img/launch.webp
:alt: Tutor local launch
:target: https://www.terminalizer.com/view/3a8d55835686

Expand Down
1 change: 1 addition & 0 deletions changelog.d/20241122_145752_regis_pyproject_toml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Improvement] Migrate packaging from setup.py/setuptools to pyproject.toml/hatch. This should not be a breaking change for most users. (by @regisb)
60 changes: 59 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
# https://packaging.python.org/en/latest/tutorials/packaging-projects/
# https://hatch.pypa.io/latest/config/build/

[project]
name = "tutor"
license = {file = "LICENSE.txt"}
authors = [
{name = "Edly", email = "[email protected]"},
]
description = "The Docker-based Open edX distribution designed for peace of mind"
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",
]
# these fields will be set by hatch_build.py
dynamic = ["version", "dependencies", "optional-dependencies"]

[project.scripts]
tutor = "tutor.commands.cli:main"

# https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels
[project.urls]
Homepage = "https://docs.tutor.edly.io/"
Documentation = "https://docs.tutor.edly.io/"
Source = "https://github.com/overhangio/tutor"
Issues = "https://github.com/overhangio/tutor/issues"
Changelog = "https://github.com/overhangio/tutor/blob/master/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 = [
"/tutor",
"requirements/base.in",
"requirements/plugins.txt",
"requirements/dev.txt",
]
exclude = ["tests*"]

[tool.hatch.metadata]
# Allow github dependencies in plugins.txt
allow-direct-references = true
1 change: 0 additions & 1 deletion requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ twine
# Types packages
types-docutils
types-PyYAML
types-setuptools
2 changes: 0 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ types-docutils==0.21.0.20241005
# via -r requirements/dev.in
types-pyyaml==6.0.12.20240917
# via -r requirements/dev.in
types-setuptools==75.5.0.20241122
# via -r requirements/dev.in
typing-extensions==4.12.2
# via
# -r requirements/base.txt
Expand Down
78 changes: 0 additions & 78 deletions setup.py

This file was deleted.

Loading