pypa / pypa/setuptools

[FR] `package-dir`-aware `find:` directive

Open
#5,145 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

setuptools version

setuptools>=80.0

Python version

3.13

OS

windows

Additional environment information

No response

Description

[project]

# 需要更改发布到pypi的包名时改这里
name = "pyproject-tmpl"
dynamic = ["version"]
description = "template python project with necessary configurations"
readme = "README.md"
requires-python = ">=3.10"

dependencies = [
    "alembic>=1.17.2",
    "ipa-python-kit>=0.0.7",
    "sqlmodel>=0.0.31",
    "typer>=0.20.0",
    "typing-extensions>=4.15.0",
]

[project.optional-dependencies]
system = [
    "psutil>=7.2.1",
]

all =[
    "pyproject-tmpl[system]"
]
# 使用uv_build时
# [build-system]
# requires = ["uv_build>=0.7.4,<0.8.0"]
# build-backend = "uv_build"

# [tool.uv.build-backend]
# module-root = "src"
# module-name = "mylib"

[build-system]
requires = ["setuptools>=80.0", "setuptools-scm>=9"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_file = "src/sdk/_version.py"
version_scheme = "guess-next-dev"
# version_scheme = "only-version"
# local_scheme = "node-and-date"
local_scheme = "no-local-version"

[tool.setuptools.package-dir]
"" = "src"
# 路径映射,便于用户通过有辨识度的方式导入模块而不是使用sdk或重命名
mylib = "src/sdk"

# [tool.setuptools.packages]
# find = {where = ["src"], include = ["sdk"]}

[tool.setuptools]
packages = ["mylib"]

[tool.uv]
index = [
    { "name" = "tencent", "url" = "https://mirrors.cloud.tencent.com/pypi/simple/" },
    { "name" = "pypi", "url" = "https://pypi.org/simple/" }
]

[dependency-groups]
dev = [
    "build>=1.3.0",
    "twine>=6.2.0",
    "black==25.1.0",
    "commitlint==1.3.0",
    "darker==2.1.1",
    "pre-commit==4.2.0",
    "pytest>=9.0.2",
    "ruff==0.13.1",
    "setuptools-scm>=9.2.2",
    "pyinstaller>=6.17.0",
]

uv run pip install -e .

import sys

print(sys.path)

from mylib import add as mylib_add

def new_add(a: int, b: int) -> int:
    c = mylib_add(a, b)
    print(f"new_add({a}, {b}) = {c}")
    return c

new_add(1,3)


Expected behavior

works

How to Reproduce
  1. pyproject.tpml
  2. uv pip install -e .
  3. uv run main.py
Output
Traceback (most recent call last):
  File "E:\src\python\pyproject-tmpl\main.py", line 6, in <module>
    from mylib import add as mylib_add
ModuleNotFoundError: No module named 'mylib'

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

Start with the pyproject.toml configuration and reproduce the failure using uv pip install -e . followed by uv run main.py. Trace how Setuptools handles the package-dir and find: configuration. Done means the reported mylib import works with the package layout shown, while the relevant package-discovery behavior remains covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.