Conversation
Bugfixes: - change CDIR in Snakefile to always contain forward slashes instead of depending on the OS.
There was a problem hiding this comment.
Did you also try pathlib here? It is generally better for cross-platform compatibility. And we wanna leave those string paths behind.
I was under the impression that Snakemake works with "Linux-Style" paths regardless of OS
Not sure how this interferes with Snakemake. But I don't like to rely on it
|
I agree with @lkstrp — try |
|
@lkstrp, @fneum I've tried it today with pathlib. Changing it to and changing every other occurance to (or similar), seemed to work in a dry-run. |
It might be slighty cleaner to go with and I'll try a full run with it today. @lkstrp I've found the Snakemake pull request, that changes all Windows paths to posix paths. |
Bug fix: - change CDIR in the Snakemake files to pathlib to properly function on Windows
| regions_offshore=resources("regions_offshore.geojson"), | ||
| output: | ||
| protected(CDIR + "{cutout}.nc"), | ||
| protected(CDIR.joinpath("{cutout}.nc").as_posix()), |
There was a problem hiding this comment.
| protected(CDIR.joinpath("{cutout}.nc").as_posix()), | |
| protected(CDIR / "{cutout}.nc"), |
Instead of joinpath, you should be able to use the/ operator (simplifies code)
.as_posix() should also not be necessary as
In [8]: from pathlib import Path
In [9]: Path("test") / "mypath"
Out[9]: PosixPath('test/mypath')
In [10]: Path("test").joinpath("mypath")
Out[10]: PosixPath('test/mypath')
In [11]: Path("") / Path("")
Out[11]: PosixPath('.')
In [12]: Path("")
Out[12]: PosixPath('.')
In [13]: "" / Path("test")
Out[13]: PosixPath('test')
This minimises code changes in .smk files to changing "+" to "/".
There was a problem hiding this comment.
Hey @fneum,
I agree that "/" is nicer than .joinpath() (and it works just fine on Windows).
as_posix() however has to stay for two reasons:
- a PosixPath is required to resolve issue Snakemake can't find retrieve_cutouts #1598. On Windows all your examples output a WindowsPath, which leads to the issue. Another option to ensure this, would be defining CDIR as a PurePosixPath. Pure is required because using just PosixPath does not function on Windows.
- input, output and log files have to be strings. At least when using a PurePosixPath this always leads to errors, if the Path is not converted to a string first (either with str() or with .as_posix()). Below you will find a few error messages I got when testing it witout converting the Paths to strings or just partially converting them to strings.
RuleException in file C:[...]\pypsa-eur\rules/retrieve.smk, line 136:
Input and output files have to be specified as strings or lists of strings.
RuleException in file C:[...]\pypsa-eur\rules/retrieve.smk, line 136:
Log files have to be specified as strings.
InputFunctionException in rule build_renewable_profiles in file C:\[...]\pypsa-eur\rules/build_electricity.smk, line 306:
Error:
Function did not return str or iterable of str. Encountered: [PurePosixPath('cutouts/europe-2013-sarah3-era5.nc')] (<class 'list'>)
``
|
Sorry for dropping in here late, but i was also fighting this path nonsense with snakemake a while ago. Snakemake is in principle fine with ie a string may not mix between them. The way CDIR as a string is used and compounded with other paths you are introducing in so many places "/" into the string after the CDIR that this is a loosing battle and you should just use a literal "/" as a separator. That works reliably because snakemake runs on all paths os.path.normpath and that converts At least that was my take-away. Note that you can play around with an ipython on windows using wine: and then in the new powershell window: and after reopening it: Have fun. |
Bugfixes:
Closes #1598
Changes proposed in this Pull Request
os.path.joinanymore. More details on this can be found in Snakemake can't find retrieve_cutouts #1598.Checklist
envs/environment.yaml.config/config.default.yaml.doc/configtables/*.csv.doc/data_sources.rst.doc/release_notes.rstis added.