Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:poetry [2021/05/04 11:03] alfred [Install from existing requirements] |
wiki2:poetry [2022/06/30 09:10] (actual) |
||
|---|---|---|---|
| Línea 9: | Línea 9: | ||
| </code> | </code> | ||
| + | ℹ️ This will create a project folder in the current path. | ||
| ==== Initializing an existent project ==== | ==== Initializing an existent project ==== | ||
| <code> | <code> | ||
| Línea 29: | Línea 30: | ||
| poetry add package | poetry add package | ||
| </code> | </code> | ||
| + | === From git repository === | ||
| + | |||
| + | <code> | ||
| + | poetry add git+repo_url | ||
| + | </code> | ||
| + | |||
| ==== Execute a command ==== | ==== Execute a command ==== | ||
| Línea 52: | Línea 59: | ||
| <code> | <code> | ||
| cat requirements.txt|xargs poetry add | cat requirements.txt|xargs poetry add | ||
| + | </code> | ||
| + | |||
| + | ===== Use ===== | ||
| + | ==== Versioning ==== | ||
| + | |||
| + | For starting a new project we use: | ||
| + | <code> | ||
| + | poetry new --src <path> | ||
| + | </code> | ||
| + | |||
| + | It generates this structure: | ||
| + | <code> | ||
| + | . | ||
| + | ├── pyproject.toml | ||
| + | ├── README.rst | ||
| + | ├── src | ||
| + | │ └── project_name | ||
| + | │ └── __init__.py | ||
| + | └── tests | ||
| + | ├── __init__.py | ||
| + | └── test_project_name.py | ||
| + | </code> | ||
| + | |||
| + | In that project_name.py we find the version. | ||
| + | |||
| + | === Check version === | ||
| + | <code> | ||
| + | poetry version | ||
| + | </code> | ||
| + | |||
| + | === Set version === | ||
| + | <code> | ||
| + | poetry version 21.12.22 | ||
| + | </code> | ||
| + | |||
| + | === Bump version === | ||
| + | <code> | ||
| + | poetry version patch | ||
| + | </code> | ||
| + | You can set: ''patch'', ''minor'', ''major''... As it says in the next table: | ||
| + | {{ :wiki2:python:poetry-version-table.png?400 |}} | ||
| + | |||
| + | |||
| + | |||
| + | === Workflow === | ||
| + | |||
| + | * From [[https://www.nicholasnadeau.com/post/2020/8/one-version-to-rule-them-all-keeping-your-python-package-version-number-in-sync-with-git-and-poetry/]] | ||
| + | |||
| + | A typical release workflow with poetry looks something like this: | ||
| + | |||
| + | Use poetry to bump your package version: ''poetry version patch'' | ||
| + | <code> | ||
| + | Bumping version from 0.1.0 to 0.1.1 | ||
| + | </code> | ||
| + | Create a tag to define your release in git | ||
| + | <code> | ||
| + | git tag 0.1.1 | ||
| + | git push --tags | ||
| + | </code> | ||
| + | |||
| + | Hope you used the same version number for both steps | ||
| + | |||
| + | To avoid human errors, we can link our poetry version to our git tags. | ||
| + | |||
| + | Update pyproject.toml to have a generic version placeholder | ||
| + | <code> | ||
| + | [tool.poetry] | ||
| + | version = "0.0.0" | ||
| + | </code> | ||
| + | |||
| + | Update your release script to fetch the git version before building the package artifacts | ||
| + | <code> | ||
| + | poetry version $(git describe --tags --abbrev=0) | ||
| + | poetry build | ||
| + | </code> | ||
| + | |||
| + | === Get version by code === | ||
| + | |||
| + | <code> | ||
| + | >>> import pkg_resources | ||
| + | >>> my_version = pkg_resources.get_distribution('my-package-name').version | ||
| + | </code> | ||
| + | |||
| + | ==== Configure script ==== | ||
| + | <code> | ||
| + | [tool.poetry.scripts] | ||
| + | dbcli = 'getfinancing.persistence.cli.dbcli:main' | ||
| </code> | </code> | ||
| Línea 58: | Línea 152: | ||
| <code> | <code> | ||
| poetry show --tree | poetry show --tree | ||
| + | </code> | ||
| + | |||
| + | ==== Add latest package ==== | ||
| + | <code> | ||
| + | poetry add pymysql@latest | ||
| + | </code> | ||
| + | |||
| + | ==== Add from requirements.txt ==== | ||
| + | <code> | ||
| + | cat requirements.txt|xargs poetry add | ||
| + | </code> | ||
| + | |||
| + | ==== Add private repo ==== | ||
| + | |||
| + | This creates the repo ''gf'' accessed with credentials. | ||
| + | |||
| + | <code> | ||
| + | poetry config repositories.gf https://pip.getfinancing.us/simple/ | ||
| + | poetry config http-basic.gf $PYPI_USER $PYPI_PSW | ||
| + | </code> | ||
| + | |||
| + | ==== Use poetry with a concrete Python version ==== | ||
| + | |||
| + | <code> | ||
| + | poetry env use python3.9 | ||
| </code> | </code> | ||