Skip to main content

A poetry python test projet

Project description

Poetry Test

In this proeject, I will be testing the poetry package manager for python.

Currently the project is capable of downloading a random image via running poetry_test or download_img

How to Poetry

--> https://python-poetry.org/docs/#installation

Installing Poetry

Install it via pipx install poetry.

pipx installs packages semi globally, very weird...

Setup a poetry project directory

  1. Make poetry create a .venv dir for you in every project that uses poetry -> poetry config virtualenvs.in-project true (this is a global setting)
  2. Run poetry init in your project dir
  3. Add dependencies with poetry add <module_name> or during the init process
  4. Run poetry install to install your dependencies.
  5. Change the python version of your venv to the same as your poetry project via: -> poetry env use /path/to/python3.11
  6. Activate your new venv via poetry shell and DO NOT source .venv/bin/activate

Local Packaging

  1. Build the package via poetry build
  2. Install the wheel locally: pip install dist/your_project.whl

To actually being able to run your python program, you must include this line in your pyproject.toml:

[tool.poetry.scripts]
your_command_name = "your_project_name.main:main"

Explanation:

  1. your_command_name = the command you will run to start your project. Should be same as project name if you only have one.
  2. your_project_name = the name of the dir in the src/ folder where your project code is
  3. .main = the name of the file you want to execute
  4. :main = the name of the function in the file you want to execute
  5. You can actually have multiple commands here

Publishing your package to pypi

  1. Run: poetry config pypi-token.pypi <YOUR_PYPI_TOKEN>
    1. This command stores the API token directly in Poetry's configuration. I don't know where since I could not read it via poetry config --list.
  2. Build and Publish via: poetry publish --build

Publishing to a custom repo (untested):

  1. Run poetry config pypi-token.<repository_name> <YOUR_REPOSITORY_TOKEN>
  2. in your pyproject.toml add:
[tool.poetry.repositories.<repository_name>]
url = "https://example.com/my-private-repo"
  1. Build and Publish: poetry publish --build -r my-private-repo

Example File Structure

simple poetry example file structure:

poetry-test/
├── pyproject.toml
├── README.md
├── src/
│   └── poetry_test/
│       ├── __init__.py
│       └── main.py
└── tests/
    └── test_example.py

advanced poetry example file structure:

poetry-test/
├── pyproject.toml            # Poetry configuration file
├── README.md                 # (Optional) Project description and instructions
├── src/                      # Main source directory
│   ├── poetry_test/          # Main package directory ( match project name)
│   │   ├── __init__.py       # Initializes the package
│   │   ├── main.py           # Main module or core logic of the package
│   │   ├── utils/            # Utility funcs or helper modules for reusable code
│   │   │   └── helpers.py    # Example helper function file
│   │   ├── config/           # Configuration files or settings for the project
│   │   │   └── settings.py   # Example settings or configuration file
│   │   └── modules/          # Sub-packages, useful for organizing projects
│   │       ├── module_a.py   # Example module for a specific feature or function
│   │       └── module_b.py   # Another example module
│   ├── scripts/              # Standalone scripts
│   │   └── data_processor.py # Example standalone script for data processing
│   └── data/                 # Data files used by the project
│       └── sample_data.csv   # Example data file used by scripts or tests
└── tests/                    # Directory for test files
    └── test_example.py       # Example test file for unit or integration tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poetry_test_project_for_me-0.2.4.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poetry_test_project_for_me-0.2.4-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file poetry_test_project_for_me-0.2.4.tar.gz.

File metadata

  • Download URL: poetry_test_project_for_me-0.2.4.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.10.7-100.fc39.x86_64

File hashes

Hashes for poetry_test_project_for_me-0.2.4.tar.gz
Algorithm Hash digest
SHA256 ca360d3a9805bbf2df2ed91142a061eae7bf8c880c3171d3470ccb668585f16f
MD5 78b4269a63ec35192a321da6c9cc340c
BLAKE2b-256 6a62d5c33c9e714b7a64745129088939bd009449f24f0fa4181f808261a586a7

See more details on using hashes here.

File details

Details for the file poetry_test_project_for_me-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_test_project_for_me-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ba0bf3b4cf0c792496e17a622e5cdeafe1461606f8275c1a8fdc55e4a1f4c64b
MD5 f594a5cd19802e2ff6a8b2f1aed8ef11
BLAKE2b-256 933ce614bfd8b9f8b7a6a360c3dd4969f2305c8669c71ad4311db9a42e462e5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page