Add setuptools entry point#156
Add setuptools entry point#156Freed-Wu wants to merge 2 commits intoiterative:mainfrom Freed-Wu:main
Conversation
There was a problem hiding this comment.
My biggest concern is:
[tool.setuptools.data-files]
"share/bash-completion/completions" = ["..."]afaik this is discouraged by @pypa - related to #122 (comment)
| os.makedirs("sdist", exist_ok=True) | ||
| argv = sys.argv | ||
| for shell, filename in shells.items(): | ||
| sys.argv = [prog, "--print-completion", shell] |
There was a problem hiding this comment.
not all programs use this. It may be e.g.:
| sys.argv = [prog, "--print-completion", shell] | |
| sys.argv = [prog, "complete", shell] |
There was a problem hiding this comment.
Yes, It's a fast dirty trial 😄 How can we get the command option about print completion or get the completion content directly from python?
|
It's not encouraged because if one package want to attach some files, install them in |
|
What is your opinion about this dirty trial? 😄 |
|
pull[bot] definitely did something wrong. |
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #156 +/- ##
===========================================
- Coverage 88.88% 76.00% -12.88%
===========================================
Files 3 4 +1
Lines 360 421 +61
===========================================
Hits 320 320
- Misses 40 101 +61 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This is a dirty experimental trial. It may not satisfy code style, etc.
I want to use this branch to demo and discuss the issue about can we add a setuptool entry point to generate shell completion scripts during building python package not after installing python package.
An example project is https://github.com/Freed-Wu/requirements-language-server/tree/fbc2a773d3c4de7bf442fd5096f7916592717e27.
It has a script:
pyproject.toml:requirements_language_server.__main__:mainhave usedshtab: Afterinstalling this package, users use
requirements-language-server --print-completion XXshcan generate completion scripts forXXsh. Then users can move these scripts to correct path to make them work.I hope an out-of-box experiences. That is during building package, shell
completion scripts will be generated (we assume they are generated in
sdist/) and packaged to python wheel. Users install the compiled wheel will get them to be installed in correct paths.shtabto build requires:pyproject.toml:tool.setuptools.data-filesto make them are packaged to python wheel.pyproject.toml:That's all.
Then
pip install --user dist/requirements_language_server-*-py3-none-any.whlwill get:~/.local/lib/python3.10/site-packages/requirements_language_server~/.local/share/bash-completion/completions/requirements_language_server~/.local/share/zsh/site-functions/_requirements_language_serverOr without
--user:/usr/lib/python3.10/site-packages/requirements_language_server/usr/share/bash-completion/completions/requirements_language_server/usr/share/zsh/site-functions/_requirements_language_serverbash-completion and
zshwill search completion scripts in these directories.Pro:
Con:
requirements_language_server.__main__:mainmust sourcerequirements_language_server/__main__.py. Ifrequirements_language_server/__main__.pyorrequirements_language_server/__init__.pyhas aimport XXXbutXXXis not declared in. Perhaps we should disable this feature by default, only enable it when user addenable-setuptools-entry-point = trueinpyproject.toml?import XXXwill fail.It's only my 2c. I just throw a bad thought to attract good ideas. 😄
PS: In fact, this thought is the continuation of the thought huggingface/huggingface_hub#1207 (comment).