Fix the detection of an unhappy installation path in a venv under Windows#554
Fix the detection of an unhappy installation path in a venv under Windows#554
Conversation
1029be1 to
92b1a47
Compare
92b1a47 to
3606064
Compare
popescu-v
left a comment
There was a problem hiding this comment.
See the remaining open comment.
3606064 to
c088121
Compare
popescu-v
left a comment
There was a problem hiding this comment.
A few remaining issues (see the comments).
c088121 to
dee6493
Compare
khiops/core/internals/runner.py
Outdated
| Parameters | ||
| ---------- | ||
| library_root_dir : PosixPath | ||
| library_root_dir_path : PosixPath |
There was a problem hiding this comment.
This should be a Path rather than a PosixPath IMHO, to account for Windows paths (and their case-insesitiveness).
There was a problem hiding this comment.
You are right, depending on the platform the constructor built either a WindowsPath instance or a PosixPath one.
Fixed
khiops/core/internals/runner.py
Outdated
| library_root_dir = str(library_root_dir_path) | ||
| conda_prefix = os.environ["CONDA_PREFIX"] |
There was a problem hiding this comment.
We could keep library_root_dir_path as such and comapre it with Path(os.environ["CONDA_PREFIX"]). This should account for Windows case-insensitiveness specifics. Cf. https://docs.python.org/3/library/pathlib.html#general-properties:
>>> PureWindowsPath('foo') == PureWindowsPath('FOO')
TrueThere was a problem hiding this comment.
This WindowsPath case-insensitivess is very interesting and suggests an appealing and elegant way to improve the tests.
But after a review it appears that the majority of the tests are prefix checking (startswith()) and only for 2 cases we have exact paths comparison.
To my humble opinion it is not worth the hassle and this tolower() way seems the most obvious and readable.
There was a problem hiding this comment.
IMHO, some of this cases could be tackled by using subpath in path.parents, in case we want to test a certain path starts with a subdirectory, or even subpath == path.parents[-2] :
>>> path = Path("/dir1/dir2/dir3/file.txt")
>>> path.parents[-2]
PosixPath("/dir1") # or WindowsPath("/dir1")Or we can use Path.parts:
>>> subpath = Path("/dir1")
>>>path = Path("/dir1/dir2/dir3/file.txt")
>>> subpath.parts == path.parts[: len(subpath.parts)] # Check path starts with subpath
True
Etc. So, IMHO it's better to systematize on using pathlib because it:
- reduces conditional OS-dependent code
- thus, reduces maintenance costs
- hence, reducing potential bugs or missing OS-dependent code in this respect.
There was a problem hiding this comment.
OK let's got for it. The comparisons will have to be exact then (not using startswith() with a prefix any longer).
One must be careful about the exact folder hierarchy to avoid comparison errors.
khiops/core/internals/runner.py
Outdated
| # the path casing on Windows | ||
| sys_base_prefix = sys.base_prefix | ||
| sys_prefix = sys.prefix | ||
| if platform.system() == "Windows": |
There was a problem hiding this comment.
Using (and comparing) pathlib.Paths directly should account for Windows case-insensitiveness and make OS-conditional code in this respect unneessary.
dee6493 to
886058e
Compare
- External tools like VSCode can modify for example the case of the path saved in `sys.executable` - As a general rule a pathlib.Path object is always built. Depending on the OS either a PosixPath or a WindowsPath instance is created. This later sees case-insensitive paths.
886058e to
3ed7b8c
Compare
External tools like VSCode can modify the case of the path saved in
sys.executableFixes #548
The case is indeed reproductible in saving the value of
sys.executableand altering its case.Implementing an automatic test would required extracting a function returning
sys.executableand mocking it during the test.Possible but but a bit overkill.
TODO Before Asking for a Review
main(ormain-v10)Unreleasedsection ofCHANGELOG.md(no date)index.html