milksnake
milksnake copied to clipboard
Non portable paths issue
I had an issue with milksnake when setuping a CI pipeline for Linux, Mac and Windows.
For Windows I SET
the CARGO_TARGET_DIR
to a folder I can cache between runs. To prevent issue with Windows backslash being wrongly escaped (or not), I use a path similar to C:/cargo_cache/project_name/target
.
After some debugging, I've realized that milksnake assumes /
is used as paths separators when looking for files. See for example https://github.com/getsentry/milksnake/blob/ef0723e41df23d8f6357570c69c1e69cb31f9e9e/milksnake/setuptools_ext.py#L146
and https://github.com/getsentry/milksnake/blob/ef0723e41df23d8f6357570c69c1e69cb31f9e9e/milksnake/setuptools_ext.py#L165
Those two lines will join()
the search path with the in_path
argument which is split with forward slashes.
I thus end up with paths that look like C:cargo_cache/project_name/target
and milksnake can't find the expected files.
It seems those lines attempt to replace the forward slashes with the platform's separator, but it's not doing a proper job.
If that is the expected behaviour, I would suggest doing something like that instead:
path = os.path.join(os.path.normalize(path), *os.path.normalize(in_path).split(os.sep))
or even just
path = os.path.join(os.path.normalize(path), os.path.normalize(in_path))
or maybe even simpler
path = os.path.normalize(os.path.join(path, in_path))