Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding environment variables in the command part of a dvc run

Tags:

dvc

Summary: I am trying to define a dvc step using dvc-run where the command depends on some environment variables (for instance $HOME). The problem is that when I'm defining the step on machine A, then the variable is expanded when stored in the .dvc file. In this case, it won't be possible to reproduce the step on machine B. Did I hit a limitation of dvc? If that's not the case, what's the right approach?

More details: I faced the issue when trying to define a step for which the command is a docker run. Say that:

  • on machine A myrepo is located at /Users/user/myrepo and
  • on machine B it is to be found at /home/ubuntu/myrepo.

Furthermore, assume I have a script myrepo/script.R which processes a data file to be found at myrepo/data/mydata.txt. Lastly, assume that my step's command is something like:

docker run -v $HOME/myrepo/:/prj/ my_docker_image /prj/script.R /prj/data/mydata.txt

If I'm running dvc run -f step.dvc -d ... -d ... [cmd] where cmd is the docker execution above, then in step.dvc the environment variable $HOME will be expanded. In this case, the step will be broken on machine B.

like image 593
Dror Avatar asked Oct 29 '25 16:10

Dror


1 Answers

From docs:

Use single quotes ' instead of " to wrap the command if there are environment variables in it, that you want to be evaluated dynamically. E.g. dvc run -d script.sh './myscript.sh $MYENVVAR'

like image 141
Ruslan Kuprieiev Avatar answered Nov 01 '25 06:11

Ruslan Kuprieiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!