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

Allows Specifying the Insertion Position of Extra Arguments Supplied to pdm run #1507

Closed
Xdynix opened this issue Nov 10, 2022 · 4 comments · Fixed by #1533
Closed

Allows Specifying the Insertion Position of Extra Arguments Supplied to pdm run #1507

Xdynix opened this issue Nov 10, 2022 · 4 comments · Fixed by #1533
Labels
⭐ enhancement Improvements for existing features

Comments

@Xdynix
Copy link

Xdynix commented Nov 10, 2022

Is your feature request related to a problem? Please describe.

I'm using PDM scripts to both run commands in PDM environment, and also as a shorthand for providing common parameters.

For example, in a Django project, it's common to run commands with manage.py. I will use script like

manage = { cmd = [
    'python', 'manage.py',
] }

So that I can use command pdm manage migrate, instead of pdm run python manage.py migrate. Where the common prefix python manage.py ... can be reused.

However, I found that one of my tools (specifically, pre-commit) has commands and arguments in this format:

pre-commit install --config somewhere/config.yml
pre-commit autoupdate --config somewhere/config.yml
pre-commit run --config somewhere/config.yml

The parameters like --config must come after commands like install. If I create script

pre-commit = { cmd = [
    'pre-commit', '--config', 'somewhere/config.yml',
] }

and execute pdm run pre-commit install, the additional argument install will always be appeneded to the cmd and resulting

pre-commit --config somewhere/config.yml install

which is invalid for pre-commit.

Since the common parts (pre-commit and --config somewhere/config.yml) of the commands are not a prefix, there is no way for me to create shorthand PDM scripts for them.

It would be greate if we can specify the insertion position of extra arguments supplied to pdm run.

Describe the solution you'd like

We can provide an optional placeholder to the cmd. e.g.:

pre-commit = { cmd = [
    'pre-commit', '$args', '--config', 'somewhere/config.yml',
] }
@Xdynix Xdynix added the ⭐ enhancement Improvements for existing features label Nov 10, 2022
@noirbizarre
Copy link
Member

I am interested into this because I might have the same issue with composite commands.

After a lots of thinking, I came to the conclusion that the best approach is the same as tox: https://tox.wiki/en/latest/example/general.html#interactively-passing-positional-arguments

Remains one issue: until now all args are given to the tail of the command by default and while the posargs is helpful, I think we should keep the default behavior if the posargs is not detected in the command (same for composite, if no posarg is given, keep the current pattern apply the posargs to the tail of every command).

Does it seems an acceptable solution/compromise ?

@frostming
Copy link
Collaborator

frostming commented Nov 21, 2022

SGTM, while I prefer the name args @noirbizarre can you help implement it?

@noirbizarre
Copy link
Member

Actually, so do I, so args it will be 👍🏼
I will try to work on this this week.

noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 25, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 25, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 25, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 25, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 25, 2022
@noirbizarre
Copy link
Member

There it is #1533 🚀

noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 25, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 27, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 28, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 28, 2022
noirbizarre added a commit to noirbizarre/pdm that referenced this issue Nov 29, 2022
frostming pushed a commit that referenced this issue Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants