__init__.py
https://docs.python.org/3/tutorial/modules.html#packages
__init__.py
files are required to make Python treat directories containing the file as packages.
This prevents directories with a common name, such as string, unintentionally hiding valid modules that occur later on the module search path.
In the simplest case, __init__.py
can just be an empty file.
It can also execute initialization code for the package or set the _all_ variable, described later.
__all__.py
https://docs.python.org/3/tutorial/modules.html#importing-from-a-package
The import statement uses the following convention: if a package’s __init__.py
code defines a list named __all__
, it is taken to be the list of module names that should be imported when from package import * is encountered.
It is up to the package author to keep this list up-to-date when a new version of the package is released. Package authors may also decide not to support it, if they don’t see a use for importing * from their package.
For example, the file sound/effects/__init__.py
could contain the following code:
__all__ = ["echo", "surround", "reverse"]
Summary
__all__
is used by both packages and modules to control what is imported when import * is specified.
__all__
is not defined, import * does not import anything.__all__
is not defined, import * imports everything (except—you guessed it—names starting with an underscore).__path__
https://docs.python.org/3/tutorial/modules.html#packages-in-multiple-directories
Packages support one more special attribute, __path__
.
This is initialized to be a list containing the name of the directory holding the package’s __init__.py
before the code in that file is executed.
This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.
While this feature is not often needed, it can be used to extend the set of modules found in a package.
https://python-poetry.org/docs/basic-usage/#project-setup
pip install poetry
poetry new <package-name>
https://python-poetry.org/docs/basic-usage/#initialising-a-pre-existing-project
cd pre-existing-project
poetry init
poetry update
poetry add fastapi
poetry add fastapi --dev
poetry remove <pkg> --dev
Remember to activate the virtual environment before running your code, to ensure that you're using the correct versions of your dependencies. You can do this with the poetry shell command, which will start a new shell session with the virtual environment activated.
poetry shell
https://python-poetry.org/docs/configuration/#using-environment-variables
export POETRY_VIRTUALENVS_PATH=/path/to/virtualenvs/directory
export POETRY_HTTP_BASIC_MY_REPOSITORY_PASSWORD=secret
export POETRY_PYPI_TOKEN_PYPI=my-token
export POETRY_HTTP_BASIC_PYPI_USERNAME=username
export POETRY_HTTP_BASIC_PYPI_PASSWORD=password
# run python script
poetry run python <script.py>
# run tests
poetry run pytest
# activate venv
poetry shell
# path to your current venv
poetry env info --path
poetry env info
# list current config https://python-poetry.org/docs/configuration/#listing-the-current-configuration
poetry config --list
poetry build
Configure pypi creds
https://python-poetry.org/docs/repositories/#configuring-credentials
Prerequisites:
poetry config pypi-token.pypi my-token
# or
export POETRY_PYPI_TOKEN_PYPI=my-token
export POETRY_HTTP_BASIC_PYPI_USERNAME=username
export POETRY_HTTP_BASIC_PYPI_PASSWORD=password
poetry config http-basic.pypi username password
poetry publish
# build and publish
poetry publish --build
# publish with uname / password
poetry publish --build --username <unam> --password <pswrd>
https://python-poetry.org/docs/libraries/#publishing-to-a-private-repository
add repo
poetry config repositories.foo https://foo.bar/simple/
publish repo
poetry publish -r my-repository
https://python-poetry.org/docs/pyproject/#classifiers
classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]
Framework :: FastAPI
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: Freeware
Natural Language :: English
Operating System :: POSIX :: Linux
Programming Language :: Python
Topic :: Education