Open jfly opened 6 months ago
We do use it in a multiple projects, although with the same input and output path. Take a look here:
https://gitlab.nic.cz/fred/api/messenger (or any other project in the same group)
As for setuptools picking up the generated modules, this may require setting options.packages = find_namespace:
if there are no __init__.py
modules present. I did think about adding generating of __init__.py
to the setuptools-grpc
as well, so you wouldn't have to use namespace packages, but so far no one requested that and we actually benefit from having namespace packages, since we have a top level fred_api
namespace for all APIs in the group.
I agree that it makes sense to add examples
directory with some sample configurations.
Just to be clear, if you would benefit from generating empty __init__.py
files in the output dirs, so that you don't need to use namespace packages, I'm fine with adding that as a feature (probably opt-in, so we don't break people depending on namespace packaging). So far no one requested that and I didn't want to implement it just for the sake of it. But if there is a demand, it should be fairly easy to add.
Thanks for the info. I'm trying to put together an example with different input and output paths, and I can't get it to work. See https://github.com/jfly/setuptools-grpc-demo/tree/broken-different-proto-and-output-paths (in particular this commit message). Also here's a quick demo:
Note how there are no module1_pb2.*
files:
$ pip show -f jfly
Name: jfly
Version: 0.0.1
Summary:
Home-page:
Author:
Author-email:
License:
Location: /home/jeremy/tmp/2024-01-12-pyhack-2/.direnv/python-3.11/lib/python3.11/site-packages
Requires:
Required-by:
Files:
jfly-0.0.1.dist-info/INSTALLER
jfly-0.0.1.dist-info/METADATA
jfly-0.0.1.dist-info/RECORD
jfly-0.0.1.dist-info/REQUESTED
jfly-0.0.1.dist-info/WHEEL
jfly-0.0.1.dist-info/direct_url.json
jfly-0.0.1.dist-info/top_level.txt
Is this possible? From the experimentation I've been doing, it feels to me like the directory structure must be in place before build_grpc
even runs.
So, first thing I see is that you need to add include_package_data = true
to your your setup.cfg
(section options
) and also indicate in MANIFEST.in
that you want to include all proto files (for example with graft src
).
I usually use pyhon -m build
to test the build itself. In this case, the setuptools complain about this:
error: error in 'output_path' option: './out' does not exist or is not a directory
However, this directory actually does exist. I'm not sure why setuptools don't recognize it, but we use Command.ensure_dirname("output_path")
for this check. I'll try to look into it and find out what it is that setuptools ignore this directory.
OK, I get it now. The problem is that out
directory does not contain any python modules and is therefore not included in the sdist befor building the wheel from it. This should fix it:
[options]
packages = find_namespace:
include_package_data = true
[build_grpc]
proto_files = **/*.proto
grpc_files = **/*.proto
proto_path = ./src
output_path = ./out
graft src
graft out
Now, as you said, the directory structure indeed has to be in place at the moment. grpc_tools.protoc
does not create the output dir if not present, but I wonder whether setuptools_grpc
should. It's definitely something to think about.
I've been trying to follow the README, and have run into a couple of issues:
proto_path
andoutput_path
is to ensure that the generated files are included in a built wheel.The one example I've been able to find that uses
setuptools-grpc
is https://github.com/mlcommons/chakra, which chooses to setproto_path
andoutput_path
to the same thing, which is not something I'd have ever expected to do.I think a simple, working example of one correct way of using this tool would go a long way towards clearing up any confusion.