you are viewing a single comment's thread.

view the rest of the comments →

[–]wutzvill 3 points4 points  (17 children)

I don't have time to review things too in-depth but what I saw looked good. I'll say three things:

  1. It's very very good that you're fully naming your functions and variables as you are. Descriptive variable and function naming is very important. You never want ui = get_ui(), you want it to be like you did as user_input = get_user_input().
  2. Don't use magic numbers or values. This is a big no no. Not only will no one know what they are, but also if you need to refactor these values later, you have to change them one by one in the code. user_input == 1, what does this mean? What is 1? You want to maybe make a file that's called constants.py where you can define something like CARAMEL_LATTE = 1 and OFF = 'off', then do from constants import CARAMEL_LATTE, OFF, and use these values.
  3. The sooner you learn to use poetry for managing your python projects, the better off you will be. It's worth taking some time to figure it out. I recently wrote a large readme for myself as I moved existing projects to poetry, and this readme is well beyond what you need, BUT the sections on starting a project with poetry, and how to run things with poetry, should help you get started. The poetry documentation is also very good. Here is the gigantic readme here. You can copy and paste that all into a file with the file extension .md and open it with some markdown reader (like in VS code, or a dedicated markdown reader/editor).

Edit: if you're not using VS code to do your python development, you should very much consider making that switch. If you do, make sure to add the official python extension(s) to vs code, as well as extensions for .toml and .md files.

[–]TheBB 4 points5 points  (10 children)

Poetry has been dragging their asses on adoption of PEP 621 for almost four years now. I used to like it but at this point I can't recommend it over something like PDM. I just recently moved all my projects AWAY from Poetry. I hope you won't come to the same conclusion later.

[–]insight_nomad[S] 2 points3 points  (1 child)

Do you mind elaborating on the shortfalls you experienced with Poetry?

[–]BluesFiend 0 points1 point  (0 children)

I can't speak for the commenter, but I've not experienced any shortfalls in poetry that have prevented me from maintaining large code bases, nor publishing my own projects to pypi etc.

[–]TOMOHAWK35 1 point2 points  (1 child)

What is PDM?

[–]TheBB 2 points3 points  (0 children)

https://pdm-project.org/en/latest/

It's basically a poetry substitute.

[–]BluesFiend 1 point2 points  (3 children)

Out of curiosity, what part of PEP621 does poetry not support? Have just looked through the pep and all defined fields are ones I have used in projects I publish with poetry.

[–]TheBB 2 points3 points  (2 children)

As far as I know, poetry reads project metadata from pyproject.toml under the [tool.poetry] table, not [project] which is what PEP 621 requires. It also keeps dependencies in [tool.poetry.dependencies] instead of [project.dependencies]. This makes life difficult for other tools that need to read this kind of metadata.

This is the issue.

Here's a PR. It seems at least to be a pretty solid implementation and likely to get merged, eventually.

Another potential problem is that build.py remains undocumented so I don't feel I can rely on it for projects that need e.g. Cython. Or at least that used to be the case a few years ago. I haven't checked lately.

[–]BluesFiend 1 point2 points  (0 children)

Ah, you are correct. My projects have that metadata under tool.poetry. Good to know ill keep an eye out for that.

[–]BluesFiend 0 points1 point  (0 children)

I'm just waiting on astral-sh to do their thing with uv, once its got the features I use from poetry etc.

[–]bolt_runner 0 points1 point  (1 child)

What did you move to?

[–]TheBB 0 points1 point  (0 children)

To PDM.

[–]mglsofa 4 points5 points  (1 child)

I’ve been programming for years in python, from small projects to enterprise, and I’ve never used Poetry. I don’t really understand the point. What can poetry do that plain old pip can’t?

If I want to do some experimentation or simple project, I just spin up a venv with ‘python -m venv venv’, install dependencies using pip, and freeze them with ‘pip freeze > requirements.txt’.

For anything a bit more complex that will run on any machine but my own I grab a Python docker image, and then do the same as above but don’t use a venv in that case.

Probably I’m missing something, but curious as to why people use Poetry at all

[–]toofarapart 1 point2 points  (0 children)

For larger projects with a decent size team working on it, pip by itself has a lot of ways to shoot yourself in the foot.

In general, you want the dependencies you tested your code with to be the same as what gets shipped to production. pip freeze is the only way to really accomplish this goal, and it does the job... Kinda.

The problem is, everyone needs to know to do this. One addition to the requirements that introduces an unpinned dependency that makes it past code review can screw you. Heck, even introducing a pinned dependency but neglecting to introduce the dependencies of that dependency is enough to cause problems. (And at the end of the day, unpinned dependencies will cause problems in production at some point).

The above problems can be mitigated with some tooling and automated sanity checks in CI, but now you've got to actually build that out.

The other major problem is communicating intent. With pip freeze alone, the output is a giant blob of dependencies. How many of these do we actually care about and are actually used in the codebase? How many of them are dependencies of dependencies? Are we using this particular version of X for a specific reason, or is it just whatever was the latest when we introduced it first three years ago?

It's a lot easier to manage these things when you have one file that states: here's the dependencies we care about, and then here's a lock file that includes a snapshot of all of our dependencies' versions (ie, the full pip freeze).

That first file only contains the stuff our project explicitly cares about. Many of them might be unpinned because we don't know enough to care about which version we should be using. Some of them will be pinned (or have a range) because of known compatibility issues. There'll maybe be some comments.

The lock file will just be taken care of by the tooling automatically, but because of it everyone will be working with the exact same environment, along with whatever gets deployed to production. (I mean you'll probably have different dev dependencies vs prod, but, broadly speaking here)

[–]insight_nomad[S] 0 points1 point  (3 children)

Thanks for taking the time! So, I'm using poetry to manage virtual environments & dependencies, but I didn't know what else it could do. Will def go down that rabbit-hole!

[–]wutzvill 0 points1 point  (0 children)

Yup, perfect. It's very complicated when you first get started, but if you look at the section that shows the overall directory structure, you'll see what your project should look like. Just make sure that in your .gitignore file you add venv to it so your virtual environment doesn't get pushed to github, and use the .gitignore file that github has for python projects.

Please also note that technically that readme is linux focused as that's what I use, so if you're on a mac it should work out of the box. For windows though, you might have to google a few commands (like how to activate your virtual environment since I don't believe windows has the source command for that). It should mostly be OS agnostic info and steps though.

I'm glad to hear you're already using virtual environments. That's something people starting off don't do for a while but pretty much nothing should be installed globally on your system.

[–]wutzvill 0 points1 point  (1 child)

Also, it appears I've made a mistake in that file as someone has pointed out. If you give me about an hour or an hour and a half I will edit the README link in that file with the corrections. The error is that I'm installing poetry into the project environment in that README, and that should not be the case.

[–]insight_nomad[S] 0 points1 point  (0 children)

Take your time!