-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
Add automation script to generate completions on release #367
Conversation
Hi, @Aloxaf , I updated the zsh script according to PEP 621 and latest CLI. But I have trouble extracting the pdm packages. It seems it is not easy to do it with pure pattern matching, unless we actually parse the TOML document. Concretely, the following formats are legal: # All in one line
dependencies = ["requests", "click==7.0"]
# Each at its own line
dependencies = [
"requests",
"click==7.0"
]
# Or hybrid
dependencies = [
"requests", "requests-toolbelt",
"click", "click-completion"
] For package names, we can take the running How do I handle it? |
Oh, I haven't noticed that the format has changed. I think the best way is to call python: packages=($(command python -c 'import toml; d=toml.load("pyproject.toml"); print(*d["project"]["dependencies"])')) Or with pure zsh?: setopt local_options re_match_pcre
[[ $(<pyproject.toml) =~ 'dependencies *= *\[((.|\n)*?)\]' ]]
packages=(${=${(Q)match//,/}}) |
Codecov Report
@@ Coverage Diff @@
## master #367 +/- ##
==========================================
+ Coverage 82.28% 82.30% +0.02%
==========================================
Files 63 63
Lines 5165 5183 +18
Branches 929 933 +4
==========================================
+ Hits 4250 4266 +16
- Misses 644 645 +1
- Partials 271 272 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Great, that helps. then how to catch all the matches: dependencies = [ ]
[project.optional-dependenceis]
extra1 = [ ]
extra2 = [ ]
extra3 = [ ] Each array contains several dependencies. I wonder if it can be done by pure zsh. Changed my mind: maybe we can inject some python code into the script and PDM knows the Python interpreter path. |
It seems working like a charm! may need another look from @Aloxaf |
pdm/cli/completions/pdm.zsh
Outdated
@@ -1,6 +1,7 @@ | |||
#compdef pdm | |||
|
|||
PDM_PIP_INDEXES=($(command pdm config pypi.url)) | |||
PYTHON="%{python_executable}" |
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.
As a global variable, PYTHON
is a too common name. Users may use this name for their own plugin.
I suggest something like PDM_PYTHON
so that it won't be accidentally overridden/accessed by other scripts.
The rest LGTM. |
Pull Request Check List
news/
describing what is new.Describe what you have changed in this PR.