pypa / pypa/packaging.python.org

Feedback: "Managing Application Dependencies" and "Packaging Python Projects" Tutorials Are Incompatible

Open
#1,562 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component: tutorials type: bug
Dominant language
Python
Stars
1.7k
Forks
1.7k
Avg merge
3d 12h
Merged PRs (30d)
4

Description

Hi! Thank you for writing all of this documentation so clearly, it has been extremely helpful.

"Managing Application Dependencies" suggests Pipenv. "Packaging Python Projects" defaults to hatchling. I assumed that you could follow the two tutorials, in-order, and end up with a working python project, but I had to write a shim to teach hatchling to read a Pipfile.lock. Pipenv doesn't seem to interact with pyproject.toml, and Hatch seems to only read dependencies from there.

I don't know enough about python packaging to suggest a solution. I think you should be able to follow the tutorials as-written and have them be compatible.

`Pipenv.lock` hook

pyproject.toml:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.metadata.hooks.custom]
path = ".ci/dependencies.py"

.ci/dependencies.py:

"""Dynamically update the dependencies metadata based on the Pipfile.lock file."""  # noqa: INP001

import json
from typing import Any

from hatchling.metadata.plugin.interface import MetadataHookInterface


class PipfileLockedDependencies(MetadataHookInterface):
    def update(self, metadata: dict[Any, Any]) -> None:
        with open("Pipfile.lock") as f:
            pipfile_lock_data = json.load(f)

        metadata["dependencies"] = [
            f"{pkg}{data['version']}"
            for pkg, data in pipfile_lock_data["default"].items()
        ]

I feel somewhat bad about suggesting new projects all include this, but at my organization we really want to make locking dependencies the norm. I hope I am missing something obvious.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the Managing Application Dependencies and Packaging Python Projects tutorials, then compare their Pipenv/Pipfile.lock and hatchling/pyproject.toml workflows. Use the reported pyproject.toml and .ci/dependencies.py example to reproduce the incompatibility. Done means the tutorials work together as written, or clearly explain the supported dependency-locking workflow and any incompatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.