You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using setup.py, it is possible to customize commands or use functions to get some results dynamically.
For instance, to run a post install script (that requires dependencies to be installed) one can write this:
class CustomInstallCommand(install):
def _post_install(self):
# Some stuff to do
def __init__(self, *args, **kwargs):
super(CustomInstallCommand, self).__init__(*args, **kwargs)
atexit.register(self._post_install)
and use this class as keyword argument value in the setup() call:
cmdclass={'install': CustomInstallCommand}
(other commands like clean, test, tox can be customized this way too).
Second example, in order to compile translation files (po files) into mo files at setup time:
def create_mo_files():
data_files = []
# do stuff
return data_files
and use the result as keyword argument value in the setup() call:
data_files=create_mo_files()
It looks quite obvious that it's not possible to do such things if one uses only a pyproject.toml file: how would it import a class or a function, or know about it, how to run it? (Or is there a way?)
From reading the code, I've seen that the keyword arguments list passed to setup() is hard coded (to build a sdist), so cmdclass and data_files are not usable at the moment (if I'm not wrong).
I guess this is not the easiest feature to implement. Is it planned or already discussed?
Reacted by Nathan, Ramkumar Bangaru, sedrubal, Yi Cao, Jakub Młokosiewicz, Oleg Höfling, Yin Zhong, Kilian Helfenbein and Marcel Ackermann
Just wanted to create this issue myself! (adding some keywords I was searching for here: post-install hook, post-install script). We can't write the code in pyproject.toml itself, but perhaps we could give a list of paths of scripts that should be run once install completes? This adds a lot to how you can customize the installation (e.g. poetry itself prompts to modify your path on install - could you do that when installing a project built with poetry?), but I think part of the argument for poetry over, e.g., setuptools + setup.py is to not have arbitrary code execution at install. Would it be to much to have scripts that prompt to run at install? Then the user sees something like " is requesting to run <script name> (). Allow this? (y/n)". This seems like a bit of a weird install step, though.
I don't plan on supporting this. The whole idea of Poetry and pyproject.toml in general is to not have executable files to setup a project so it's unlikely it will ever be implemented.
I was just researching Poetry as one of possibilities for our new workflow and I bumped into this issue. Up until now, we've been using good old setup.py with several custom build cases:
compiling translation files .po → .mo (has already been mentioned)
compiling grpc protocol buffers to python modules
calling webpack to transpile and bundle the JavaScript code in our django apps
If Poetry doesn't plan to support these custom build steps, we could:
add generated binary/minified files to our versioning system (ugh...)
call these build steps manually (let's say from a Makefile) before running calling poetry build; unfortunately, that clashes with Poetry excluding files mentioned in .gitignore, but maybe there is a way around it; still, this way seems to be prone to errors (what if I forget to call them?), but kind of OK for the CI use i guess
not use Poetry for the projects that require this (unfortunately, most of our projects requires at least the translations build step – so that would basically mean not using Poetry at all)
I really like Poetry and I thought it could be a solution to our current problems. But without these custom build steps, I'm afraid we won't be able to use it. @sdispater, do you think that there is any way around this? Any chance we could add a hook that would run before each call of poetry build (basically option 2 above, but without the manual component)? That wouldn't necessarily mean adding some executable files to Poetry itself, just being able to call a python function (or a shell script, but I'm much more inclined to Python callable). Or could this be somehow achieved by plugins?
Reacted by Yani Lathouris, Ramkumar Bangaru, Onilton Maciel, Sebastian Hurtado, Martin Kirchgessner, Yi Cao, Nick Groszewski, Edgar Ramírez Mondragón, Jonathan Boudreau, Joshua Murphy and 8 more
Not being able to run custom commands is one of the blockers for us to switch to poetry. There's now a plugin system implemented: #3733 – Probably one needs to implement a plugin to have that feature?
Activity
neighthan commentedon Feb 22, 2019
Just wanted to create this issue myself! (adding some keywords I was searching for here: post-install hook, post-install script). We can't write the code in
pyproject.tomlitself, but perhaps we could give a list of paths of scripts that should be run once install completes? This adds a lot to how you can customize the installation (e.g.poetryitself prompts to modify your path on install - could you do that when installing a project built withpoetry?), but I think part of the argument forpoetryover, e.g.,setuptools+setup.pyis to not have arbitrary code execution at install. Would it be to much to have scripts that prompt to run at install? Then the user sees something like " is requesting to run <script name> (). Allow this? (y/n)". This seems like a bit of a weird install step, though.sdispater commentedon Mar 2, 2019
I don't plan on supporting this. The whole idea of Poetry and
pyproject.tomlin general is to not have executable files to setup a project so it's unlikely it will ever be implemented.stinovlas commentedon Sep 25, 2019
I was just researching Poetry as one of possibilities for our new workflow and I bumped into this issue. Up until now, we've been using good old
setup.pywith several custom build cases:.po → .mo(has already been mentioned)If Poetry doesn't plan to support these custom build steps, we could:
poetry build; unfortunately, that clashes with Poetry excluding files mentioned in.gitignore, but maybe there is a way around it; still, this way seems to be prone to errors (what if I forget to call them?), but kind of OK for the CI use i guessI really like Poetry and I thought it could be a solution to our current problems. But without these custom build steps, I'm afraid we won't be able to use it. @sdispater, do you think that there is any way around this? Any chance we could add a hook that would run before each call of
poetry build(basically option 2 above, but without the manual component)? That wouldn't necessarily mean adding some executable files to Poetry itself, just being able to call a python function (or a shell script, but I'm much more inclined to Python callable). Or could this be somehow achieved by plugins?martinkirch commentedon Sep 3, 2020
In case anyone comes here because of
.mofiles embedding : don't forget to list them inincludehttps://python-poetry.org/docs/pyproject/#include-and-excludeStill, their automatic compilation is not possible. Maybe the plug-in system will solve this, follow #1237
CI (python matrix): Update to 3.10 (python-poetry#265)
dreamflasher commentedon May 26, 2022
Not being able to run custom commands is one of the blockers for us to switch to poetry. There's now a plugin system implemented: #3733 – Probably one needs to implement a plugin to have that feature?
epignatelli commentedon Jan 27, 2023
Ditto, I think that this is a reason why I will not use poetry.
I hope this'll help developers' roadmap.
github-actions commentedon Feb 29, 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.