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

Add automation script to generate completions on release #367

Merged
merged 9 commits into from
Apr 3, 2021

Conversation

frostming
Copy link
Collaborator

@frostming frostming commented Apr 1, 2021

Pull Request Check List

  • A news fragment is added in news/ describing what is new.
  • Test cases added for changed code.

Describe what you have changed in this PR.

@frostming
Copy link
Collaborator Author

frostming commented Apr 1, 2021

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 A-Z a-z,0-9, -, _, . sequence.

How do I handle it?

@Aloxaf
Copy link
Contributor

Aloxaf commented Apr 1, 2021

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-io
Copy link

codecov-io commented Apr 2, 2021

Codecov Report

Merging #367 (b15bbc0) into master (a10f9fe) will increase coverage by 0.02%.
The diff coverage is 92.00%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 82.23% <92.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pdm/cli/options.py 98.21% <ø> (ø)
pdm/cli/commands/completion.py 89.47% <80.00%> (-10.53%) ⬇️
pdm/cli/commands/info.py 93.54% <92.00%> (-6.46%) ⬇️
pdm/cli/actions.py 74.48% <100.00%> (-1.32%) ⬇️
pdm/cli/commands/search.py 64.58% <100.00%> (+1.53%) ⬆️
pdm/cli/utils.py 80.55% <100.00%> (+0.63%) ⬆️
pdm/formats/requirements.py 86.02% <100.00%> (+1.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd95330...b15bbc0. Read the comment docs.

@frostming
Copy link
Collaborator Author

frostming commented Apr 2, 2021

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//,/}})

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. calling python isn't an option as it needs some quirks to find the correct python. But it is ok to depend on 3rd party shell utilities and downgrade to no-completion when they are not installed on the system.

Changed my mind: maybe we can inject some python code into the script and PDM knows the Python interpreter path.

@frostming
Copy link
Collaborator Author

It seems working like a charm! may need another look from @Aloxaf

@@ -1,6 +1,7 @@
#compdef pdm

PDM_PIP_INDEXES=($(command pdm config pypi.url))
PYTHON="%{python_executable}"
Copy link
Contributor

@Aloxaf Aloxaf Apr 2, 2021

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.

@Aloxaf
Copy link
Contributor

Aloxaf commented Apr 2, 2021

The rest LGTM.

@frostming frostming marked this pull request as ready for review April 3, 2021 02:09
@frostming frostming merged commit d245736 into master Apr 3, 2021
@frostming frostming deleted the completion branch April 3, 2021 02:14
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

Successfully merging this pull request may close these issues.

4 participants