pipenv icon indicating copy to clipboard operation
pipenv copied to clipboard

How to combine multiple command in one script ?

Open meteorlxy opened this issue 7 years ago • 11 comments

In the scripts field of Pipfile, we can define some scripts and run them by pipenv run <script-name>.

How to combine multiple commands in one script? It seems that the common commands separator (like &&) does not work.

E.g.

[scripts]
test = "python --version && python --help"

After pipenv run test, only the python --version runs, and the && python --help seems to be treated as args.

In addition, commands in array could be better, but seems not available now:

[scripts]
test = [
  "python --version",
  "python --help"
]

meteorlxy avatar May 31 '18 08:05 meteorlxy

I’d recommend using a “real” task manager for this kind of usage. PyInvoke is a good tool for this.

uranusjr avatar May 31 '18 08:05 uranusjr

@uranusjr

When developing js projects, the scripts field in package.json is widely used for this, and we don't need something like PyInvoke to handle such simple use cases.

As my project has both js and py code, currently I'm using yarn run to combine multiple pipenv run 😅 ....

I love the idea of pipenv, and I hope pipenv could be as good as yarn in node 😄

meteorlxy avatar May 31 '18 08:05 meteorlxy

@meteorlxy How about combining the commands you want to run in a shell script, and invoking that from the 'scripts' section?

bjarchi avatar May 31 '18 20:05 bjarchi

The example supplied is simple, and @uranusjr has done most of the pipenv-related rewrite of our command module, but I suspect people's use cases would get significantly more complex and expectations would rise very quickly. I am pretty leery about adding these kinds of features because we just don't have the manpower to support them at the moment. When things like this break, they break spectacularly and are quite difficult to untangle

techalchemy avatar Jun 03 '18 21:06 techalchemy

I'll mark it as a discussion point because the example is simple and if it really is just 'do this list of things instead of just one thing', I don't see any real barriers. But if it gets more complex...

techalchemy avatar Jun 03 '18 21:06 techalchemy

The list-based syntax is reasonable for me, but I fear we might be opening a floodgate here. I would seriously encourage people to try a “real” task runner. I mean, GNU make is pretty awesome.

I do have some scripts + Pyinvoke integration design in mind, but am too lazy to write a full proposal… Feel free to contact me if you care about this.


Edit: I want to mention that the approach of Yarn (and NPM) is not exactly, well, optimal. As a Windows user, I’ve seen more than my fair share of those NPM “scripts” that just fails to work on Windows. I would very much like to avoid this kind of design.

uranusjr avatar Jun 04 '18 07:06 uranusjr

@uranusjr I think copying the behavior of tox commands would work for most people

graingert avatar Oct 10 '18 11:10 graingert

I'm also having this problem. For example,

[scripts]
chenv = [
    "git update-index --no-assume-unchanged .env",
    "git add -f .env",
    "git commit -m 'updated the .env file'",
    "git update-index --assume-unchanged .env"
]

Which would be used as:

# removed local envs
pipenv run chenv # to update the .env file version which only the global envs

Unfortunately, the && symbol is not working.

adrianohrl avatar Feb 12 '20 21:02 adrianohrl

Just sharing my workaround until we have a builtin solution: && and || are not processed correctly, but this is working if wrapped into sh -c "".

As example, to call all linters

lint = """sh -c "
    isort --check mypackage \
    && black --check mypackage \
    && flake8 mypackage \
    && mypy mypackage \
"
"""

A bit ugly but at least it's working.

noirbizarre avatar May 27 '22 14:05 noirbizarre

I use powershell for pipenv history And this perfectly works for me! We have to use semicolon ; for multiple commands

in one line

all = """PowerShell.exe -Command "python manage.py makemigrations; python manage.py migrate; python manage.py runserver" """

in multiple lines

all = """PowerShell.exe -Command "
python manage.py makemigrations; \
python manage.py migrate; \
python manage.py runserver\
"
"""

if you use bash, then use @noirbizarre code! elif you use cmd, then use cmd.exe /C instead of PowerShell.exe -Command

Thank you!!

son1473 avatar Apr 15 '23 09:04 son1473