Closed EvanShenkman-Sonos closed 3 years ago
@EvanShenkman-Sonos appreciate the kind words and also the detailed issue descriptions.
First thing that comes to mind is that this could couple of issues.
docker run --user "$(id -u):$(id -g)" ...
when running this so that the file created ends up being accessible by the user.pathlib
's Path.resolve()
.The temp path usage is expected; since when doing a complete build (sdist + wheel) poetry does create these in isolation. And this happens in a temp directory. You can try poetry build -f wheel
. Another thing to note is to make sure that your include
and package
configurations are correct. It could be that when the isolated build happens these generated files are not copied over prior to the build step.
Related: You could also check this project for an example of poetry manged project that generates python code from protobuf
- https://github.com/python-gnxi/python-gnmi-proto
@abn - thanks for the quick reply!
Yup, after figuring out it wasn't an OS-issue, permissions was the next thing I tried. Even after recursively changing ownership and group-ownership, poetry build
behaves the same way. Inside of the output
directory, I am able to step-into a python interpreter and import and use the generated python source with or without changing the permissions. I don't think permissions are the problem.
I don't think I've changed Docker's storage backend. Below is the output of docker info
. The Storage Driver
field looks like the default.
Running poetry build -f wheel
runs successfully, however it suffers the same problem as the sdist build. If I try to install the wheel, I'm unable to import the namespace or the package and I don't see the directories in site-packages.
Since the copy of the output directory works, I don't think my include
or package
configurations are incorrect. With the copy I'm not changing the directory structure or any of the file contents and poetry build
works as expected.
Tomorrow I will try to follow the same procedure I described initially with the only difference being that I'll run protoc
on the host, not within a container. I'll report back- thanks again!
@abn -- The more I dig into this, the more I'm convinced it has nothing to do with Docker and it's most likely a user-error on my part with how I'm configuring poetry
.
I ran the same protoc
commands on my host, rather than within a container, creating the same output
directory, it's subdirectories, and python source. I'm running into the same issues: poetry build -f sdist
and poetry build -f wheel
both result in empty packages. So it's definitely not a permissions issue nor is it a Docker storage backend issue.
After some more hacking, I was able to get poetry build
working, but I'm unsure about why what I've done works. Maybe you can shed some light.
Here is my updated project structure and pyproject.toml
file...
After looking through python-gnmi-proto repository, I decided to install the betterproto
library and use it to generate the python source.
➜ mkdir output
➜ protoc --proto_path=. --python_betterproto_out=output (find . -name '*.proto')
Writing __init__.py
Writing my_namespace/__init__.py
Writing my_namespace/my_package/__init__.py
Writing my_namespace/my_package/v1.py
➜ tree output
output
├── __init__.py
└── my_namespace
├── __init__.py
└── my_package
├── __init__.py
└── v1.py
In this case, running poetry build
still doesn't produce the packages correctly...
➜ poetry build -f sdist
Skipping virtualenv creation, as specified in config file.
Building my_package (0.1.0)
- Building sdist
- Built my_package-0.1.0.tar.gz
➜ cd dist
➜ tar -xvf my_package-0.1.0.tar.gz
x my_package-0.1.0/pyproject.toml
x my_package-0.1.0/setup.py
x my_package-0.1.0/PKG-INFO
However, modify my packages
configuration (dropping the from part) to...
packages = [
{ include = "my_namespace" }
]
And generate the python source to be side-by-side with the proto tree...
➜ protoc --proto_path=. --python_betterproto_out=. (find . -name '*.proto')
Writing __init__.py
Writing my_namespace/__init__.py
Writing my_namespace/my_package/__init__.py
Writing my_namespace/my_package/v1.py
➜ tree my_namespace
my_namespace
├── __init__.py
└── my_package
├── __init__.py
├── v1
│ ├── bar.proto
│ ├── baz.proto
│ └── foo.proto
└── v1.py
Poetry can successfully build the package...
➜ poetry build -f sdist
Skipping virtualenv creation, as specified in config file.
Building my_package (0.1.0)
- Building sdist
- Built my_package-0.1.0.tar.gz
➜ cd dist
➜ tar -xvf my_package-0.1.0.tar.gz
x my_package-0.1.0/pyproject.toml
x my_package-0.1.0/my_namespace/__init__.py
x my_package-0.1.0/my_namespace/my_package/__init__.py
x my_package-0.1.0/my_namespace/my_package/v1/bar.proto
x my_package-0.1.0/my_namespace/my_package/v1/baz.proto
x my_package-0.1.0/my_namespace/my_package/v1/foo.proto
x my_package-0.1.0/my_namespace/my_package/v1.py
x my_package-0.1.0/setup.py
x my_package-0.1.0/PKG-INFO
This isn't ideal since the distribution contains the proto files.
I'm either not structuring my directories in a way that plays nicely with poetry
, or I don't fully understand the nuances of the packages
configuration option. Any insight would be awesome! Thanks!
I ended up using include
and exclude
glob patterns to remove the proto files from the distribution archive. I think this is an acceptable solution.
I would still be interested in learning about the root-cause of the package
configuration issue I described above.
@EvanShenkman-Sonos Did you ever figure out the reasons this happens? For my part, I noticed a couple weird things:
poetry build -f sdist -n
in the build dir, I get the almost-empty sdist you described above. However, when I run it in the source dir, I get the correct sdist with all my source files included.setup.py
into the right spot, and run python setup.py sdist
in my virtualenv, all my source files get included.D'oh - turns out the problem in my case was due to the aforementioned cmake interaction. The poetry build
command is running in a tree that's .gitignore
d, and poetry excludes any VCS-ignored files from inclusion in any build. A simple workaround of building in the source tree and moving it out to the build tree should suffice.
@brettdh - I got burned by the same exact thing: poetry
was ignoring my source files because of my .gitignore
. Moving stuff around should work. Like I mentioned in my last comment, I was able to override that unwanted behavior by explicitly using an include
glob in my pyproject.toml
file. Hopefully this helps others if they run into a similar issue!
Link to relevant section poetry docs: https://python-poetry.org/docs/pyproject/#include-and-exclude
Root-cause:
If a VCS is being used for a package, the exclude field will be seeded with the VCS’ ignore settings (.gitignore for git for example).
I'm going to close this issue.
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.
-vvv
option).My pyproject.toml file
```toml [tool.poetry] name = "my_package" version = "0.1.0" description = "My protobuf generated package" authors = ["First LastMy protoc generated directory structure
```bash ➜ tree output/ output/ ├── pyproject.toml └── my_namespace └── my_package └── v1 ├── bar_pb2.py ├── baz_pb2.py └── foo_pb2.py ```Issue
⚠️ Disclaimer: this may very well be an issue with
docker
, notpoetry
⚠️I'm trying to use
poetry
to build and publish a package that consists entirely of source code generated by protocol buffer definitions. I use a docker image that containsbuf
andprotoc
to generate the python source. Theoutput
directory is created by the host. The namespace directory, package directory, and source files are created by the container. The entire project directory, which includes theoutput
directory, is volume mounted to the container.After the
docker run
command, I have the source files described above. I then copy thepyproject.toml
file from above into theoutput
directory. I am then unable to successfully runpoetry build
inside of theoutput
directory.I have made the following observations on both MacOS and Linux Mint...
The sdist archive does not contain the
my_namespace
directory or subdirectories.The wheel build fails entirely with an interesting message that points towards a potential docker-poetry interoperability issue...
MacOS
Linux Mint
If I recursively copy the entire
output
directory the problem goes away.I am no Docker expert, but it seems like
poetry
somehow resolves the directories in question to the host's temporary volume mount paths that should only be visible to the Docker engine. I was surprised to find that the problem exists in both MacOS and Linux.How does
poetry
go about resolving paths during builds? How is it thatpoetry
decided to look in/var/folders
or/tmp
instead of the working directory while building?Thanks in advance and for the work y'all have done to make
poetry
such a fantastic tool 🍻