Skip to content

Commit

Permalink
Fix usage of tempfile.mkdir
Browse files Browse the repository at this point in the history
Changed in Python version 3.12: mkdtemp() now always returns an absolute path,
even if dir is relative.

Signed-off-by: Antonin Bas <antonin.bas@gmail.com>
  • Loading branch information
antoninbas committed Nov 10, 2023
1 parent d238243 commit 3b274cf
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backends/bmv2/bmv2stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def run(self, stf_map):
str(rand),
]
+ self.interfaceArgs()
+ ["../" + self.jsonfile]
+ [self.jsonfile]
)
if self.cmd_line_args:
runswitch += self.cmd_line_args
Expand Down
3 changes: 2 additions & 1 deletion backends/bmv2/run-bmv2-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def process_file(options, argv):

if run_init_commands(options) != SUCCESS:
return FAILURE
tmpdir = tempfile.mkdtemp(dir=".")
# ensure that tempfile.mkdtemp returns an absolute path, regardless of the py3 version
tmpdir = tempfile.mkdtemp(dir=Path(".").absolute())
basename = os.path.basename(options.p4filename)
base, _ = os.path.splitext(basename)

Expand Down
2 changes: 1 addition & 1 deletion backends/p4test/run-p4-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def file_name(tmpfolder, base, suffix, ext):
def process_file(options, argv):
assert isinstance(options, Options)

tmpdir = tempfile.mkdtemp(dir=".")
tmpdir = tempfile.mkdtemp(dir=Path(".").absolute())
basename = os.path.basename(options.p4filename)
base, ext = os.path.splitext(basename)
dirname = os.path.dirname(options.p4filename)
Expand Down
2 changes: 1 addition & 1 deletion backends/tc/run-tc-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def check_generated_files(options, tmpdir, expecteddir):
def process_file(options, argv):
assert isinstance(options, Options)

tmpdir = tempfile.mkdtemp(dir=".")
tmpdir = tempfile.mkdtemp(dir=Path(".").absolute())
basename = os.path.basename(options.p4filename)
base, ext = os.path.splitext(basename)
dirname = os.path.dirname(options.p4filename)
Expand Down

0 comments on commit 3b274cf

Please sign in to comment.