I have the following project layout:
├── README.md
├── requirements.txt
├── pyproject.toml
├── awesome_package/
├── __init__.py
├── __version__.py
└── main_module.py
└── some_packages
Inside the awesome_package.main_module
there is a function that starts my script (the foo()
function).
I’d like to have a some-script
script that executes my foo
function after installing my library.
This is my pyproject.toml
:
[project]
name = "some-name"
readme = "README.md"
dynamic = ["version"]
dependencies = [
...
]
[project.urls]
...
[project.optional-dependencies]
dev = [
"build"
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project.scripts]
some-script = "awesome_package.main_module:foo"
[tool.hatch.version]
path = "awesome_package/__version__.py"
[tool.hatch.build.targets.wheel]
packages = ["sphinxlint"]
Using this pyproject.toml
I’m able to build the library using:
python -m build
Or for dev purposes
pip install -e '.[dev]'
Everything is working as intended, except for the script which fails to execute. After installation of the wheel, or after the pip install in dev mode, I’m able to run the script some-script
. However, it fails to import the foo function and I get the following error:
Traceback (most recent call last):
File "/Some/path/project_name/venv/bin/some-script", line 7, in <module>
from awesome_package.main_module import foo
ModuleNotFoundError: No module named 'awesome_package'
Any suggestions?