-
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
prebuild action before 'poetry build' command #5539
Comments
@sblondon we do have an undocumented feature to use a build script. This is undocumented because we have not yet formalised the api for this, so use with caution. You can see an example configuration for this here. The script it refers to is here. This example is for generation of extensions, but you can use the same principle to generate files however you want. |
Thank you @abn for the hint. It works for translation too. In case it helps someone, there are two modifications:
[tool.poetry.build]
generate-setup-file = false
script = "build.py"
import subprocess
def create_mo_files(setup_kwargs):
print("Compile translations:")
subprocess.run(["pybabel", "compile", "--directory", "package_name/translations"])
return setup_kwargs
if __name__ == "__main__":
create_mo_files({})
I don't close the issue because I don't know if you want to keep it open until the feature is released. In my point of view, it could be closed. |
You might want to also add The changes in #5401 will also ensure these are picked up before the build script is run. |
undocumented feat:python-poetry/poetry#5539
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
My usecase is to compile .po files to .mo files before building the package. This issue talks also about a generic way to implement it.
There is already topics about including data :
nox
(Possible feature: nox/CI generate MO translations for generating wheels cjolowicz/cookiecutter-hypermodern-python#790). Closed, and I don't think it's a good way to fix this usecase.The problem is not about including the files: they are inside the python tree. If it was not the case, set up
include
configuration (include documentation, about sdist and wheel) would solve it.The need is to generate automatically the .mo files. I think about several way to do it:
poetry build
. It works but we have to remember to not usepoetry build
alone.tool.poetry.scripts
section in pyproject.toml, then executepoetry run mo-files; poetry build
Everything is in poetry, but we still have to remember to not use
poetry build
alone.poetry build
does the prebuild command before. The pyproject.toml could be:The value could also be a path to a shell script too instead of
package_name:function
if you think it's better. It's not my prefered choice because it change the behaviour with thetool.poetry.scripts
. If someone needs to run a script, it's possible to usesubprocess.run()
to do it. In my case, I would probably do that to runpybabel compile ...
Such solution is generic enough to solve other needs before building package. It's not limited to generate .mo files.
The text was updated successfully, but these errors were encountered: