-
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
[Discussion] Poetry to provide a decent hook-based plugin system #693
Comments
Hi, What does we want ?
What is different in poetry for doing this ? Should we try to implement this ? Anyway, the idea of a plugin system is itself a great thing !!! |
Just for information: I am currently rewriting the core of Cleo to make it more flexible and pluggable. Regarding the actual plugin system, I am not sure what it will look like just yet. But the general idea is to be able to add commands and command options to Poetry like @jgirardet said. I also think being able to hook into the Now, i will likely implement the plugin system myself and make a PR to get feedback. This is something I had in my mind from the start but there were more pressing matters than this but since Poetry is on the path of stabilization I think it's a good time to start experimenting with it. I can't guarantee that it will make it to the |
Cool, thanks for the info. |
Hey @sdispater, is https://poetry.eustace.io/docs/plugins/ something that implements what you wanted? Is it already possible to hook into that? |
@sdispater any updates? |
while @webknjaz inital post points to uses that would extend |
Hi, @sdispater ! Our team is looking for pipenv's alternatives and poetry seems great, if it'd have plugin system, which is mandatory for our development process. I've seen that related PR is in progress -- can you give us eta for this feature? |
Another use case for hooks would be calling preprocessors like cython or template precompilers. One important thing is that this requires the plugin interface living within the projects python virtual environment, while the plugin interface discussed above lives in the python interpreter where poetry is installed. The big advantage of a plugin interface living in the project interpreter would be, that it not only solves the preprocessing-requirement, but also the other requirements of this issue on a per project basis. This would mean that adding a plugin is as simple as adding a development dependency to |
Is there a pre publish hook or any work a round or hack to get this? EDIT: i created https://pypi.org/project/poetry-publish/ and used poetry via subprocess... |
That would be really useful if plugins could be installed inside the virtualenv of the package, not system/user wide! |
Would be nice if the plugin system allowed customizing the execution of package installation. This would allow a significant speed-up by enabling parallel installation: see https://github.com/python-poetry/poetry/pull/2374/files |
Cool, did not realize this was covered in "Download distributions separately before installing them.". |
Is it possible to somehow hook into poetry today, which e.g. makes it possible for me to inject the version from setuptools_scm into pyproject.toml just before building a wheel using I'm looking for a "quick fix" until there is a proper setuptools_scm support with poetry. This is what I do currently, but it's not at all very nice...: # scm_version_hack.py
from setuptools_scm import get_version
def write_toml(filepath="pyproject.toml", reset=True):
contents = []
new_contents = []
with open(filepath, "r") as infile:
contents = infile.readlines()
for line in contents:
if line.startswith("version ="):
if reset:
new_contents.append(f'version = "0.0.0" # DO NOT CHANGE VERSION HERE\n')
else:
new_contents.append(f'version = "{get_version()}"\n')
else:
new_contents.append(line)
with open(filepath, "w") as outfile:
outfile.writelines(new_contents)
def main():
print(get_version())
if __name__ == "__main__":
main() python -c "import scm_version_hack; scm_version_hack.write_toml(reset=False)"
poetry build
python -c "import scm_version_hack; scm_version_hack.write_toml(reset=True)" |
@fredrikaverpil, you may be interested in this pseudo-plugin I made: https://github.com/mtkennerly/poetry-dynamic-versioning |
Thanks @mtkennerly that looks nice! 👍 So I think then my current workaround is probably better in the interim. |
I wonder why this feature would not be provided by Poetry out-of-the-box, of course on a voluntary basis. |
Is there any update on this ? We deploy our project in two pip packages (a @abn , it seems @sdispater isn't contributing anymore. Will someone take over the issue ? |
Fixed the dependency on poetry instead of poetry-core in pyproject.toml. Fetching the version from git tags now when using setuptools (for poetry we cannot do that currently, see python-poetry/poetry#693).
Example (simple but useful initial concept) project utilizing the new plugin system is at https://pypi.org/project/poetry-date-version-plugin/ and https://github.com/miigotu/poetry-date-version-plugin #3733 makes the possibilities endless It requires installing poetry from master |
Does this means the plug-in can be located inside the virtual env and not on the same installation than poetry ? |
Yes, it can be installed next to poetry itself with pip even |
What I would expect is not to pollute the system install and everything works from the user’s virtualenv |
It works either way. If poetry is inside a venv, so are the plugins. |
I was hoping as well that it would be possible to enable a plugins specific to a project. However, it seems difficult to allow them to run within the virtualenv that you created with Poetry, since that might be running an entirely different Python version than the one that Poetry is running in. |
That's when you run |
@miigotu, @gsemet meant whether you can include a plugin in your project dependencies that will be invoked within your project's virtualenv. Kind of like with setuptools, you could include setuptools_scm in setup_install to get project version from git. Anyway, I looked at the PR and the answer unfortunately is that plugin needs to be installed in the same environment from which poetry runs. Then your pyproject.toml needs to declared it wants to use it. So ultimately is similar what existing unofficial plugins were doing, just that now there's an official way to do it. This kind of sucks for reproducibility (another developer will need to also install this plugin), but it is still something. I'm hoping that maybe in the future when you run
|
If you want this plugin system to work you need to treat this plugin like a “dev-package”, ie, just install it within the virtualenv. My use case is auto versioning. I just want this feature for the moment it needs to be installed on the user environnement (poetry-dynamic-versioning). So I have a ugly bootstrap script that installs it with a fixed version, like the old days where no lock files existed... the plugin dependency should be declared and controlled in the lock file, so that two different project could use two different versions of the same plugin. |
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. |
It's a follow-up for #672 (comment).
Issue
So setuptools have this nice hook points system where they allow replacing certain utils by some third-party implementations.
It can catch up with what's available by iterating through a list of entrypoints with names corresponding to hooks.
This is a fairly popular technique among setuptools-based dists. For example, pytest and tox support having third-party dists being automatically activated and used when installed given they "advertise" their entry points as required by the plugin system. These two tools use https://github.com/pytest-dev/pluggy to achieve this.
Back to Poetry, I think lots of people agree that providing ability to extend such a great tool is a widely wanted feature.
This would allow adding custom dist/package format generators, custom metadata generators etc. They could be used to retrieve long description from some esoteric formats or places converting that into supported markups. This would also make possible having a custom version constructor like popular plugins to setuptools facilitating version sourcing from Git/Hg (#140/#672). Or, another example, exporting a pinned env and direct dependencies into pip-friendly formatted requirements. And who knows, maybe someone will even try out having another resolver replacement?
Any thoughts on how this might look like?
The text was updated successfully, but these errors were encountered: