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

Use Hatch for build backend and project management #71

Merged
merged 7 commits into from
Nov 21, 2023

Conversation

pederhan
Copy link
Member

@pederhan pederhan commented Nov 20, 2023

This PR migrates the project management and build backend to Hatch, which is a standards-compliant PyPA-backed project. As part of this, all dependency and metadata for the project has been migrated to the new pyproject.toml format (PEP 518, PEP 621).

Project version is now managed in the new zabbix_auto_config/__about__.py file, which can be bumped with hatch version. In the future we can also extend this functionality with the hatch-regex-commit plugin to create git tags and commits whenever the version is bumped.

Why Hatch over setuptools?

Hatch makes virtual environment and dependency management easy. A single command (hatch shell) creates a virtual environment, installs all dependencies (both application and development dependencies), and then enters the virtual environment.

Environments

Hatch provides the ability to add multiple development environments à la tox and nox without adding a bunch of boilerplate. Furthermore, different environments can be defined for different purposes, such as testing and documentation.

Scripts can be configured to run against a test matrix of different python versions and feature flags with just a few lines of configuration.

Scripts

Hatch provides the ability to define scripts that can be run against specific environments. Given the following configuration that defines an environment for building and serving documentation:

[tool.hatch.envs.docs]
dependencies = [
  "mkdocs>=1.5.2"
]

We can define Hatch scripts that lets us build and serve the documentation:

[tool.hatch.envs.docs.scripts]
build = "mkdocs build --clean --strict"
serve = "mkdocs serve --dev-addr localhost:8000"

Which we can run like this:

hatch run build
hatch run serve

Plugins

Hatch provides a plugin interface, which allows third party authors to extend the functionality of Hatch. The Hatch documentation lists some of these in the following categories:

Why not Poetry?

Poetry has repeatedly shown a lack of respect for PEP standards, and generally invent their own solutions when it comes to dependencies, environments, etc. Hatch handles separate environments and dependencies in a standards-compliant way, and enables the resulting pyproject.toml file to be parsed by any PEP 621-compliant metadata parser.

Also watch: why I will never use python-poetry

@pederhan pederhan merged commit af4bd03 into unioslo:master Nov 21, 2023
3 checks passed
@pederhan pederhan deleted the hatch-project-management branch November 21, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant