Poet was created for Python devs using a specific workflow involving Pyenv, Virtualenv, and Poetry to manage their project dependencies and environments as detailed in my post, PVP- A Workflow for Python Projects. Poet allows you to initialize a Poetry project, create a clearly-labelled virtual environment, and set that environment as the local Python version for your project, all in a single command. Poet also lets you easily determine if Poetry's shell is active and can act as a proxy to run common Poetry commands.
To use Poet you will need to have completed setup as described in PVP Workflow Requirements.
Poet is pretty easy to get setup.
-
Clone this GitHub repository to your machine. (Clone Link)
-
Add the following alias to your
~/.bashrc
or~/.profile
file, replacing{path_to}
with the file path to thepoet.py
file in the cloned repository:Template:
alias poet='python3 ~/{path_to}/poet.py'
Example:
alias poet='python3 ~/Coding/Projects/poet/poet.py'
That's it! You're ready to call on Poet to help you initalize and manage projects with added convenience!
-
poet
orpoet status
- Returns the active status of the Poetry shell -
poet new <project_name> <python_version>
- Initializes a new Poetry project and accompanying virtual environment. Sets the new virtual environment as the local version of Python for the project directory. Also changes the defaultREADME.rst
toREADME.md
-
poet pipfile-install
- This command extracts the names of packages listed as dependencies and dev-dependencies from a Pipenv Pipfile and then uses Poetry to install those packages respectively. This does not maintain the versions listed in the Pipfile, it relies on Poetry to re-resolve the dependencies. -
poet export
- Poetry only supports exporting project dependencies to arequirements.txt
file. This shortened command fills in the remaining arguments so you don't have to search around for the only command string that works with Poetry's exporting abilities.
Poet can also act as a proxy to run these Poetry commands, simply refer to poet
rather than poetry
:
poet add <dependency_name>
- Install and add a dependency to your projectpoet build
- Builds your project into source and wheels that can then be published to PyPIpoet check
- Verifies the structure of yourpyproject.toml
filepoet config
- Manage Poetry's configspoet env <options>
- Various tasks related to managing Poetry's virtual environmentspoet init
- Initialize a new project with Poetrypoet install
- Install project dependencies listed inpyproject.toml
poet lock
- Locks the current versions of your Poetry project dependencies to yourpoetry.lock
filepoet publish
- Publishes a previously built Poetry project to PyPIpoet search <dependency_name>
- Search through packages from PyPI for potential tools for your projectpoet remove <dependency_name>
- Uninstall and remove a project dependencypoet run <command_string>
- Runs the given command string within Poetry's virtual environmentpoet shell
- Activate Poetry's shellpoet show
- Lists all of the current project dependenciespoet update
- Updates your project's dependencies and adds the changes to yourpoetry.lock
file