-
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
pyproject.toml option equivalent to "--no-root" #2458
Comments
Just out of interest: What's your use case for the no-root option? Because I couldn't imagine one for me until now. |
|
Hello @techdragon, could you provide a small example, that shows the problems you have? fin swimmer |
@finswimmer I took a few days to ponder, and I honestly cant remember the exact problems I was having which isn't a great starting point for producing some examples of them. I could try swapping a random sample of my projects to the normal default flow of not using "--no-root", but I really don't want to break anything, and the alternative of making new some random new projects and trying to find problems, is awfully close to trying to prove a negative. |
I would love to have this feature as well. The types of projects I work on typically have no use for installing the project itself in my environment, and I'd love to be able to skip this useless (for me) part of the installation process, without having to type (It also, to me, feels a little odd to have this self-installation behavior be the default behavior, even if in my case it is just harmless overhead.) |
I think the root install is an issue mostly because it's a surprising special case and thus impacts usability. I think for many people the local-package install breaks people's mental models of how virtualenv "normally" works. Classically, the working directory is code under development, and the environment (system install and/or virtualenv) contains imported copies of dependency code not under development. The surprise is compounded by the use of "editable"/"develop" mode, which is a somewhat oddball installation mode -- and not particularly indicated unless you read the documentation very closely. The "poetry install" command is mostly pitched as "install my dependencies", not "install my dependencies and also 'build' myself". To be clear, this isn't super terrible. The virtualenv is project-local, so you're not polluting a shared system image with development code. Editable/develop mode mostly works to give you a Pythonically fast edit/run cycle. But again it is surprising, and the surprise can lead to things being broken when people don't understand the magic that has taken place under the hood. Specifically, if the project doesn't follow standard layout (e.g. "this is just a couple quick command line scripts, I don't want to make a whole module directory") or otherwise has some unusual install-time actions, then the root install can break stuff -- I've run into this myself. This can be hard to debug. Furthermore, the fact that "poetry install" (re-)installs the local package every time it's run, even if literally nothing has changed, feels weird, because the rest of "poetry install" is very nice about doing nothing when nothing needs doing. Finally, last and least, you get these weird .egg-info files around, which are annoying litter. So, in summary -- the biggest problem with root install (and thus, the biggest reason people want to opt out of it with a project configuration flag) is one of user surprise. Perhaps simply doing a better job of describing the intended development cycle (both in the docs and in runtime help and output) would help the problem. As it stands, when introducing poetry to people, I always have to give two big "gotcha" warnings -- one is the silly python2/python3 installer thing, and this is the other one. If I don't, they almost always trip over it at some point. |
Hello, it seems we have very different expectations about that :) For me, I still have not found any use-case, where I need to use Let's assume a simple project like this:
How do you import fin swimmer |
In that particular case (and this may be more common than you'd think), I'd just put cli.py and sharedcode.py in the toplevel, not even in a package. You can run "./cli.py", which can "import sharedcode" and everything is very simple and doesn't require any poking into subdirectories. Nobody publishes anything like this into pypi, of course, but for quick Python scripts it's fairly common. |
You mean like this?
Then just do so. As fin swimmer |
The bigger point that some of us have tried to make in this thread is that the behavior of installing a root package by default is surprising and unusual in the context many Python projects and practitioners, and it would be good to have a way to disable that behavior at the project level. @finswimmer, what I'm hearing from your comments is that Poetry wants to be an opinionated tool in this respect, and not necessarily a tool that's geared towards a broad audience of Python practitioners. If that's the case, it would be helpful to be explicit about this in the documentation, to avoid further discussions like this one, which seems to have devolved into a "well, it works for me" in a way that does not seem productive. I would also suggest closing off this issue with that clarification, to avoid any other hopeful souls like myself getting their hopes up and wasting their time upvoting the issue. |
I opened this knowing it should be fine for most people, otherwise someone would probably have opened it before me. I'm simply seeking a way to turn this off when necessary. I'm not suggesting we make something users have to think about or suggesting we add new capabilities to
This issue is about adding a matching option into |
Hello @anaulin,
of course
I don't think we should close this now. We appreciate user input about how they use fin swimmer |
@finswimmer , with all due respect, I note that you are focusing on use cases and "what is possible" and "what is not possible". I would like to gently encourage you to also consider the feedback about "what is confusing" and "what is surprising". Note that confusion and surprise can be addressed in various ways, not just by adding or adjusting features. The way the tool communicates, the way configuration is done, and the way the documentation is written can all contribute to reducing confusion and surprise. Finally, it seems strange that there are "command line only" flags and "configuration file only" options. Is there a reason poetry doesn't have a unified configuration system that would have avoided this discussion entirely (allowing any flag default to be changed in the configuration file, and allowing any configuration option to be changed on the command line)? |
This is the only thing I’m keen to focus on. I feel like all the other things are distracting from the simple request I opened to add a config file option to reflect this one command line flag so it was “unified” and available in both places. Simple as that. I’d have written the PR myself if I wasn’t busy. |
I've run into a lot of friction with this as well. To @anaulin's point, this behavior tends to confuse other folks when I introduce poetry into a project and I feel like it is a hindrance for broader adoption. A per-project config option to set this makes a lot of sense to me since you generally either want the behavior or don't and it is unlikely you will be switching back and forth. Is there active resistance to a PR for this or is it more a matter of someone taking the initiative to start drafting a PR? |
There is an extremely common misunderstanding of virtualenvs that I think is what has lead to this request. A virtualenv is, by design, independent of (almost) everything outside of it by default. You should have no dependence on your modules being importable simply because they happen to be in your current directory. What could be more environment-sensitive than that? :P This has harmful effects such as false successes where your app seems to work during dev because you have a package in your current dir, but fails when you deploy it because you failed to ensure that that package is included in your build artifact. Consider that virtualenvs don't need an associated "project directory" at all. E.g. when you use You need to think of a virtualenv as being isolated and independent. You should have a true install (even if it's an editable one) of your project so that you can be (more) confident that it's working the way it will in the real world. I strongly suggest two measures to help you adjust your mental model:
Poetry, pyenv, and other virtualenv management tools are typically designed around this best practice. This is why installing the project is the default behavior, and it's how it can be the case that while some can't imagine why it's the default, others who have a strong understanding of virtualenvs scratch their heads as to why you could possibly want it any other way. IMO it's a bad idea to add a configuration explicitly for the purpose of easing a bad practice. |
With all due respect, @mikenerone, I disagree a bit with your analysis. (I would like to gently point out that your tone lands as a bit condescending, which I presume you don't intend; you strongly imply that a lack of technical proficiency is the only reason for disagreement on this issue. Please consider alternative ways to highlight assumption mismatches; thank you!) First, you seem to be asserting that always-run-from-venv is the One True Development Workflow (if using a venv at all), or at least the Definitely Best Development Workflow. It's certainly not a bad workflow, your advice is a quite reasonable default for anyone developing a Python package that will be shared via package distribution systems (pypi, etc), and "test like you fly" is generally good practice for sure. However, not everyone is developing a Python package that will be shared (some of us mainly use Poetry to consistently manage dependencies, not to build a package), and even for those that do, there are plenty of other workflows that can also work and verify installability. Second, even if that workflow is generally good practice, there is still a surprise factor being discussed, which is somewhat orthogonal. For example, the description of "poetry install" says: "The install command reads the pyproject.toml file from the current project, resolves the dependencies, and installs them." This implies that it installs dependencies and says nothing about installing the current package. The fact that it also does that is surprising and disconcerting and breaks people's mental model that Poetry is managing dependencies, since it's also stuffing the contents of the current directory into the venv. In any case, you may be quite right that differing assumptions from different user communities are what make this thread weirdly contentious. (One wouldn't normally expect that a request for a command line option also be settable from a configuration file would be in any way controversial!!) If that is accurate, then that observation may show a path to resolution, namely (1) decide whether it is in fact desirable for Poetry to strongly center on this One True Way, (2) if so, make sure this is made more clear in Poetry's documentation and operational communication -- for example:
As a final remark, it's probably best if we please try to take on board that the people asking for this are highlighting a spot of confusion, surprise and dismay -- I'd prefer if we figure out where that comes from and how to resolve it (which may not be by implementing the feature request as originally proposed), rather than assert that it is unnecessary or ill informed? Many of us are willing to offer PRs, but of course don't want to do something that runs against the grain of the design intent. |
Indeed, no disparagement is intended. If I feel it's a misunderstanding, I also acknowledge that it's a super common one (almost always one of the first corrections with new hires), and also that I had the same misunderstanding myself at one time. If there's a fault, it falls with documentation regarding virtualenvs, not the developer community at large. In any case, though, it's certainly not a "special case" as you said. I do agree that something should be done about the confusion. A bit of explanation about it in the Poetry documentation to provide some guidance might go a long way toward addressing the issue. |
It'd be nice to pause the mutual 'splaining of the Real Good Way to Do Python ™️ , and instead refocus on @nextmat 's very practical, and reasonable, question:
|
@anaulin Hmm, a single comment that attempted to explain the reason behind that resistance, directly addressing that question, followed by an exchange about what else to do about it in light of that resistance? That's what you want paused? |
(I also think answering @nextmat 's question would be nice! And then we can unpause the discussion of Larger Changes. "Pause" doesn't have to mean "stop" after all.) |
Well I stated very clearly that for me the answer is yes, there's active resistance (not that I get to make the decision or anything). That's why I don't really get why @anaulin's criticism about not answering that referenced my comment. If you're upset that it's been too long since a response from Poetry devs, don't point at me about it. |
(OK, who's the decider? I'm actually unfamiliar with the governance of Poetry. Would it be @finswimmer ?) |
@finswimmer, @sdispater, and @abn |
@mikenerone seems you felt personally called out. Sorry you feel hurt, that wasn't my intention. I was referring to the several comments on this thread that have happened both before and after you showed up, both by you and others, about what constitutes or does not constitute the "standard" or "right" or "better" way to do Python. I'm sure you are aware that you are not the only participant on this thread. I did not read your comment as a response to the direct question, but rather as a detailed explanation of why some folks don't like the idea of allowing folks to set an existing Poetry option via |
np, clean slate then. But let's be open to points of debate. It's async communication, and we have to live with the concurrency. :) |
First off, the team appreciates the community's interest in the project, and we are really happy that the project is useful in varied scenarios. Some scenarios are more surprising than others. :) As for the original request, am I understanding this correct that the intent is to be able to configure per command cli option in a project's If it is the former, I do not think that this will be something Poetry will implement. This is not something that, imho, belong in a Obviously there are many ways to achieve the same results. From what I can gather there are two separate use cases being discussed here that would (?) benefit from being able to not install the root project.
Am I missing something here? Note: For topics other than this, please create isolated issues. |
If I may... I feel like what's missing from this conversation is concrete examples of how 1. It is a bit confusing to read that to some users the fact that Indeed the first sentence of poetrys' documentation on the 2. On the other hand, it seems like for some projects, installing it in the development environment (even as editable) is problematic or even a no go. Why is that? What actually breaks or prevents people to work on their project?
Maybe in some of the cases presented in this thread, there is a concrete fix that could be applied before reaching for
This suggestion looks like a good compromise to me. That would mean that the setting would land in a |
Where I run into this are projects where I'm using poetry for dependency management and virtual environment management but don't want to explicitly package anything. This is a pretty common scenario in application development. As a point of clarification, the friction for me is really in two places right now:
Either a poetry config option or a Thanks again for Poetry. In general I find it dramatically better than the alternatives and look forward to resolving this in one way or another so we can just go on with using it. 😄 |
@nextmat Thanks. What happens when you forget to use |
@sinoroc I just get a |
I'd argue this option actually belongs in both One reason why a project might require this option is the popular testing tool Tox. Currently Another is Docker builds. #2760 and #1879 cover various issues in Docker environments where This is doubly problematic in the case of a web based project deployed using docker and tested with tox, where there is potentially (I'd argue this is quite likely) no scenario where the developers actually want to "install" the code they are writing and then the test setup will cause problems, in this situation there is no reason to ever install "the package" at all and forcing this as default behaviour only causes problems by constantly requiring users of There are definitely legitimate uses for having a config file option for always doing the same thing as |
As far as I know (from a previous discussion with @abn), Poetry's maintainers have on their todo list to revamp parts of the code base responsible for the handling of the configuration (which I believe includes the Most likely this feature request ( If some of you feel like pitching in to get this feature released sooner, I guess looking into the whole config subsystem is not a bad idea. Get in touch with the maintainers and ask what their vision is for the rewrite then try to get things moving forward. |
Thanks for the context, @sinoroc. In the interim, here is a short shell function that solves this issue, in case others find it useful: poet() {
if [ "$1" = "install" ]; then
poetry "$@" --no-root
else
poetry "$@"
fi
} |
please make --no-root default |
This would be very useful for a variety of situations where Python applications are designed around the convention of running from a directory rather than being packaged into a wheel at all. For example, the Django
And is run like:
Django applications are typically deployed in this way rather than building a wheel. FastAPI conventions are similar:
uvicorn main:app --reload In both cases, it's normal to run I think that the tension/disagreement is one between libraries and (non-wheel distributed) applications. I think that it's fine that Poetry defaults to targeting wheel-packaged libraries rather than applications, but I also think there is a large user base of source-directory based applications for which being able to explicitly set |
While not exactly the same, Rust's I think having a similar distinction for Poetry would make it more natural to use for non-wheel distributed applications. |
Another use case is for something like a standalone MkDocs project. You may want to use Poetry to lock the dependencies used to build the docs, but there aren't actually any Python files in your project (just Markdown files) so if you run
In these cases, having a way to annotate that this project has no root and allow the simple |
Duplicate #1132. @johnthagen's comments pretty much sum up the state of the art in both the Python and broader packaging ecosystems -- a |
Since Poetry is being used here solely to build mkdocs, if the --no-root option is omitted when installing, Poetry will emit a ValueError. See this Issue: python-poetry/poetry#2458 (comment) Signed-off-by: Stephan Garland <stephan.garland@zapier.com>
The current project could not be installed: [Errno 3] No such file or directory: README.rst The current project could not be installed: No file/folder found for package website - python-poetry/poetry#1132 - python-poetry/poetry#1537 - python-poetry/poetry#2458 - https://discuss.python.org/t/projects-that-arent-meant-to-generate-a-wheel-and-pyproject-toml/29684
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature Request
Can we add an option to the
pyproject.toml
orpoetry.toml
that defaultspoetry
to using theinstall --no-root
behaviour by default, the fact I'm constantly having to runpoetry install --no-root
almost every time (I honestly cant recall a time I haven't used this... so for me its close to always) rather thanpoetry install
makes this feel like something I should be able to configure.The text was updated successfully, but these errors were encountered: