pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
6.1k stars 309 forks source link

hatch/hatchify is creating blank .venv/lib/python3.12/site-packages/*.pth file #1745

Open bessx opened 1 month ago

bessx commented 1 month ago

Ultimately, hatch is not properly adding the installed package to the the PATH. This is incredibly annoying and means that I can only run the program from the my-package/src folder, otherwise I constantly get a Module not found error.

(.venv) users-MacBook-Pro:my-packaye user$ cd src
(.venv) users-MacBook-Pro:src user$ test
Hello, world!
(.venv) users-MacBook-Pro:src user$ cd ..
(.venv) users-MacBook-Pro:my-package user$ test
Traceback (most recent call last):
  File "/Users/user/Documents/dev/my-package/.venv/bin/test", line 5, in <module>
    from my_package.main import main
ModuleNotFoundError: No module named 'my_package'
cat .venv/lib/python3.12/site-packages/_my_package.pth 

(it's blank)

This is happening with every new module I create (using hatch new).

the only thing I add to pyproject.toml is:

[project.scripts]
test = "my_package.main:main"

[tool.hatch.build.targets.wheel]
packages = ["src/my_package"]
jwatte commented 1 day ago

I'm seeing what I think is this problem, too. I use hatchling as build tool for uv. I have two different packages "backoff" and "pyproto" and they both list hatchling as their build system in their pyproject.toml files, and they are both listed in the root pyproject.toml file. However, when called by "uv sync," the "backoff" site-packages pth file contains the correct path, but the "pyproto" site-packages pth file is created but empty. There are no errors printed, even when running "uv sync -v"