Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6150b61

Browse files
committed
Fix non-in-place building
It's unclear when that stopped (or possibly whether it's ever worked), but "regular" commands which don't build in-place (e.g. a simple `setup.py build`) have not worked in a while, because the overrides on tasks trigger `build_regexes` before the task itself (to say nothing of invoking `build_regexes` directly). As a result, the build_dir does not exist yet unless there's an old build_dir remaining for some reason, and trying to create the file crashes. Ensure the build dir exists before trying to write `_regexes.py`. There's a minor TOCTOU in order to handle Python 2's `os.makedirs`, as it doesn't have `exist_ok`.
1 parent 05e0e41 commit 6150b61

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ def write_params(fields):
9292

9393
import yaml
9494

95-
py_dest = os.path.join(self.build_lib, "ua_parser", "_regexes.py")
96-
9795
log.info("compiling regexes.yaml -> _regexes.py")
9896
with open(yaml_src, "rb") as fp:
9997
regexes = yaml.safe_load(fp)
98+
99+
lib_dest = os.path.join(self.build_lib, "ua_parser")
100+
if not os.path.exists(lib_dest):
101+
os.makedirs(lib_dest)
102+
103+
py_dest = os.path.join(lib_dest, "_regexes.py")
100104
with open(py_dest, "wb") as fp:
101105
# fmt: off
102106
fp.write(b"# -*- coding: utf-8 -*-\n")

0 commit comments

Comments
 (0)