poetry: setup.py generated by `poetry build` does not have included file in package_data
-
I am on the latest Poetry version.
-
I have searched the issues of this repo and believe that this is not a duplicate.
-
OS version and name: Ubuntu 19.04
-
Poetry version: 0.12.17
Issue
I have a web project that builds a static JS file, which I have explicitly ignored in my .gitignore file, but that I do want to include in builds of my project. Adding that file to the include directive in my pyproject.toml works correctly in that the file is included in the sdist tar, HOWEVER, it’s missing from the package_data entry in the generated setup.py, so when I install the package, the file is not included and the installed package is broken.
Here’s the setup. I have two files in a package sub-directory:
web/static
|-- app.js
|-- utils.js
Then in .gitignore this line:
web/static/app.js
In pyproject.toml:
packages = [
{include = "web"}
]
include = ["web/static/app.js"]
Running poetry build -f sdist succeeds. But then setup.py looks like this:
packages = \
['web']
package_data = \
{'': ['*'],
'web': ['static/utils.js']}
I would expect that a file specified in include would have an entry there, or be covered by another rule, but that’s not the case and it breaks things for me.
Let me know if you need more info or how I can help. Poetry is awesome.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 31
- Comments: 29 (8 by maintainers)
Commits related to this issue
- Add py.typed file for PEP 561 compliance https://www.python.org/dev/peps/pep-0561/ https://mypy.readthedocs.io/en/latest/installed_packages.html python-poetry/poetry#1338 The py.typed file indicates... — committed to br3ndonland/inboard by br3ndonland 4 years ago
- Add py.typed file for PEP 561 compliance https://www.python.org/dev/peps/pep-0561/ https://mypy.readthedocs.io/en/latest/installed_packages.html python-poetry/poetry#1338 The py.typed file indicates... — committed to br3ndonland/inboard by br3ndonland 4 years ago
- Add py.typed file for PEP 561 compliance https://www.python.org/dev/peps/pep-0561/ https://mypy.readthedocs.io/en/latest/installed_packages.html python-poetry/poetry#1338 The py.typed file indicates... — committed to br3ndonland/inboard by br3ndonland 4 years ago
- :sparkles: Package and distribute type information From [Hypermodern Python Cookiecutter](https://cookiecutter-hypermodern-python.readthedocs.io/en/2020.6.15/guide.html?highlight=py.typed#the-initial... — committed to TeoZosa/cookiecutter-cruft-poetry-tox-pre-commit-ci-cd by TeoZosa 3 years ago
- Include py.typed in the package See python-poetry/poetry#1338 and also https://python-poetry.org/docs/pyproject/#packages — committed to wearepal/ranzen by tmke8 3 years ago
- Made ServoX PEP 561 compliant (see eg. https://github.com/python-poetry/poetry/issues/1338#issuecomment-703737178 https://gist.github.com/br3ndonland/987bdc6263217895d4bf03d0a5ff114c#pytyped) — committed to opsani/servox by ekalosak 3 years ago
I’m having the same issue.
@abn just wanted say a big THANK YOU! I really appreciate the well thought out responses. Poetry is in good hands.
i hit the same when i try to include a marker according to PEP561:
which results in
but the file is not excluded in any vcs-related context.
py.typednow appears to be properly included after packaging my project with Poetry 1.1.0 and poetry-core 1.0.0.To verify without affecting your PyPI package, you can publish to Test PyPI as described in the PyPA tutorial.
Thank you to @abn and the other maintainers and contributors 🎉 👏
@atollk I would not call the use of
setup.pyto be the “canonical way” of managing python packages. It has most certainly been the defacto option for a long while. However with the introduction of PEP 517 and PEP 518, the python packaging ecosystem is building towards a “standards” based approach that detaches the tool specifics from the package build-system configuration. The use ofsetup.pysimply indicates the use of setuptools as the PEP 517 build backend. For poetry managed packages we expect poetry to be used as the build backend. For context,pipsupports this from version19.1. TLDR; python package managers should be able to build packages defining build systems viapyproject.toml.As for PEP 561, by the time the setup file generation is removed, we anticipate the required features to be supported. For example see #2000. This needs to be ported to core, but I do expect to see the
py.typedusecase supported soon. Hope that helps.I’m not sure how related my problem is to this issue and if it warrants a separate issue, but
include = ['package/file.py']doesn’t seem to override my.gitignoreas I expected it to. It does not end up in my installed package in site-packages when I runpip install ...gitignore:
pyproject.toml:
Removing the entry from
.gitignoreworks fine, however.Running
poetry buildseems to correctly include the file in the wheel and sdist (and doesn’t if I don’t include thetool.poetry.includeentry, as expected).I’m working on it in https://github.com/ActivityWatch/aw-qt/pull/51
Edit: I made a dirty workaround that temporarily comments out the file from
.gitignorebefore building (and uncomments when build is done), but would appreciate a clean fix.@bdoms Yes, we understand that in rare cases where the project maintainer wants to remain compatible with downstream build scenarios that rely on older build toolchain, this might require user intervention. However, supporting a feature like this in perpetuity is not a good idea for a few reason. Maintaining
setup.pygeneration as we expand poetry’s capabilities becomes harder as it requires us to take into consideration various cases. This overhead does not make sense in comparison with the small cross section of scenarios that may be invalidated (ie. package manager, pip or otherwise, uses a version that does not understand PEP-517 and only knowssetuptools, the platform does not have pre-built wheels for the packages and requires the use of thesdist) and the fact that these issues can easily be worked around. Also it should be noted that the generation ofsetup.pyfile was always meant to be a workaround rather than a supported feature. The current implementation of this is in no way considered reliable in all scenarios. Additionally, withpoetry>=1.1.0, if the build happens in apoetrymanaged virtual environment, thepipversion used will be the version bundled withvirtualenvproject, which at the moment is20.x.All this said, it is also important to note that this is not happening overnight. The following steps need to happen prior to this being removed.
tool.poetry.build.generate-setup-fileintroduced in a GA release (1.1.0), defaulting totrue. (opt-in)tool.poetry.build.generate-setup-filedefaults tofalse(1.2.0). (opt-out)setup.pygeneration deprecation (unplanned).setup.pygeneration removal (unplanned).I like Poetry a lot because it has generally made my life easier, but removing
setup.pyfrom sdist builds is a backwards incompatible change. There’s no guarantee that people are using a version ofpipthat works without it, or evenpipor any other build tool at all - they may just expectsetup.pyto be there and call it directly. If you’re following semantic versioning the backwards incompatibility requires a major version change in order to be implemented. I get that you may not use it yourself, but make no mistake: THIS WILL BREAK PEOPLE’S WORKFLOWS. There’s gonna be some bad days when build/deploy systems suddenly stop working and devs are scrambling to find out why.As for whether it’s still happening, I just ran
poetry self updateon Ubuntu 20.04 with Python 3.8 and the Poetry version I got was 1.0.9. In that version, yes, this is still happening just as described in the initial report above.@sdispater thanks for checking in! I upgraded to
1.0.0b5and this is still a problem: a file I had excluded in.gitignorebut explicitly included inpyproject.tomlis there in the tar but not insetup.py.The code has moved around a bit since I last checked, but looking at it now the problem appears to be this line: https://github.com/sdispater/poetry/blob/master/poetry/masonry/builders/sdist.py#L137
It’s the
elsecase for theif isinstance(include, PackageInclude)check when creating the list of files that becomes thepackage_data. I have no idea why the files I need fail that check, but all of the files I’ve been having problems with fail there, so they hit thepassline, and thus are not included in the list.