Skip to content

[FR] package-dir-aware find: directive #5145

@xdewx

Description

@xdewx

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'

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions