-
Notifications
You must be signed in to change notification settings - Fork 35
Add setuptools entry point #156
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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__:main
have usedshtab
: Afterinstalling this package, users use
requirements-language-server --print-completion XXsh
can 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.shtab
to build requires:pyproject.toml
:tool.setuptools.data-files
to make them are packaged to python wheel.pyproject.toml
:That's all.
Then
pip install --user dist/requirements_language_server-*-py3-none-any.whl
will 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_server
Or 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_server
bash-completion and
zsh
will search completion scripts in these directories.Pro:
Con:
requirements_language_server.__main__:main
must sourcerequirements_language_server/__main__.py
. Ifrequirements_language_server/__main__.py
orrequirements_language_server/__init__.py
has aimport XXX
butXXX
is not declared in. Perhaps we should disable this feature by default, only enable it when user addenable-setuptools-entry-point = true
inpyproject.toml
?import XXX
will 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).