Skip to content

Commit

Permalink
Expand ~ in paths for cmdline_for_next_invocation (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr authored Jul 5, 2024
2 parents 29f7d0e + 780a18f commit a158176
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.12", "pypy3.10"]
python-version: ["3.8", "3.12", "pypy3.10"]
include:
- python-version: 3.7
- python-version: 3.8
coverage: "--cov=rebench"
name: "Ubuntu-latest: Python ${{ matrix.python-version }}"
steps:
Expand Down
6 changes: 5 additions & 1 deletion rebench/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,12 @@ def _keep_alive(seconds):
self.ui.warning(
"Keep alive, current job runs for %dmin\n" % (seconds / 60), run_id, cmdline)

location = run_id.location
if location:
location = os.path.expanduser(location)

(return_code, output, _) = subprocess_timeout.run(
cmdline, env=run_id.env, cwd=run_id.location, stdout=subprocess.PIPE,
cmdline, env=run_id.env, cwd=location, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True, verbose=self.debug,
timeout=run_id.max_invocation_time,
keep_alive_output=_keep_alive,
Expand Down
2 changes: 1 addition & 1 deletion rebench/model/benchmark_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def compile(cls, suite_name, suite, executor, build_commands):
command = suite.get('command')

location = suite.get('location', executor.path)
if location:
if location and not location.startswith('~'):
location = os.path.abspath(location)
build = BuildCommand.create_commands(suite.get('build'), build_commands, location)
benchmarks_config = suite.get('benchmarks')
Expand Down
2 changes: 1 addition & 1 deletion rebench/model/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Executor(object):
@classmethod
def compile(cls, executor_name, executor, run_details, variables, build_commands, action):
path = executor.get('path')
if path:
if path and not path.startswith('~'):
path = os.path.abspath(path)
executable = executor.get('executable')
args = executor.get('args')
Expand Down
10 changes: 9 additions & 1 deletion rebench/model/run_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import os
import re
import shlex

from .benchmark import Benchmark
from .termination_check import TerminationCheck
Expand Down Expand Up @@ -278,7 +280,13 @@ def cmdline(self):

def cmdline_for_next_invocation(self):
"""Replace the invocation number in the command line"""
return self.cmdline() % {'invocation': self.completed_invocations + 1}
cmdline = self.cmdline() % {'invocation': self.completed_invocations + 1}
# split will change the type of quotes, which may cause issues with shell variables
parts = shlex.split(cmdline)
for i, part in enumerate(parts):
parts[i] = os.path.expanduser(part)
cmdline = shlex.join(parts)
return cmdline

def _construct_cmdline(self):
cmdline = ""
Expand Down
15 changes: 15 additions & 0 deletions rebench/tests/model/runs_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from os.path import expanduser
from ...model.data_point import DataPoint
from ...model.measurement import Measurement
from ...model.termination_check import TerminationCheck
Expand Down Expand Up @@ -79,3 +80,17 @@ def test_too_many_fails(self):

check.indicate_failed_execution()
self.assertTrue(check.should_terminate(0, None))

def test_command_user_path_expansion(self):
self._cnf = Configurator(
load_config(self._path + '/small_expand_user.conf'), DataStore(self.ui),
self.ui, None, data_file=self._tmp_file)
runs = self._cnf.get_runs()
sorted_runs = sorted(list(runs), key=lambda r: r.cmdline())
self._run = sorted_runs[0]

expected_cmd = '~/tests/vm1.py 1 Bench ~/suiteFolder/Bench1'.replace('~', expanduser('~'))
self.assertNotIn("~", expected_cmd)
expected_cmd += " -message 'a string with a ~'"
next_invocation_cmdline = self._run.cmdline_for_next_invocation()
self.assertEqual(expected_cmd, next_invocation_cmdline)
32 changes: 32 additions & 0 deletions rebench/tests/small_expand_user.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Config file for ReBench
# Config format is YAML (see http://yaml.org/ for detailed spec)

# this run definition will be chosen if no parameters are given to rebench.py
default_experiment: Test
default_data_file: 'small.data'

# general configuration for runs
runs:
invocations: 10
retries_after_failure: 3

benchmark_suites:
Suite:
gauge_adapter: TestExecutor
command: Bench ~/suiteFolder/%(benchmark)s -message "a string with a ~"
benchmarks:
- Bench1
- Bench2

executors:
TestRunner1:
path: ~/tests
executable: vm1.py %(cores)s
cores: [1]

experiments:
Test:
suites:
- Suite
executions:
- TestRunner1

0 comments on commit a158176

Please sign in to comment.