Closed uwefladrich closed 5 months ago
Note that I at first suspected the way I am starting the ecbundle-create
process from Python to be the problem (i.e. using subprocess.run()
with no further arguments).
However, I tested with a small script:
#!/usr/bin/bash
echo "PWD=${PWD}"
and called it from Python in a subdirectory:
import subprocess
from pathlib import Path
subprocess.run(
[Path("pwdtest.sh").resolve()],
cwd=Path("subdir"),
)
and that works, i.e. $PWD
points to the correct subdirectory.
I also checked if the shell=true
argument to subprocess.run()
made any difference, but it didn't.
Note (mostly to myself): I am guessing that the os.path.expandvars()
call in
https://github.com/ecmwf/ecbundle/blob/814873bf2c770b2693b08181243dd05d110e0c2c/ecbundle/project.py#L26
is responsible for expanding the environment variables in dir: ...
.
It seems that subprocess.Popen()
will not set $PWD
when using cwd=...
: https://github.com/python/cpython/issues/48307 :disappointed:
Since this is not an issue of ecbundle in the first place, I close the issue.
What happened?
When
ecbundle-create
is called from a Python script (as opposed to a shell script or directly on the command line) andbundle.yml
file uses$PWD
indir:
specs, andecbundle-create
, thenthe
dir:
argument in the bundle file is not correctly resolved andecbundle-create
fails withThis does not happen when
ecbundle-create
is called from a Shell script.What are the steps to reproduce the bug?
A minimal setup of files looks like this:
Where
ecbundle-create.py
andecbundle-create.sh
are the scripts I am testing,subdir/bundle.yml
is the bundle file using the$PWD
references, andsubdir/external/ecbuild
contains a clonedecbuild
repository. It is not really important to useecbuild
, any other project would do.The bundle file is minimal:
Now, from within
minimal-example
, I can run theecbundle-create.sh
script:and everything works fine. The complete bundle is created in
subdir/source/
and all links are correctly set.However, running a Python script with (arguably) the same functionality:
results in
(common path prefixes replaced by "
...
" for readability)It can be seen that
ecbundle-create
looks for theecbuild
code inminimal-example/external/
, not inminimal-example/subdir/external/
, as it should.Version
2.1.1
Platform (OS and architecture)
Red Hat Enterprise Linux 9.3 (Plow)
Relevant log output
No response
Accompanying data
No response
Organisation
SMHI/EC-Earth