Skip to content

Commit 15dbb6c

Browse files
authored
Merge pull request #90 from daavid00/dev
Fixing observed timeout during JOSS review
2 parents ddabdfe + 081c0cb commit 15dbb6c

3 files changed

Lines changed: 70 additions & 57 deletions

File tree

.github/workflows/ci_pycopm_ubuntu.yml

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,43 @@ on:
99
jobs:
1010
run-pycopm-local:
1111
timeout-minutes: 30
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-24.04
13+
container:
14+
image: ubuntu:26.04
1315

1416
steps:
15-
- uses: actions/checkout@v2
16-
with:
17-
fetch-depth: 0
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
1819

19-
- name: Set up Python 3.12
20-
uses: actions/setup-python@v2
21-
with:
22-
python-version: 3.12
20+
- name: Install system dependencies
21+
run: |
22+
apt-get update
23+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
24+
python3 python3-pip python3-venv \
25+
build-essential git curl ca-certificates \
26+
software-properties-common \
27+
octave \
28+
mpi-default-bin \
29+
freeglut3-dev \
30+
libhdf5-dev
31+
32+
ln -s /usr/bin/python3 /usr/bin/python || true
2333
2434
- name: Install Flow Simulator
2535
run: |
26-
sudo apt-get update
27-
sudo apt-get install software-properties-common
28-
sudo apt-add-repository ppa:opm/ppa
29-
sudo apt-get update
30-
sudo apt-get install mpi-default-bin
31-
sudo apt-get install libopm-simulators-bin
36+
apt-get update
37+
apt-add-repository ppa:opm/ppa
38+
apt-get update
39+
DEBIAN_FRONTEND=noninteractive apt-get install -y libopm-simulators-bin
3240
33-
- name: Install ert dependency
34-
run: |
35-
sudo apt-get install freeglut3-dev
36-
37-
- name: Install dependecies
41+
- name: Install python requirements
3842
run: |
43+
python3 -m venv vpycopm
44+
. vpycopm/bin/activate
45+
echo "$PWD/vpycopm/bin" >> $GITHUB_PATH
3946
pip install --upgrade pip setuptools wheel
40-
pip install -r dev-requirements.txt
41-
42-
- name: Install pycopm
43-
run: |
4447
pip install -e .
48+
pip install -r dev-requirements.txt
4549
4650
- name: Check code style and linting
4751
run: |
@@ -59,8 +63,8 @@ jobs:
5963
6064
- name: Check if hello world example succeded
6165
run: |
62-
file="/home/runner/work/pycopm/pycopm/output/HELLO_WORLD_PYCOPM.EGRID"
63-
if [[ -f "$file" ]]; then
66+
file="output/HELLO_WORLD_PYCOPM.EGRID"
67+
if [ -f "$file" ]; then
6468
echo "pycopm succeeded"
6569
else
6670
echo "pycopm failed"
@@ -69,5 +73,5 @@ jobs:
6973
7074
- name: Build documentation
7175
run: |
72-
pushd docs
76+
cd docs
7377
make html

src/pycopm/core/pycopm.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import time
99
import sys
10+
import shlex
1011
import argparse
1112
from io import StringIO
1213
import subprocess
@@ -396,20 +397,23 @@ def check_cmdargs(cmdargs):
396397
)
397398
sys.exit()
398399
if (cmdargs["input"].strip()).endswith(".DATA"):
399-
if (
400-
subprocess.call(
401-
cmdargs["flow"].strip(),
402-
shell=True,
403-
stdout=subprocess.DEVNULL,
404-
stderr=subprocess.STDOUT,
405-
)
406-
!= 1
407-
):
400+
cmd = shlex.split(cmdargs["flow"].strip()) + ["-h"]
401+
try:
402+
if (
403+
subprocess.run(
404+
cmd,
405+
stdout=subprocess.DEVNULL,
406+
stderr=subprocess.STDOUT,
407+
check=False,
408+
).returncode
409+
!= 0
410+
):
411+
raise RuntimeError
412+
except (FileNotFoundError, RuntimeError):
408413
print(
409-
f"\nThe OPM flow executable '-f {cmdargs['flow'].strip()}' is not found, "
410-
f"try to install it following the information in the documentation.\n"
414+
f"\nThe OPM flow executable '-f {' '.join(cmd)}' is not available or not working.\n"
411415
)
412-
sys.exit()
416+
sys.exit(1)
413417
for option, flag in zip(["how", "nhow"], ["-a", "-n"]):
414418
if cmdargs[option].strip() not in ["min", "max", "mode"]:
415419
print(

src/pycopm/utils/input_values.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import csv
99
import sys
1010
import tomllib
11+
import shlex
1112
import subprocess
1213
from itertools import islice
1314
import numpy as np
@@ -64,19 +65,22 @@ def check_flow(dic, in_file):
6465
"See the pycopm documentation.\n"
6566
)
6667
sys.exit()
67-
flowtoml = subprocess.call(
68-
dic["flowpth"].strip(),
69-
shell=True,
70-
stderr=subprocess.STDOUT,
71-
stdout=subprocess.DEVNULL,
72-
)
73-
flowflag = subprocess.call(
74-
dic["flowflag"],
75-
shell=True,
76-
stderr=subprocess.STDOUT,
77-
stdout=subprocess.DEVNULL,
78-
)
79-
if flowtoml != 1 and flowflag != 1:
68+
69+
cmd1 = shlex.split(dic["flowpth"].strip()) + ["-h"]
70+
cmd2 = shlex.split(dic["flowflag"]) + ["-h"]
71+
72+
def run(cmd):
73+
try:
74+
return subprocess.run(
75+
cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False
76+
).returncode
77+
except FileNotFoundError:
78+
return None
79+
80+
flowtoml = run(cmd1)
81+
flowflag = run(cmd2)
82+
83+
if not (flowtoml == 0 or flowflag == 0):
8084
print(
8185
f"\nThe OPM flow executable '{dic['flowpth'].strip()}' is not found; "
8286
"try to install it following the pycopm documentation.\nIf it was "
@@ -85,14 +89,15 @@ def check_flow(dic, in_file):
8589
"(e.g., flow = '/home/pycopm/build/opm-simulators/bin/flow'),\n"
8690
"or using the command flag -f or --flow.\n"
8791
)
88-
sys.exit()
89-
if flowtoml != 1:
90-
dic["flow"] = dic["flow"].split()
91-
for i, value in enumerate(dic["flow"]):
92+
sys.exit(1)
93+
94+
if flowtoml == 0:
95+
parts = shlex.split(dic["flow"])
96+
for i, value in enumerate(parts):
9297
if "flow" in value:
93-
dic["flow"][i] = dic["flowflag"]
98+
parts[i] = dic["flowflag"]
9499
break
95-
dic["flow"] = " ".join(dic["flow"])
100+
dic["flow"] = " ".join(parts)
96101

97102

98103
def read_reference(dic):

0 commit comments

Comments
 (0)