Intro

What a fucking pain in the ass.

What you need to know

[Easy] Poetry needs your PyPI credentials via an API token so that you can publish to PyPI.

[Pain] Poetry needs your root directory structured in a certain way so that you can run 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.

References

[Pain] To import functions from files in other directories into your file, you need to modify the path for module resolution within your script.

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

sys.path.append(path.join(path.dirname(__file__), ".."))
from utils.test_utils import get_usage_stats

[Pain] From your root directory, when subdirectories reference imports, they have to use the absolute import path in dot syntax.