-
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
Better documentation for how files are included in built artifacts #2015
Comments
Hello @astronouth7303, could you please add more details about what you want to add to a package and/or what information you are missing? fin swimmer |
What setuptools calls package data: Non-module files. The specific discussion was about |
From what I understand, every file in your package directory will be included in the package, unless it is ignored by your |
@thejohnfreeman that's not working for me -- if I explicitly include a file that's in
Specifically, the sdist step seems to succeed, but the wheel step fails. EDIT: While the |
Do you have a link to the failing example, maybe in a branch on GitHub? |
@thejohnfreeman yes! Thanks for the quick reply. Here's the branch: https://github.com/meshy/django-schema-graph/tree/poetry EDIT: I've noticed that there's a stacktrace leading to an |
Here's the stacktrace from the failed CI build -- hopefully it'll help: Traceback (most recent call last):
File "/.../pip/_vendor/pep517/_in_process.py", line 257, in <module>
main()
File "/.../pip/_vendor/pep517/_in_process.py", line 240, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/.../pip/_vendor/pep517/_in_process.py", line 110, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
File "/.../poetry/masonry/api.py", line 39, in prepare_metadata_for_build_wheel
builder = WheelBuilder(poetry, SystemEnv(Path(sys.prefix)), NullIO())
File "/.../poetry/masonry/builders/wheel.py", line 44, in __init__
super(WheelBuilder, self).__init__(poetry, env, io)
File "/.../poetry/masonry/builders/builder.py", line 64, in __init__
self._module = Module(
File "/.../poetry/masonry/utils/module.py", line 68, in __init__
PackageInclude(
File "/.../poetry/masonry/utils/package_include.py", line 15, in __init__
self.check_elements()
File "/.../poetry/masonry/utils/package_include.py", line 37, in check_elements
root = self._elements[0]
IndexError: list index out of range |
Sorry I didn't see this earlier. I could have solved this for you back in February! You need to change some lines in your
The |
Oh excellent! -- I didn't quite get that the first time round. Thank you for clarifying! |
How do I include a full set of sub folders like botocore? |
@brianbruggeman |
@thejohnfreeman It seems like the For example,
You would specify |
@hyliu1989 |
Thanks for the clarification. However, contrary to your explanation,
I produced this case with poetry 1.1.4 with MacOS 10.14.6. The python version is 3.8.5. File structure
Example pyproject.toml (2)
Here setup_cython.py is just some script I used following the undocumented feature mentioned in #11. I don't think it is critical to this case and can be safely removed when you try to reproduce this case. However, I do have to specify Example pyproject.toml (1)I have the following chunk:
|
You are right. Looks like the It could be that everything that's in the wheel gets installed, and this is not something poetry can change. It might be that it is how wheels are standardized, you (or I) should read the standard more in details to be sure (PEP 427). Looks like in poetry files can either be in both distributions (sdist and wheel) or none at all and that's it. Which is not ideal from my point of view. Maybe it is possible to get more flexibility, and I just do not know how yet.
It might be a feature so that files created during custom build steps are added to the wheel. If it is not the case, then yes maybe poetry should throw a warning. But what to do if a joker is used, such as
I am not following this bit. Would you mind sharing more details about this? Personal opinion: Looks likes a lot of flexibility is missing in my opinion. It should be possible to specify files to be included in either the sdist, or wheel, or both, or none. Even more so when a project has custom build steps (as it seems to be your case).
See how I do this with setuptools for example: |
It is the same issue as #3153, which my workaround is to add setuptools in the build.requires. |
Correction... Example project here: https://github.com/sinoroc/poetry-gh-2015 Project file structure:
All files are in the git repository except We want the We also want the
Content of the sdist:
Content of the wheel:
Somehow the These things are undocumented, or I could not find it. I somehow found out about it from #2789 (and this code). Example project: https://github.com/sinoroc/poetry-gh-2015 |
All that's left for this use case is an option for a post-install script that can put data files where they need to be on the system, outside the site-packages directory (and a corresponding uninstall script to remove them). |
Thanks to the assistance from @thejohnfreeman in python-poetry/poetry#2015
hey I think I might be blocked by this too. or something similar. I'm just testing poetry as an option today and simply not getting what I need and I'm extremely confused by the behavior I am seeing. The exact example in the docs here: https://python-poetry.org/docs/pyproject/#include-and-exclude seems like a super dangerous and bad practice and I see no docs about how to avoid it. If I have files at the root of my repo that I want included, they're just going to be dumped into the root of What I'm looking for is an option to Here's my directory structure:
I specifically don't control that resources directory as it's used by more than the python side of things. but I would like to make sure it installs into a directory inside my distribution folder on target machines because I want to make sure I'm not breaking anything. in |
The easiest is to make the directory structure of your source code repository look exactly like the directory structure of your packages. Maybe use symbolic links to achieve this, should work perfectly fine with git. Other thing I want to add is that what you are trying to do is not a "bad practice" but still not the best practice. There are legitimate reasons for what you mention as "seems like bad practice", one might have very good reasons to want to add some files directly to To conclude, maybe show you |
Thanks for the response, @sinoroc. Unfortunately, I can't make my repo structure match the structure that I want in my package because my repo is used for more than python. Here's an example of my current
This is currently a blocker for me if it's not something I can fix with configuration because I cannot deploy a package that will simply throw stuff into It seems like, in order to unblock myself, I should write a script that shuffles files around into a different structure during the packaging process in some tmp directory. Is that what some folks do? |
I guess it's not clear to me why I am able to specify a custom location of my python (with |
We are trying to get this to work and we share @tribals frustration. Some of the solutions suggested in this thread:
It seems the best solution is outlined here #5539 In our case, we want files in We add this to our pyproject.toml
caution: it seems this is a new undocumented feature and may change. I also don't know the fully implications of setting generate-setup-file to false We then have: from distutils.dir_util import copy_tree
if __name__ == "__main__":
copy_tree("src/schema", "our_package/schema") I don't love this though, as it leaves the local tree with duplicate copies of the files, which may cause confusion when developers locally run code that uses pkgutils I would really love to see first-class support for this in poetry, or at least have the documentation advertise the problems with |
poetry aims to create wheels. Things like data_files doesn't work in wheels, hence there's no hook poetry can use for files destined outside of python package area. If you want this capability, the only place that will happen is upstream of poetry. |
I suspect there are two camps here. One that wants data files that need to be installed outside the system site packages and the other that just wants the include files to be placed into the package directory in the wheel during build. The former has many thorns when it comes to universal wheels, and tools that install wheels do not really support it consistently across the board. The latter is less controversial I reckon. However it should also be noted that this will need to be handled somehow for editable installs as well since adding these directories to the @cmungall I'm also curious, is there a reason why src/schema is not placed as src/package/schema in your source tree. This is better for editable installs as well. |
Many of our repos are not python-centric; the schemas (specified as linkml are language independent. By forcing the source to be in src/package/schema we are forcing pythonic conventions on a broad community of data modelers. |
Closing this, because several things seems to be discussed here and the OP hasn't come back to tell if they question is answered. Feel free to open a new ticket if you have any explicit question. |
Hey there - I've come here via Google seeking a replacement for Other than the build script above, is it possible to configure included files to be placed in the |
@AlecThomson Place your data files inside an importable package instead of placing them at the root. This is straightforward. |
Ok @sinoroc. I had actually been attempting to follow some suggestions above in this thread -- symlinking my required files into the package dir e.g.
Which was placing |
After reading python-poetry/poetry#2015, it seems the best solution is to include the "include" directory directly in the project.
# Description ## What is the current behavior? See the referenced issue for details. closes: #1440 ## What is the new behavior? After reading python-poetry/poetry#2015, it seems the best solution is to include the "include" directory directly in the project. ## Does this introduce a breaking change? No. ### Checklist - [x] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
# Description ## What is the current behavior? See the referenced issue for details. closes: #1440 ## What is the new behavior? After reading python-poetry/poetry#2015, it seems the best solution is to include the "include" directory directly in the project. ## Does this introduce a breaking change? No. ### Checklist - [x] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
…section, as this had unintended consequences of installing them into the site-packages directory instead of along side the package code. This is related to python-poetry/poetry#2015 . Since the LICENSE is available in the dist-info directory along side the package, then this is sufficient. Additionally, the python version classifiers will be automatically added by poetry from the version range specification in the tool.poetry.dependencies section, so no need to explicitly define them.
every file in your package directory will be included in the package, unless it is ignored by your .gitignore (see python-poetry/poetry#2015) since we gitignore *.so files, we need to explicitly include them when building wheel
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. |
Issue
While helping with licensezero/cli#3, I was looking for "how to do package data with poetry" but found the docs were unclear or at least extremely implicit about it.
The text was updated successfully, but these errors were encountered: