Skip to content
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

Support for application-first, library-first, and non-package modes that change Poetry defaults #1132

Closed
2 tasks done
thejohnfreeman opened this issue May 28, 2019 · 22 comments · Fixed by #8650
Closed
2 tasks done
Labels
area/ux Features and improvements related to the user experience kind/feature Feature requests/implementations

Comments

@thejohnfreeman
Copy link
Contributor

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

I'd like to be able to use Poetry to manage a virtual environment for a project that I never intend to package or publish.

My particular use case is that I want to use Python for testing a project written for another language. I just want to use Python as a cross-platform scripting language that comes with a nice test framework (pytest). I don't want to have to give my project a name or version in pyproject.toml, but Poetry refuses to create a virtual environment or install any dependencies until they are given. Pipenv doesn't have this limitation (because it doesn't try to handle packaging, which would require a name and version), so I'm using it in the meantime. I love Poetry, and I would rather use one tool, so please consider limiting name and version checks to the methods that absolutely need them.

@jacebrowning
Copy link
Contributor

jacebrowning commented May 28, 2019

The --no-interaction mode (-n) will infer the name from the directory:

$ cd <my_project>
$ poetry init -n
$ poetry add pytest
$ poetry run pytest

This has worked for all my application projects (e.g. Django) that will never be packaged.

@thejohnfreeman
Copy link
Contributor Author

Yes, and the version is defaulted. In my use case, this is sitting in a project that has a name and version in another language's ecosystem. Choosing a name is not difficult. There are two good reasons I don't want to have to give a version, though:

  • I don't want the "dummy version" in pyproject.toml to confuse newcomers into thinking that there is a Python package cohabiting with the rest of the project. The project has a version that is tracked in another file specific to the other language's ecosystem.
  • I don't want me or someone else to accidentally run any commands that might try to package or publish this project to PyPI. I want Poetry to warn that packaging is not possible for this project.

And If I'm not giving a version to Poetry, I might as well not give a name either.

@mwchase
Copy link

mwchase commented May 30, 2019

As a general workaround for the second point, you could add a trove classifier starting with "Private ::", per pypi/warehouse#5440

@shelper
Copy link

shelper commented Jun 22, 2021

I also want the option to configure the project that poetry manages as a non-package.
not always want to package the project, e.g., could be a ML or DS project

@neersighted neersighted added area/ux Features and improvements related to the user experience and removed area/venv Related to virtualenv management labels Oct 4, 2022
@neersighted neersighted changed the title "Pipenv mode": a virtual environment manager that does not package Support for application-first, library-first, and non-package modes that change Poetry defaults Oct 4, 2022
@neersighted
Copy link
Member

Renamed to better capture the intent and make this the round-up issue for related duplicates.

@johnthagen
Copy link
Contributor

As prior art to potentially draw inspiration from, see huak, yet another Cargo-inspired Python workflow manager:

huak distinguishes between library and application-like projects. Projects default to the library type if a type isn't specified. Specify the type with either the --lib or --app flag.

After testing it, I noted that huak new --app adds an additional src/main.py, and a script in pyproject.toml:

[project.scripts]
test-app = "test_app.main:main"

It's a small start, but I think this is the idea that Poetry could go down to begin treating and thinking about applications (e.g., a FastAPI app) differently from wheel-packaged libraries.

@followben
Copy link

I came here via #2458, but as an application developer working with fastapi I was also surprised coming from pip that poetry created a root package by default. --no-root isn't onerous, but would be good to have an application-first switch to use poetry for dependency management only and not for packaging my app.

Given the issue consolidation this something we can expect on the roadmap @neersighted?

@silverwind
Copy link

silverwind commented Jun 17, 2023

Seconding this request. I think the only change necessary is that the [tool.poetry] section should be made optional, so instead of

[tool.poetry]
name = "foo"
version = "0.0.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.11"

a minimal pyproject.toml would just be

[tool.poetry.dependencies]
python = "^3.11"

Neither Pipenv nor npm require this useless metadata like poetry currently does.

@con-f-use
Copy link

con-f-use commented Aug 10, 2023

Don't know if exactly related, but there's superficially similar discussion by the PyPA people.

And also my similar (ill-conceived) issue: #8292 (comment)

@johnthagen
Copy link
Contributor

I think the only change necessary is that the [tool.poetry] section should be made optional

This is a good idea. We'd just need to make sure that publish is disabled since one thing that is important in [tool.poetry] even for applications is to prevent accidental publishing of private code:

[tool.poetry]
...
classifiers = [
    "Private :: Do Not Upload",
]

Since we do not yet have:

But, given that applications in this configuration couldn't be built as a wheel, I think applications would get "private"-ness as natural consequence of this change?

silverwind added a commit to silverwind/gitea that referenced this issue Nov 5, 2023
Poetry 1.7.0 or higher will print a warning otherwise, see discussions:

python-poetry/poetry#8369
python-poetry/poetry#1132
ilyagr added a commit to ilyagr/jj that referenced this issue Nov 5, 2023
ilyagr added a commit to ilyagr/jj that referenced this issue Nov 5, 2023
1. Add --no-root to poetry invocations. Poetry 1.7 displays an error otherwise
(though things still work)

https://github.com/orgs/python-poetry/discussions/8622
python-poetry/poetry#1132

2. Document python-poetry/poetry#8623
ilyagr added a commit to ilyagr/jj that referenced this issue Nov 6, 2023
1. Add --no-root to poetry invocations. Poetry 1.7 displays an error otherwise
(though things still work)

https://github.com/orgs/python-poetry/discussions/8622
python-poetry/poetry#1132

2. Document python-poetry/poetry#8623
silverwind added a commit to go-gitea/gitea that referenced this issue Nov 6, 2023
Poetry 1.7.0 or higher will print a warning otherwise, see discussions:

python-poetry/poetry#8369
python-poetry/poetry#1132

> --no-root Do not install the root package (the current project).
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Nov 6, 2023
Poetry 1.7.0 or higher will print a warning otherwise, see discussions:

python-poetry/poetry#8369
python-poetry/poetry#1132

> --no-root Do not install the root package (the current project).
silverwind added a commit to go-gitea/gitea that referenced this issue Nov 6, 2023
Backport #27919 by @silverwind

Poetry 1.7.0 or higher will print a warning otherwise, see discussions:

python-poetry/poetry#8369
python-poetry/poetry#1132

> --no-root Do not install the root package (the current project).

Co-authored-by: silverwind <me@silverwind.io>
ilyagr added a commit to martinvonz/jj that referenced this issue Nov 7, 2023
1. Add --no-root to poetry invocations. Poetry 1.7 displays an error otherwise
(though things still work)

https://github.com/orgs/python-poetry/discussions/8622
python-poetry/poetry#1132

2. Document python-poetry/poetry#8623
@radoering
Copy link
Member

I drafted a PR to introduce a "non-package" mode: #8650

Documentation is still missing, but the PR description and the pyproject.toml added for testing should be enough to give it a try. Please give feedback if this mode satisfies your use cases.

@codethief
Copy link

codethief commented Jan 11, 2024

Adding one more use case that's somewhat similar to @radoering's: We have a monorepo of $NON_PYTHON projects where we use Python scripts for scripting (especially CI jobs, commit hooks etc.) Neither script is a standalone application or a library or anything. Like others have said before, we just use Poetry for dependency management.

On the note of dependency management, the following may or may not also be relevant for the current discussion: I don't understand why Poetry forces me to specify a Python version in tool.poetry.dependencies, given that Poetry doesn't install or manage my Python versions. (I use asfd and a .tool-versions file for that which I now have to keep in sync with pyproject.toml somehow.) Why can't Poetry simply use the Python version I installed it / run it with (depending on virtualenvs.prefer-active-python)? If I remove the Python version from tool.poetry.dependencies I get several errors about how

The current project's supported Python range (>=2.7,<2.8 || >=3.4) is not compatible with some of the required packages Python requirement: […]

Anyway, should I create a separate ticket for this or do people think this ties into the current discussion (and MR)?

@tobiasfeil
Copy link

I have a bash alias for poetry install, because it's cumbersome to type the whole shebang every time, so I'll just add the --no-root option to the alias.

@silverwind
Copy link

silverwind commented Jan 16, 2024

I have a bash alias for poetry install, because it's cumbersome to type the whole shebang every time, so I'll just add the --no-root option to the alias.

Imho, no-root should be made a setting as well in addition to the CLI option, so that it can be set in poetry.toml.

fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this issue Jan 17, 2024
Poetry 1.7.0 or higher will print a warning otherwise, see discussions:

python-poetry/poetry#8369
python-poetry/poetry#1132

> --no-root Do not install the root package (the current project).
@codethief
Copy link

@silverwind …which brings us back to #2458 :)

@nextmat
Copy link

nextmat commented Jan 22, 2024

#8650 looks like it will address needing to use --no-root, and it is currently scheduled for the 1.8 release (#8770). 🚀

@rnickle
Copy link

rnickle commented Jan 30, 2024

The addition of:

[tool.poetry]
package-mode = false

In #8650 looks perfect for my use case.

I'm developing an Ansible collection I would like to package with Galaxy, but I prefer to manage dependencies with Poetry.

Thank you very much!

@yrro
Copy link

yrro commented Feb 15, 2024

Thanks for implementing this. For those reaching this issue from a search engine, the documentation for enabling non-package-mode can be found here: https://python-poetry.org/docs/basic-usage/#operating-modes

silverwind added a commit to silverwind/gitea that referenced this issue Feb 20, 2024
Poetry 1.7.0 or higher will print a warning otherwise, see discussions:

python-poetry/poetry#8369
python-poetry/poetry#1132

> --no-root Do not install the root package (the current project).
@nextmat
Copy link

nextmat commented Mar 1, 2024

Thank you again for getting this in! Updated link since the above 404s for me:

https://python-poetry.org/docs/basic-usage#operating-modes

Copy link

github-actions bot commented Apr 1, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/ux Features and improvements related to the user experience kind/feature Feature requests/implementations
Projects
None yet
Development

Successfully merging a pull request may close this issue.