Skip to content
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

mypy-protobuf cannot be used under setup_requires #137

Closed
tarmath opened this issue Jun 22, 2020 · 7 comments
Closed

mypy-protobuf cannot be used under setup_requires #137

tarmath opened this issue Jun 22, 2020 · 7 comments

Comments

@tarmath
Copy link

tarmath commented Jun 22, 2020

I have a small project whose setup.py extends the build command to also generate the python classes from the protobuf definitions. I am generating the stubs with mypy-protobuf at the same time, and now trying to make this happen in the standard fashion, by calling only "python setup.py clean build" and having it handle the build dependency.

while listing mypy-protobuf under the setup_requires downloads mypy-protobuf under an .eggs directory and adds it on the python path, the installed egg is missing the script I could use to call protoc with. It only has the windows .bat file.

ll -R .eggs/mypy_protobuf-1.23-py3.7.egg
total 48
drwxr-xr-x  9 mpichette  staff    288 Jun 22 12:23 EGG-INFO
-rw-r--r--  1 mpichette  staff  24033 Jun 22 12:23 mypy_protobuf.py

.eggs/mypy_protobuf-1.23-py3.7.egg/EGG-INFO:
total 48
-rw-r--r--  1 mpichette  staff  416 Jun 22 12:23 PKG-INFO
-rw-r--r--  1 mpichette  staff  597 Jun 22 12:23 RECORD
-rw-r--r--  1 mpichette  staff   92 Jun 22 12:23 WHEEL
-rw-r--r--  1 mpichette  staff   56 Jun 22 12:23 entry_points.txt
-rw-r--r--  1 mpichette  staff   16 Jun 22 12:23 requires.txt
drwxr-xr-x  3 mpichette  staff   96 Jun 22 13:20 scripts
-rw-r--r--  1 mpichette  staff   14 Jun 22 12:23 top_level.txt

.eggs/mypy_protobuf-1.23-py3.7.egg/EGG-INFO/scripts:
total 8
-rw-r--r--  1 mpichette  staff  48 Jun 22 12:23 protoc_gen_mypy.bat

Could you please also surface the correct plugin to be used in the protoc command line?

Much appreciated!

@nipunn1313
Copy link
Owner

See #102 for a bunch of background context

In our setup.py, we provide

entry_points={"console_scripts": ["protoc-gen-mypy = mypy_protobuf:main"]},
scripts=["protoc_gen_mypy.bat"],

The entry_points describe the script you're looking for (I believe)
There are instructions about it here https://setuptools.readthedocs.io/en/latest/setuptools.html

If you simply install mypy-protobuf (eg pip install mypy-protobuf) - it will install the protoc-gen-mypy somewhere onto your path.

I'm not sure what keeping something under setup_requires does - or where protoc-gen-mypy would get installed. There's some documentation on setup_requires here

I'm open to a strategy that works for you here. Do you have a recommendation?

Potentially helpful documentation
https://setuptools.readthedocs.io/en/latest/setuptools.html
https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html

@tarmath
Copy link
Author

tarmath commented Jun 23, 2020

first of all, thank you for the quick reply!

To be clear, what I'm trying to figure out, is how to allow mypy-protobuf to be used at build time without having previously installed it manually. As installing a package installs its dependencies without someone having to do that manually, I am attempting to make building my package work without having to manually install its build dependencies (as that is a constraint that I have to work with currently).

Though the changes in the PR you pointed out are great, they have definitively removed the possibility for folks to use mypy-protobuf in this fashion. However adding back another small script (not unlike) protoc_gen_mypy.bat may just let me hack my way forward...

@tarmath
Copy link
Author

tarmath commented Jun 23, 2020

As a side note, I realize setup_requires is a deprecated feature, but it is still to my knowledge the only possible way to get this done.

Another alternative I had looked at is using pyproject.toml to add mypy-protobuf as a dependency, as per these peps:

https://www.python.org/dev/peps/pep-0518/
https://www.python.org/dev/peps/pep-0517/

However, setuptools does not use this new "standard", and one cannot only build the package using pip, so this appears to be another a dead-end.

@tarmath
Copy link
Author

tarmath commented Jun 24, 2020

Actually, it looks like I could make it work by simply using the mypy_protobut.py file directly inside the protoc command line:

--plugin=protoc-gen-mypy=[...].eggs/mypy_protobuf-1.23-py3.7.egg/mypy_protobuf.py

However, it requires the file to be executable, but it is not when setuptools extracts it... just a file mode away from a working solution!

@nipunn1313
Copy link
Owner

I'll accept a PR that makes mypy_protobuf.py executable if that'll help you out!

Something about the installation process is supposed to create protoc-gen-mypy - so I'm curious how setuptools' setup_requires handles this

@tarmath
Copy link
Author

tarmath commented Jul 6, 2020

Apologies for not getting back here earlier. Though I feel that I am very close to a solution/conclusion, I have run out of time to investigate this further at the moment. will get back to it in due time...

feel free to close this issue for now if you want to keep things clean, I will simply reopen one referencing it if/when needed...

Thanks for your help with this!

@nipunn1313
Copy link
Owner

hiya - going through these older tasks.

I spent a few minutes trying to repro, but was not able to figure out how to successfully use setup_requires. Does seem like setup.py and the python packaging ecosystem is evolving quickly (incl pyproject.toml). Could not quite figure out how to make a custom packaging build script of the variety you describe.

Do you have a link to the small project you were talking about w/ an example of what the setup.py looks like?

Will close for now. Feel free to reopen with more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants