-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for app/library type to poetry new
and poetry init
#9668
Comments
For more on the issues this causes, see: |
In my opinion this distinction between app and lib is flawed for Python projects. (There are many apps that are packaged, e.g. Poetry itself, pipx, pre-commit, ...) Setting package mode as in #9622 and maybe doing more based on this makes more sense to me, because:
I have not thought about that but we could consider to do this when creating a project in non-package mode, too. |
Thank you for the reply! :-)
Yeah I definitely agree that there are types of projects where it's a grey area between "app" and "library" (eg CLI tools, Poetry itself etc). Naming is hard and all that...but by "app" I was instead meaning ~"end-user" projects that are typically not distributed for the world to use, but are used directly by the person or team maintaining them for a very specific purpose. Think Django webapps that people are deploying to production, or data analysis projects shared by a team of data scientists etc, rather than an open source project that's shared for consumption by others. I would argue these types of "app" projects:
Given (1), I think it would be really beneficial for Poetry to support these types of projects better out of the box. (Plus, I would argue that the authors of libraries or of tools like pipx are much more capable of overriding defaults than most end users, so it makes sense to pick the defaults for the more-common and more-beginner-heavy app project type instead.) The current default I would also posit a big reason these types of projects use a package manager like Poetry (instead of using pip and requirements files), is because they want the determinism of a lockfile. However, without also ~"locking" the Python version to at least a major version (eg As-is, all of the options for us (Heroku) adding support for reading the Python version from In contrast, uv's behaviour is already a lot more suitable out of the box for these app type projects: The |
I expect that, although you want to force apps to be not portable to different pythons, other users would find that an annoying default. Specifically wildcarding the python version is error-prone, let's not make that any sort of default #8418. Prefer an upper bound, if you must. However: putting a very narrow range in Except of course that poetry does not lock a python version. I think uv may be different here, perhaps that is significant. (Aside: if you like uv - or any other tool - better - then use that!) IMO if you want a very narrow python version some out-of-band (from poetry's point of view) mechanism is the way to go. |
Thank you for the reply.
This isn't about liking uv better. This is me giving feedback as the maintainer of a PaaS adding support for Poetry (alongside our existing pip + Pipenv support), who has a lot of contact with real world deployed projects and common user pain points. Poetry's current defaults/design choices are currently very skewed towards the use-cases of packaged/published/widely-distributed type projects - which is a project type that is much less common than the simple "app that doesn't need to be published and probably doesn't even need a build backend" case. If Poetry wants to increase user adoption (or reduce attrition to uv), then it seems a few tweaks to cater for this more common project type might be worth considering?
But for a simple app that isn't being distributed, the "project requirements" are actually that it only support a single Python version. It having to declare that it supports multiple is both unnecessary and likely a lie, given the lack of CI etc (described in #9668 (comment)). That said, an alternative option would be for Poetry to do what uv does, and for The downside to this is that for the common "simple app that isn't distributed" case, the user now has to update/maintain the Python version in two places ( |
"poetry" doesn't want anything, people who work with it may want different things. So far as I am concerned - I am very comfortable with people choosing whichever tool works best for them. (As per the comment that you are replying to!) I understand that you have a use case where you want to specify a narrow python range (though apparently still not an exact version) Perhaps we are just repeating ourselves now but summarizing my last: I suspect this is not so universal use case as you think, and I reckon this is not a great fit for being solved in poetry. |
I think this is the primary point of contention :-) I would posit:
Is Poetry primarily focused on people who package/publish/distribute projects? If so, then yeah perhaps Poetry just intending to be a good fit for these "end user app" type use-cases. However, the current README / https://python-poetry.org descriptions seem to suggest it's also aimed at these use-cases, which is perhaps where my confusion lies? |
offering a datapoint: I have a django app that I deploy to Azure, and the definition of the Azure web app is where I specify the version of python that the deployment uses. It's been a while since I used similar services eg heroku but I seem to recall - and would expect - that they too offer a knob where one specifies the deployed python version. In local development I might or might not be using the same python version that I deploy with. so I prefer to have a relatively broad range in my project definition, and only have to update the configuration in Azure (or wherever) when I want to upgrade. Defining a narrow python version in two places would be a small step backwards, rather than forwards. |
I maintain Heroku's Python support, hence starting this discussion :-) We want to move away from platform-proprietary ways of specifying the Python version, and be able to reliably determine what Python version to use when deploying a project from a canonical version used by other tooling (e.g. That doesn't mean there isn't still value in having a way to override the version for Heroku specifically if needed (similar to you adding config to your Azure app definition), but that "deploying the same Python version you tested with" is a pretty fundamental concept for reliably deploying arbitrary end user code, and it's beneficial to not force users to add yet more platform-specific config in the common case.
Based on my experience seeing (and having to deal with) the issues end users run into (at Heroku scale, so not a small dataset), I would confidently state that using different Python versions for local development vs deployment is more often than not an anti-pattern. This pattern should still be permitted of course, however it should not be encouraged by the defaults used by beginners - and instead be something experienced like yourself can opt into. Defaults really do matter! |
well now we're getting to the heart of the matter. This fits with my comment about the poetry configuration not conceptually being the right thing here. To my mind this is simply not what that field is for, and it is overloading the poetry configuration to use it that way. I think I've probably said all that I have to say here. Suggest that if you want more opinions then the most likely way to flush them out would be to submit a merge request, it doesn't sound as though it ought to be very much effort. |
That's a fair point. (Albeit I do believe that semantically it is still correct to say many of these projects only support a single Python version, since they aren't tested against other versions.) Regardless, I still believe there would be a benefit to Poetry helping with the "control/lock the Python version" part of the project management UX here. Ultimately tools like pyenv, GitHub Actions, IDEs, PaaS deployment workflows all need to pick a single Python version to install, and an unbounded version range doesn't let them reliably pick a version. Perhaps the solution is to double down on For example, by:
I'm happy to file separate issues for 1+3+4 (2 is covered by this issue already, with a tweak to the Python version parts) if they sound reasonable to you? |
honestly I don't love any of this, but I am only a contributor and in the end my vote doesn't matter anyway. As a matter of tactics if I were trying to get change accepted, I think it's reasonable to expect that smaller changes have a better chance than larger changes. Also making smaller changes first allows you to test the water. So if you see a sensible way to split things up, that sounds reasonable to me. |
Issue Kind
Brand new capability
Description
Currently if I use
poetry new
orpoetry init
, I end up with apyproject.toml
configuration that is more oriented towards a library than an app, with no way to tell thenew
/init
commands otherwise (beyond--python
, but that's only one of several things that would need overriding).For example they generate:
...whereas for an app:
package-mode = false
from Introduce non-package-mode #8650, and don't want the name/version/description/authors/readme fields)[build-system]
)3.12.*
) rather than allowing an unsafe range (such as>=3.12
) - so prod vs staging vs each developer's machine is at least using the same major Python version.And therefore for apps, a config like the following is more appropriate:
As such, it would be helpful if the
poetry new
andpoetry init
commands accepted something like a--type
argument (and corresponding question prompt when using those commands in interactive mode), that accepted options like"app"
or"library"
, that then generated config more appropriate for the specified use-case. The interactive prompts and/or existing CLI args would still allow users to mix and match if needed (for example, the user could select "app" mode, but when prompted for thepython
value, could override the app mode's suggested default of "3.N.*" to a wider range if they prefer.Such a type option would be similar to:
uv init
's--app
vs--lib
: https://docs.astral.sh/uv/reference/cli/#uv-initcargo new
's--bin
/--lib
: https://doc.rust-lang.org/cargo/commands/cargo-new.htmlPossible arg/option names:
--type {app,lib}
(or--type {app,library}
--app
/--lib
(or--app
/--library
)Note: I intentionally didn't include
--package-mode {true,false}
in the list, since this feature request is about more than justpackage-mode = false
and about several other defaults that make less sense when using Poetry with an app.Impact
Workarounds
Users either:
poetry new
/poetry init
at all, and create theirpyproject.toml
from scratch using the docspoetry new
/poetry init
and fill out questions that aren't relevant, but then have to change the defaults afterwards...but both of these rely upon the user knowing that the default configs generated by new/init are not ideal for app use-cases, and what they should change to make them more suitable.
The text was updated successfully, but these errors were encountered: