Skip to content

Commit 953827a

Browse files
committed
added pydra module path to the sys path in run_pickled to avoid import issues when running tests from inside the namespace package
1 parent 5686862 commit 953827a

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

docker-scripts-for-tests/start-docker-slurm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NO_ET=TRUE
77
docker pull $DOCKER_IMAGE
88

99
# Start image
10-
docker run -itd -h slurmctl --cap-add sys_admin -d --name slurm -v $PKG_DIR:/pydra -e NO_ET=$NO_ET $DOCKER_IMAGE
10+
docker run --rm -itd -h slurmctl --cap-add sys_admin -d --name slurm -v $PKG_DIR:/pydra -e NO_ET=$NO_ET $DOCKER_IMAGE
1111

1212
# Display previous jobs with sacct
1313
echo "Allowing ports/daemons time to start" && sleep 10

pydra/engine/run_pickled.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import pickle
1+
import cloudpickle as cp
22
import sys
3+
from pathlib import Path
34
from pydra.engine.helpers import load_and_run
45

6+
# To avoid issues when running pytest, where the namespace package "pydra" is dropped in
7+
# the pickling process due to it being run from inside the source tree
8+
sys.path.append(str(Path(__file__).parent.parent))
9+
510

611
def run_pickled(*file_paths, rerun=False):
712
loaded_objects = []
813

914
for file_path in file_paths:
1015
with open(file_path, "rb") as file:
11-
loaded_objects.append(pickle.load(file))
16+
loaded_objects.append(cp.load(file))
1217

1318
if len(loaded_objects) == 1:
1419
result = loaded_objects[0](rerun=rerun)

pydra/engine/tests/test_submitter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
import pytest
1111
from pydra.design import workflow
1212
from fileformats.generic import Directory
13+
from pydra.engine.core import Task
14+
from pydra.engine.submitter import Submitter
15+
from pydra.engine.workers import DebugWorker
16+
from pydra.design import python
17+
from pathlib import Path
18+
from datetime import datetime
19+
from pydra.engine.specs import Result
1320
from .utils import (
1421
need_sge,
1522
need_slurm,
1623
BasicWorkflow,
1724
BasicWorkflowWithThreadCount,
1825
BasicWorkflowWithThreadCountConcurrent,
1926
)
20-
from ..core import Task
21-
from ..submitter import Submitter
22-
from ..workers import DebugWorker
23-
from pydra.design import python
24-
from pathlib import Path
25-
from datetime import datetime
26-
from pydra.engine.specs import Result
2727

2828

2929
@python.define

pydra/engine/workers.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,16 +974,13 @@ async def run(
974974
-------
975975
None
976976
"""
977-
import pickle
978-
from pathlib import Path
979-
980977
jex = self.psij.JobExecutor.get_instance(self.subtype)
981978
absolute_path = Path(__file__).parent
982979

983980
cache_dir = task.cache_dir
984981
file_path = cache_dir / "runnable_function.pkl"
985982
with open(file_path, "wb") as file:
986-
pickle.dump(task.run, file)
983+
cp.dump(task.run, file)
987984
func_path = absolute_path / "run_pickled.py"
988985
spec = self.make_spec("python", [func_path, file_path])
989986

0 commit comments

Comments
 (0)