Poetry Packages
Let’s play with Packages and Libraries
References
Switch to Root Folder
cd /some/path/you/want
Create a new Package
poetry new mypackage
add some libraries
poetry add requests
… add some code …
cat << 'EOF' > mypackage/__init__.py
print("importing", __name__)
EOF
cat << 'EOF' > mypackage/main.py
print("importing", __name__)
def test1():
print("test1")
def test2(name: str):
print("hello", name)
def test3(name: str, age:int):
print(f"Hello {name} at age {age}")
if __name__ == "__main__":
print("This is a Library or Package. You should import it into your Code and not run it directly ...")
EOF
Build Package
poetry build
List Tree
(mypackage-py3.11) stoege@host:~/git/demo/mypackage> tree
.
├── README.md
├── dist
│ ├── mypackage-0.1.0-py3-none-any.whl
│ └── mypackage-0.1.0.tar.gz
├── mypackage
│ ├── __init__.py
│ └── main.py
├── poetry.lock
├── pyproject.toml
└── tests
└── __init__.py
4 directories, 8 files
you have a package called “mypackage-0.1.0” created. As ’tar.gz and ‘.whl’ File