What it the "correct" way to write a setuptools plugin that generates python source files for a wheel? #3180
-
I'm working on implementing a The following it the debug output of using my POC attempting to add a simple $ DISTUTILS_DEBUG=1 python setup.py bdist_wheel
options (after parsing config files):
options (after parsing command line):
option dict for 'aliases' command:
{}
option dict for 'bdist_wheel' command:
{}
running bdist_wheel
Distribution.get_command_obj(): creating 'bdist_wheel' command object
Distribution.get_command_obj(): creating 'bdist' command object
Distribution.get_command_obj(): creating 'build' command object
Distribution.get_command_obj(): creating 'build_scripts' command object
Distribution.get_command_obj(): creating 'build_ext' command object
running build
running build_py
Distribution.get_command_obj(): creating 'build_py' command object
creating build
creating build/lib
creating build/lib/my_module
copying my_module/__init__.py -> build/lib/my_module
copying my_module/bar.py -> build/lib/my_module
Distribution.get_command_obj(): creating 'install' command object
Distribution.get_command_obj(): creating 'install_scripts' command object
installing to build/bdist.linux-x86_64/wheel
running install
config vars:
{'abiflags': '',
'base': '/home/patrick/.pyenv/versions/grpc-test-venv',
'dist_fullname': 'test-package-setuptools-hook-0.0.1',
'dist_name': 'test-package-setuptools-hook',
'dist_version': '0.0.1',
'exec_prefix': '/home/patrick/.pyenv/versions/grpc-test-venv',
'platbase': '/home/patrick/.pyenv/versions/grpc-test-venv',
'platlibdir': 'lib',
'prefix': '/home/patrick/.pyenv/versions/grpc-test-venv',
'py_version': '3.9.10',
'py_version_nodot': '39',
'py_version_short': '3.9',
'sys_exec_prefix': '/home/patrick/.pyenv/versions/grpc-test-venv',
'sys_prefix': '/home/patrick/.pyenv/versions/grpc-test-venv',
'userbase': '/home/patrick/.local',
'usersite': '/home/patrick/.local/lib/python3.9/site-packages'}
running install_lib
Distribution.get_command_obj(): creating 'install_lib' command object
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/my_module
copying build/lib/my_module/__init__.py -> build/bdist.linux-x86_64/wheel/my_module
copying build/lib/my_module/bar.py -> build/bdist.linux-x86_64/wheel/my_module
running install_egg_info
Distribution.get_command_obj(): creating 'install_egg_info' command object
Distribution.get_command_obj(): creating 'egg_info' command object
running egg_info
creating test_package_setuptools_hook.egg-info
writing test_package_setuptools_hook.egg-info/PKG-INFO
writing dependency_links to test_package_setuptools_hook.egg-info/dependency_links.txt
writing top-level names to test_package_setuptools_hook.egg-info/top_level.txt
writing manifest file 'test_package_setuptools_hook.egg-info/SOURCES.txt'
------
POC: Generating a Python file
my_module/foo.py
------
exclude_pattern: applying regex r'(^|/)(RCS|CVS|\.svn)/'
writing manifest file 'test_package_setuptools_hook.egg-info/SOURCES.txt'
Copying test_package_setuptools_hook.egg-info to build/bdist.linux-x86_64/wheel/test_package_setuptools_hook-0.0.1-py3.9.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/test_package_setuptools_hook-0.0.1.dist-info/WHEEL
creating 'dist/test_package_setuptools_hook-0.0.1-py3-none-any.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'my_module/__init__.py'
adding 'my_module/bar.py'
adding 'test_package_setuptools_hook-0.0.1.dist-info/METADATA'
adding 'test_package_setuptools_hook-0.0.1.dist-info/WHEEL'
adding 'test_package_setuptools_hook-0.0.1.dist-info/top_level.txt'
adding 'test_package_setuptools_hook-0.0.1.dist-info/RECORD'
removing build/bdist.linux-x86_64/wheel
$ unzip -l dist/test_package_setuptools_hook-0.0.1-py3-none-any.whl
Archive: dist/test_package_setuptools_hook-0.0.1-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
0 2022-03-19 13:34 my_module/__init__.py
21 2022-03-19 13:02 my_module/bar.py
183 2022-03-19 16:09 test_package_setuptools_hook-0.0.1.dist-info/METADATA
92 2022-03-19 16:09 test_package_setuptools_hook-0.0.1.dist-info/WHEEL
10 2022-03-19 16:09 test_package_setuptools_hook-0.0.1.dist-info/top_level.txt
527 2022-03-19 16:09 test_package_setuptools_hook-0.0.1.dist-info/RECORD
--------- -------
833 6 files I did some digging in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hi @plannigan there is some (very little) documentation about this entry-point in https://setuptools.pypa.io/en/latest/userguide/extension.html#customizing-distribution-options. It is a very generic and very powerful hook. You need to write a function that accepts a Just note that this hook is called very early when no configuration file was read yet... Have you considered instead adding a new sub-command to |
Beta Was this translation helpful? Give feedback.
-
Please note the way setuptools currently is supposed to work:
|
Beta Was this translation helpful? Give feedback.
Hi @plannigan there is some (very little) documentation about this entry-point in https://setuptools.pypa.io/en/latest/userguide/extension.html#customizing-distribution-options.
It is a very generic and very powerful hook. You need to write a function that accepts a
Distribution
object and can modify it arbitrarily.Just note that this hook is called very early when no configuration file was read yet...
Have you considered instead adding a new sub-command to
build
? There is some discussion/examples in #2591.