What a fucking pain in the ass.
poetry build
If your project name is michina
, then your pyproject.toml
should look like
[tool.poetry]
name = "michina"
version = "0.1.0"
...
And when you run poetry build
, poetry will find a project folder in your root directory with that name.
The project name and the folder name have to be snake case.
In the root folder, you need a README.md
.
Whenever you run a python script, there is a path that the system will use to resolve modules so that they can be imported. You can see it when you run
import sys
print(sys.path)
This sys.path
is a list of directories to look for packages. In order for your file to be imported, the directory that it’s in has to be in this list. We can do this by appending to it the location of the directory. Let’s say we’re writing in folder/test.py
and we want to import some utility functions in utils/test_utils.py
. folder/
and utils/
are siblings of the same directory, so we can’t directly import one from the other. Instead, we append the parent folder ..
to sys.path
. Then, when the Python script runs, the utils
folder will be used to resolve the module import.
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from utils.test_utils import get_usage_stats