I wrote a nice self-containing python in the cwl. How can I include python’s pip requirements: “pip install” before running the script?
I want to keep everything in one script, see below.
Thank you for your help.
baseCommand: ["python", "convert.py"]
- entryname: convert.py
import numpy as np
data = np.loadtxt('$(inputs.in_file.path)')
with open('$(inputs.out_file)','w') as fOut:
fOut.write("Sum is: "+str(np.sum(data)))
If your CWL runner support it, then you could add a
For example, with the CWL reference runner: GitHub - common-workflow-language/cwltool: Common Workflow Language reference implementation you can add the
--beta-conda-dependencies flag. If the libraries you need are in PyPI only (or if you prefer PyPI over the Conda registry) then that feature could be extended for a
--beta-pip-dependencies flag in the future.
The other option is to add a
DockerRequirement either pointing to an image with the dependencies installed, or a
dockerFile with an inline recipe using the packages you need.
Sorry I did not post my solution:
- baseCommand: ["sh","script.sh"]
- entryname: script.sh
pip3 install -r requirements.txt
and similarly I add requirements.txt and the python-script as initialWorkDirRequirement.
@mrc Thank you for your suggestion:
- I am on the PyPi train
- I want to have the cwl applicable for all runners
I don’t know of an image that would fit and I am not too much into docker-recipes that I know how to solve it that way. I am a scipt-kid who hopes the sh-commands does work.
For readers looking for a solution with conda (mamba/micromamba):
- entryname: environment.yaml
- entryname: run.sh
micromamba create -q -f environment.yaml
rm -fr run.sh environment.yaml stac.py
- entryname: stac.py
baseCommand: ["/bin/sh", "run.sh"]