Giter VIP home page Giter VIP logo

setuptools-protobuf's Introduction

protobuf support for setuptools

Plugin for setuptools that adds support for compiling protobuf files.

Dependencies

The plugin requires the external protoc executable that is part of the protobuf project to be present. On Debian systems, this executable is shipped in the protobuf-compiler package.

If the protoc_version option is specified, the specified version of protoc will be downloaded from github. When it is not specified, a protoc binary is expected to be present in the environment. You can override the binary with the PROTOC environment variable.

Optionally, it can also generate typing hints if the mypy extra is selected.

There is no separate install_proto command; generated files (e.g. _pb2.py files) are placed in the source tree and expected to be installed by other install commands.

Usage

You can configure setuptools-protobuf in either setup.py, setup.cfg or pyproject.toml.

setup.py

from setuptools_protobuf import Protobuf

setup(
...
    setup_requires=['setuptools-protobuf'],
    protobufs=[Protobuf('example/foo.proto')],
)

setup.cfg

...

[options]
setup_requires =
    setuptools
    setuptools-protobuf

pyproject.toml

[build-system]
requires = ["setuptools", "setuptools-protobuf"]

[tool.setuptools-protobuf]
protobufs = ["example/foo.proto"]

# Require the generation of typing hints:
mypy = true

# Optionally, set the specific protoc version to use:
protoc_version = '25.1'

GitHub actions

To install protoc in a GitHub action, you can use the setup-protoc action:

- name: Install Protoc
  uses: arduino/setup-protoc@v2

setuptools-protobuf's People

Contributors

dependabot[bot] avatar jelmer avatar sassy-asjp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

setuptools-protobuf's Issues

Add feature to download protoc version

It would be nice to specify a version of protoc to use and have it just be downloaded automatically, instead of having to have the user of the sdist make sure to download, install, and configure PROTOC environment variable.

Tag release

Hello. Could you tag a new release? I'd like to be able to use the protoc download feature without having to specify the build dependency from the github url or mess around with hosting it on an internal pypi index.

How to configure in pyproject.toml?

From reading the source code of this project, it seems that it wants an instance of the Protobuf class (also defined by this project) as a configuration item. How do I define that when I'm using pyproject.toml instead of setup.py or setup.cfg?

Questions about proper usage of setuptools-protobuf

Hello!
I am working on a nice protobuf build process in my project and bumped into your project, which looks very promising.
The problem is, I am new to all this PEP-517 stuff and I can't figure out how I can do several things and can I do it at all:

  1. I need to include builded proto into sdist, but as far I can see, you are injecting into "build" subcommands, so am I understanding correctly that I need to inject something somewhere myself?
  2. I want to build proto while editable installation too.
  3. I need to figure out my protobufs list dynamically, and maybe even move protobuf files into my project tree while building process.
  4. And I can't figure out what I need to write in my pyproject.toml to start using setuptools-protobuf.

I would very much appreciate your consultation, thanks in advance!

SetuptoolsDeprecationWarning: Direct usage of `distutils` commands

When I run python3 setup.py build on a project using setuptools-protobuf, I get this warning now:

running build
/usr/lib/python3/dist-packages/setuptools/_distutils/command/build.py:130: SetuptoolsDeprecationWarning: Direct usage of `distutils` commands
!!

        ********************************************************************************
        It seems that you are using `distutils.command.build` to add
        new subcommands. Using `distutils` directly is considered deprecated,
        please use `setuptools.command.build`.

        By 2023-Dec-13, you need to update your project and remove deprecated calls
        or your builds will no longer be supported.

        See https://peps.python.org/pep-0632/ for details.
        ********************************************************************************

!!
  for cmd_name in self.get_sub_commands():
running build_protobuf
running build_py

Relevant versions of the Debian packages:

python3-setuptools 68.1.2-1
python3-setuptools-protobuf 0.1.9-1

Support wildcards in protobufs

Hey @jelmer,
Thanks for the awesome project!

Is it possible to change the source to specify the path for the protobuf files using wildcards? Or even better, if the protobufs configuration is not specified, it automatically searches for all .proto files inside the project?

Best regards,

  • Jorge Pereira

AttributeError: 'Distribution' object has no attribute 'protoc_version'

My build just started failing with the error below. From a glance at https://github.com/jelmer/setuptools-protobuf/pull/25/files it looks like protoc_version is set in load_pyproject_config, but I'm configuring setuptools-protobuf with setup.py instead of pyproject.toml.

       Traceback (most recent call last):
        File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 18, in <module>
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 321, in run
          self.find_sources()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 329, in find_sources
          mm.run()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 551, in run
          self.add_defaults()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 589, in add_defaults
          sdist.add_defaults(self)
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/sdist.py", line 113, in add_defaults
          self._add_defaults_build_sub_commands()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/sdist.py", line 133, in _add_defaults_build_sub_commands
          self.filelist.extend(chain.from_iterable(files))
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 494, in extend
          self.files.extend(filter(self._safe_path, paths))
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/sdist.py", line 132, in <genexpr>
          files = (c.get_source_files() for c in cmds if hasattr(c, "get_source_files"))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/command/sdist.py", line 131, in <genexpr>
          cmds = (self.get_finalized_command(c) for c in missing_cmds)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 304, in get_finalized_command
          cmd_obj = self.distribution.get_command_obj(command, create)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 861, in get_command_obj
 cmd_obj = self.command_obj[command] = klass(self)
                                                ^^^^^^^^^^^
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/__init__.py", line 174, in __init__
          super().__init__(dist)
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 66, in __init__
          self.initialize_options()
        File "/tmp/pip-build-env-bwn4ne78/overlay/lib/python3.11/site-packages/setuptools_protobuf/__init__.py", line 26, in initialize_options
          or get_protoc(getattr(self.distribution, 'protoc_version'))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: 'Distribution' object has no attribute 'protoc_version'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.