-
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 scripts
#241
Comments
So, this already works: [tool.poetry.scripts]
funniest-joke = "funniest.command_line:main" Maybe we could support this as well: [tool.poetry.scripts]
funniest-joke = { path = "bin/funniest-joke" } ...analogous to how we can specify dependencies. |
Thanks for the info, I tried a |
It's documented here: https://poetry.eustace.io/docs/pyproject/#scripts |
Ah I misread your initial comments. What's called "scripts" in poetry is called "entry points/console scripts" in setuptools. What I'm referring to is the "scripts" keyword to If at all possible, if those scripts could be somehow selected per-platform, that would be amazing (maybe only for platform-specific wheels?) |
For those interested, I'm working on this at https://github.com/ojii/poetry/tree/non-python-scripts |
@ojii I was just testing you fork and it appears to be working, but I think the syntax I proposed is misleading unless you rename the script, which is something setuptools doesn't do. Say I have this in my
I might expect to be able to run |
I think it's reasonable to just reject those scripts if the filename does not match the key. (In |
Not sure that such rejection would be reasonable. As a user, I would expect either a list of scripts (for plain copy) or mapping with renaming. Having to enter mapping with the same data entered twice (key and part of the value) does seem to be just a source for errors on user's side. |
@cauebs @markovendelin I've updated my branch to re-name the scripts according to the users configuration. Should I open a PR or are there other blocking issues with this? |
Pretty cool! Worthy of a PR, in my opinion. |
Probably waiting on python-poetry/poetry#241 to easily use a "script" entrypoint for a package.
Are there plans to merge #304 any time soon? I've been recommending poetry in the company I work for, but sadly, this feature is a must have :( Edit: Maybe there is a workaround that @cauebs or @sdispater can recommend for this in the meanwhile. |
Is the script section able to execute commands that can help you integrate developer tasks into poetry? I imagine it like this: [tool.poetry.scripts]
test = "pytest tests/ --verbose" It would be a nice feature to have, what do you think? |
I definitely agree. I am trying to do the same thing to run a molten app via gunicorn and it would be much easier to do it this way then write a script for a custom gunicorn application. |
I'd like to be able to type |
I'm keen for something similary to NPM scripts. I would like to use
|
Just wanted to share messy workaround I ended up with. pyproject.toml
You'll need to create file scripts.py
Then run something, for example:
It works :) |
I'd also like to see a feature like this, currently I am doing [tool.poetry.scripts]
generate-code="codegen:generate_code" But this will also create the To run scripts only in dev mode I propose this: [tool.poetry.dev-scripts]
generate-code="codegen:generate_code" This is analogous to |
@mm-matthias @germn @cw-andrews @Kamforka @purificant It looks like there is a desire for developer/project specific helper scripts, but that's not what Scripts in this section will be globally available in any python environment that installs that package. For example, if someone were to install a package that had
in its pyproject.toml, that would be overriding the For a lot of what is being described, which is project specific developer scripts, a Makefile sounds more appropriate. Makefiles have the advantage of being language independent and already installed on most systems. This means for example, your makefile could have a script that setup a installed poetry and used it to create a virtual environment. Here is a simple example of a test: ## Run the tests in current environment
pytest
help: ## Show this help message.
@## https://gist.github.com/prwhite/8168133#gistcomment-1716694
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)" | sort
In your project you could then run I'd rather not have poetry turn into yet another way to run scripts for developers. |
Also you can see an example Makefile in the poetry codebase itself: |
I'm waiting the plugin system to see if something like could'nt be added outside of poetry "core". Make file style command would be very usefull inside the pyproject.toml |
Looks like a similar feature is being added: |
@brycedrennan I see your point, but I still feel like this feature has a direct place inside the Also for those who've got used to It makes it even more confusing for those who are somehow related to But as far as I know the |
Naming aside, we shouldn't overload a section to handle both entrypoints and dev-scripts. And certainly not in a way that would hose the environments of people who installed our packages with global overrides of I'll still have to have a Makefile to handle installing the proper python version (via pyenv) and poetry itself. That's why this just feels like unnecessary fragmentation. It also doesn't help for projects that use multiple languages. Makefile works for everything. I concede there is demand for it though. |
I didn't say we should overload, rather I was talking about a section that could handle task running. I understand that basically anything can be achieved using makefiles, but honestly I never had a Also I think that the main ambition behind |
I thought using the already existing scripts section to support developer tasks was what was proposed here. Based on what you're saying now, I'll interpret that previous comment to mean you wanted entrypoints to be moved to a different section. Makefiles can be pretty messy in some projects and thus its common to find them intimidating. Here are makefiles from libraries you use: |
I don't think python-poetry/poetry-core#40 is related to this issue |
@euberdeveloper as per the OP, this issue is talking about "scripts" similar to how setuptools does it. I think the issue(s) you are looking for are #591 #2496. |
Ok, I read them and it was written that the owner of poetry won't implement it but there is a third party plugin that works pretty well, thank you |
This is the only thing holding us back from rolling poetry out across our entire company. The posted solutions are workable but it's less than ideal to have to type To help mitigate this I've just created the poetry-exec-plugin, ready and waiting for poetry 1.2 to be released with its plugin system. It works just like [tool.poetry-exec-plugin.commands]
lint = "flake8 && black --check . && mypy ."
test = "pytest" Then your scripts can be run with Hopefully this is helpful to others 😄 |
|
Why is this not built in? It's pretty much a must-have. Installing an extra plugin is strange. |
From what I understand the team behind poetry has made a decision not to support this kind of user experience in the core codebase. Other similar teams in different communities / programming languages have made different decisions and this thread reflects that. |
This change refactors implementation and tests relating to script file specifications. Relates-to: python-poetry#40 Relates-to: python-poetry#241
Re @hg-zt
I just want to package a |
Per the poetry-core ticket that closed this issue, the syntax is
and it only works with poetry-core 1.1.0a5 or later (which will need to be specified in the build-system table in your pyproject.toml), and hence Poetry 1.2.0a1 or later, and But given the above caveats, it should package the desired scripts into the sdist and wheels, and then they will be installed by the installer (i.e. pip) as expected. You can see some examples in the poetry-core test suite. |
Hi @TBBle, Can you confirm the syntax is still correct?
To test, I changed the section to be
And then the check worked, and the package was correctly built, and included the script. |
That looks like a bug in poetry-core, so I'd report it separately. I guess
and so should the use of That said, the example in the poetry-core test suite hasn't changed, so I'm not sure why it doesn't reproduce there. Either way, worth a new bug report since this ticket is closed and your issue won't get the attention it needs here. Edit: Turns out there's already a fix in progress: python-poetry/poetry-core#404, as this issue was reported at #4665 (including by you, I see now). |
1.2.0a2 is behind the release version, I had to use the regular release rather than the alpha. |
What version do you mean by "regular release"? There's no non-pre-release version of 1.2 series Poetry (the latest is 1.2.0b2), and the current release versions of Poetry (1.1 series) do not have this feature. Poetry 1.1.x only supports what setuptools calls "console_scripts entry point", not what setuptools calls "scripts". (Both are different kinds of "scripts" in Poetry's terminology, and the latter is what this issue was requesting, and has now been implemented for Poetry 1.2). |
Any updates here? |
See #2310 for where updates will appear, since this issue has been closed after the underlying support in poetry-core was delivered, so it works for package creation, but apparently not As noted in #2310, it's also missing from the docs still, although maybe that's because of the current non-working cases. |
Any updates here ? |
It's been almost 5 years lol |
Nope, no updates here, and there won't be any, as this issue has been closed, and the support for |
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 would be nice if poetry supported the scripts feature of setuptools (note: this is not the same as entry points).
I tried using a custom build script but it seems to be ignored by poetry when building wheels.
The text was updated successfully, but these errors were encountered: