Poetry 1.2 or Hatch? #56
Replies: 5 comments 7 replies
-
Wow, this is a fantastic write-up! (Hatch creator btw) |
Beta Was this translation helpful? Give feedback.
-
One other thing that could be mentioned: Poetry tries to access the keyring, even when that it not actually necessary: python-poetry/poetry#1917 |
Beta Was this translation helpful? Give feedback.
-
Added some info about the breaking change in |
Beta Was this translation helpful? Give feedback.
-
Thank for this repo, i feel like i finally understand hatch bc of it!!, honestly this pyproject.toml is way better than the one generated by hatch new, any way, since you're using hatch for dependencies and builds, just wondering how you add dependencies, bc rn i'm just copying and pasting them to the dependencies array, which feels weird |
Beta Was this translation helpful? Give feedback.
-
I was able to migrate the project from pre-commit to Hatch scripts today (#89). It was easy to do and works great. |
Beta Was this translation helpful? Give feedback.
-
Background
Poetry has been helpful by putting dependency management and packaging together in one tool using
pyproject.toml
. However, Poetry has also created many problems for maintainers, and many of these problems have been introduced in patch releases.Background from this project:
pipx
instead of their install script)Poetry 1.2 introduces an enormous number of changes for a minor version, and upgrading from 1.1 to 1.2 may involve as much work as switching to a different tool. Hatch is one such alternative tool. Here, we can discuss the pros and cons of Poetry, Hatch, and other related tools.
Poetry
Poetry for project metadata
pyproject.toml
.pyproject.toml
.Poetry for dependency management
^
).poetry
andpoetry-plugin-export
.setuptools
differently than Poetry 1.1. This is one reason why updating to Poetry 1.2 may be a breaking change for many projects.Poetry for packaging
poetry publish --build
command has been a convenient way to build and publish in one step.extras
metadata (validate extras against dependencies and in schema python-poetry/poetry-core#542), which broke package builds from source for many projects including isort (Build from source (e.g. via pre-commit) is broken by new poetry version PyCQA/isort#2077).Poetry for environments
virtualenvs.create false
installs packages into the wrong place on Ubuntu python-poetry/poetry#6459get-poetry.py
->install-poetry.py
)install-poetry.py
->install.python-poetry.org
)pipx
instead of their install script)Hatch as an alternative to Poetry
General points
Hatch for project metadata
Hatch does align with the Python standard for declaring project metadata in
pyproject.toml
. Hatch does not have Poetry in its migration FAQ, but a Poetrypyproject.toml
could be refactored as described in the Hatch docs on project metadata:[tool.poetry]
section moves to the[project]
section.pyproject.toml
optional, or at least validate it *after* the plugins are run python-poetry/poetry#4299). The version number moves to__init__.py
or__about__.py
, and is then directly accessible from Python code.Hatch for dependency management
Hatch dependencies can be installed with pip, and can therefore benefit from the pip dependency resolver and pip keyring support.
Refactoring dependencies in
pyproject.toml
is fairly straightforward, as described in the Hatch docs on project metadata:[tool.poetry.dependencies]
move to thedependencies
list in the[project]
section[tool.poetry.dev-dependencies]
move to a group in[project.optional-dependencies]
(these groups are called "extras" according to Python packaging standards)[tool.poetry.extras]
would also move to[project.optional-dependencies]
[tool.poetry.urls]
would move to[project.urls]
Hatch currently has some limitations around managing dependencies:
pyproject.toml
file manually, which is maybe a minor drawback, but not a big dealHatch for packaging
The
[build-system]
section ofpyproject.toml
could be easily refactored as described in the docs on build configuration:requires = ["poetry-core>=1.0.0"]
->requires = ["hatchling"]
build-backend = "poetry.core.masonry.api"
->build-backend = "hatchling.build"
Hatch for environments
poetry run
->hatch run
)poetry config virtualenvs.in-project true
setting (inproject_directory/.venv
)pyproject.toml
in a section like[tool.hatch.envs.<ENV_NAME>]
[tool.hatch.envs.<ENV_NAME>]
section, settingpath = ".venv"
will create an in-project virtualenv in the same location as a Poetry in-project virtualenv. A similar effect can be achieved by setting the environment variableHATCH_ENV_TYPE_VIRTUAL_PATH=.venv
.HATCH_ENV
environment variable or specifying the environment name in commands, likehatch env create ci
orhatch run ci:coverage run
.Beta Was this translation helpful? Give feedback.
All reactions