Fundor 333

Why Do I Disinstall Pipenv and Use Only Poetry?


Why Do I Disinstall Pipenv and Use Only Poetry?

2024-07-10 | dev coding pipenv poetry pyenv pyproject
Reading time 5 minutes | Word count 945 |

Some time ago I wrote about my preference to write Terminal Commands for what I need 1 and thant was not the end of it.

Sometime More than often I need to build the same basic structure for code a Terminal Command and I usualy use a makefile2 for the building of the project or the command specific for this particolar project3.

But I don’t like to repeate the same thing over and over so I develop with git and pyproject a “blank” project as template for my personal python project (there is also a Django Blank Template but I use it less and less).

The main idea of the template is to build something with all I need for python, not only the “booring stuff” but also some cool stuff like automation. I toke some ispiration from other post and project of mine 4 5 for the base of the template.

VEnv

Starting the .venv

If you are coding in Python you must use a virtual env for easy dev and testing so I search for tools.

I love the .venv and all the cleaner workspace which came with it but I choose, at the begginning, the wrong tool for automation of the venv.

In the beginning, I wrote all my project with a pipfile6 in mind which is a good idea for a deploy, not for a package.

If it is a personal project you need to run only on your machine and not relese anyware else it is a great tool because Pipenv is build for deploy only.

But with the new white hairs on my head I change my mind.

If I want to become something bigger than a little dev I find usefull have all the code and the test ready for mass distribuition or having a simpler system to install on a pc or server as a command like a Click program. So I search more and find pyproject and I want to try it.

But PyProject without a tool is horrible, no other words… It’s easy to read but you need to know all the parameters and keywords for editing or updating soo… No, I don’t like it, but maybe there are some tools for edit pyproject in a easy way so I search for something more funtional and easy to use and poetry was suggested to me. 7

Poetry

Poetry is a terminal tool for creating and manipolation of venv and pyproject.toml’s files. With some expirience I add more stuff in the pyproject for the basic.

One the best thing of poetry is the clean way you can edit the settings of the project and build, clean and upgrade your venv.

PS: usually I have the .venv inside the project thanks to this command

poetry config --local virtualenvs.in-project true

Editor config

With poetry we have the venv so now we need to define the style of the code and check if the code is following it.

So I find Editor config , one of the best thing I found on the web.

It is a tool split in two part:

  1. A config file (.editorconfig) with the indication for all the type of the file of the project and how they must be formatted8
  2. A checker (something implemented in an IDE, an IDE Plugin, CI) which format or check the code following the .editorconfig file configuration.

In my case every time I save something the editor (VSCode in my case) will reformatting the code following the .editorconfig settings.

I feel the need for this tool because I worked with some developer who wrote Spaghetti Code every day so or I kill him or I use this tool…

Spaghetti code

Pre-Commit

This is something I use as safety net for myself. Some time I work at night or with time restriction I make error or make something not python-like but spaghetti-like and this is bad, very bad.

For this reason I add pre-commit9 for autofix and check all this minor error. And because I add pre-commit I add more dotfiles for configurations of all the parts of the project and the tools for make more check and fix some of the problems.

If you set pre-commit in the right way for your project, you have an automatic way to make your local machine check your code and valitated the new code without pushing and “waysting” CI cycles 10 and fix the problems before the CI say “Wrong, wrong, wrong, wrong, You are WRONG”.

Worng

Conclusion

This is the consempt for a generic python project but you can do it for all the type of projects and make your personal templating repo of Github and add other stuff, for example a blank template for Kubernates with some type of checker of the config (maybe with pre-commit).

You can also expand the idea adding some dotfile for the IDE, like the config for running the project with multiple setting (dev mod, presentation, online, staging) or the default config four your prefer CI tool.


  1. Why I Stop Making Script and Start to Make Bash Terminal Commands  ↩︎

  2. The team makefile  ↩︎

  3. How to create a self-documenting Makefile  ↩︎

  4. Dotfiles, bot and yaml files  ↩︎

  5. From DevOps to GitOps  ↩︎

  6. Pipenv e come tutto è in uno  ↩︎

  7. Beautifull article about Poetry over others I move from pipenv to poetry in 2023 - Am I right ?  ↩︎

  8. I have a multifile format file done by me but if you need to start you can generate your own here  ↩︎

  9. Using pre-commit hooks to write better code  ↩︎

  10. Sometime you have a slow CI or a “premium” CI so the cycles are a fine resource to keep. ↩︎

Mentions and response

Respond to this post on your own site. If you do, send me a webmention here.

Find out more about webmentions on the IndieWeb.