CZ-NIC / setuptools-grpc

Setuptools module for building protobuf and grpc service python modules.
GNU General Public License v3.0
5 stars 1 forks source link

Getting error about no input files although output files are there #5

Closed EricBuist closed 1 year ago

EricBuist commented 1 year ago

Hi, The setuptools-grpc fails to compile protobuf files even for simple projects.

I created a minimal project with a src/proto/test.proto at root.

pyproject.toml:

[project]
name = "sample-project"
version = "1.0.0"
description = "Protobuf stubs"

[build-system]
requires = ['setuptools>=42', "setuptools-grpc"]
build-backend = 'setuptools.build_meta'

[build_grpc]
proto_files = "test.proto"
proto_path = "src/proto"
output_path = "src"

setup.py

from setuptools import setup
from distutils.command.build import build

class CustomBuild(build):
    sub_commands = [
        ('build_grpc', None)
    ] + build.sub_commands

if __name__ == '__main__':
    setup(cmdclass={'build': CustomBuild})

There is no setup.cfg, and as far as I understood, I should not need one; everything should go in the pyproject.toml.

I plan to have a MANIFEST.in file so .proto files get included in the package, but this is irrelevant at this stage since the build fails.

No matter what I try, I'm getting errors when running python -m build.

running build_grpc building protos Missing input file.

What can I do about that? I spent the whole day yesterday trying to figure out a way to create a Python package with both .proto files and the generated .py code, and everything fails. I'm reaching the point the only solution left will be a build.sh script call protoc, then a custom Python script creating the necessary file structures and TGZ and WHL file compatible with PyPI. I really dislike hacking and this is starting to be one of the worst project I worked on, because of how the Python build system is too messy and inconsistent. Why should I need a setup.cfg while up to date documentation of setuptools refers to a pyproject.toml, and if I really need to use setup.cfg, why do I need a pyproject.toml for Python Build to work?

stinovlas commented 1 year ago

Hi! This package provides setuptools command build_grpc. We still use setup.cfg for configuring setuptools, but my guess is the problem is in [build_grpc] header in pyproject.toml. pyproject.toml support is still experimental in setuptools and I'm not sure whether they provide any way to configure custom commands like build_grpc from pyproject.toml. If they do, it will probably be through something like [tool.setuptools.something.build_grpc].

You can either use setup.cfg along with pyproject.toml (this still works) or you can open a discussion in https://github.com/pypa/setuptools and ask about configuring custom setuptools commands in pyproject.toml. The maintainers are usually quite responsive. If you figure out how to do that (if that's even possible at the moment), I'll be happy to add this to README.

stinovlas commented 1 year ago

Sidenote: pyproject.toml is universal configuration that's build backend agnostic. On the other hand, setup.cfg is configuration file specific for setuptools (which is one specific build backend; you could also use flit, hatch and others).

When you use setuptools and build package, you may need to use both, although setuptools authors are trying to make it fully pyproject.toml compatible (although we are not there yet). Some other tools like isort or mypy may also read their configuration from setup.cfg, but they're just piggybacking setuptools configuration file.

stinovlas commented 1 year ago

Closing due to inactivity. If and when setuptools allows commands configuration in pyproject.toml, we can add more examples to the README. For the time being, there's nothing we can do on our side (well, we could read the pyproject.toml ourselves, but that sounds like a bad idea, it's better to use standardized setuptools configuration).