Bugfix submodule filenotfounderror#1768
Conversation
Also add management for temporary tarball file
fneum
left a comment
There was a problem hiding this comment.
Looks good! Thanks @jonathan-peel! Defining temporary folders/files relative to output files is quite clever!
The one thing that needs to be adjusted is the removal of shadow directories. As useful as they are, they don't work well on Windows (especially corporate issues), and that's why we want to avoid them. Also, I am unsure about os.chmod on Windows. Maybe remove if not strictly necessary.
Could you also confirm that you tested the adjustments outside of the snakemake module setup? Background is that some of the downloads are cached and errors might not be caught by CI.
|
Hi Fabian, thanks for having a look and for the pointers on Windows compatibility. I've removed the shadow directories and chmod as requested. I've also resolved merge conflicts and rebased the branch. |
|
I can also confirm that I tested everything in both pure pypsa-eur module mode and a setup where pypsa-eur is a snakemake module (and git submodule). |
* Fix FileNotFoundError for rule retrieve_eez * Fix FileNotFoundError for rule retrieve_nuts_2021_shapes * Update zip -> zip_file; change to shcopy2 * Fix FileNotFoundError for rule retrieve_nuts_2013_shapes * Fix FileNotFoundError in rule retrieve_worldbank_urban_population * Fixed FileNotFoundError in rule retrieve_co2stop * Fix FileNotFoundError for rule download_wdpa * Fix FileNotFoundError for rule download_wdpa_marine * Change zip to zip_file in rule retrieve_aquifer_data_bgr * Remove unnecessary imports * Add release note * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add link to pull request * Fix FileNotFoundError for rule retrieve_eurostat_data * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove shadow directory from rule retrieve_eurostat_data * Add tempory file handling for rule retrieve_eurostat_data * Fix FileNotFoundError for rule retrieve_eurostat_household_data Also add management for temporary tarball file * Update release notes * Replace shadow directories with manual file deletion. * Update release notes. * Removed chmod for windows compatability. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Fix FileNotFoundError for rule retrieve_eez * Fix FileNotFoundError for rule retrieve_nuts_2021_shapes * Update zip -> zip_file; change to shcopy2 * Fix FileNotFoundError for rule retrieve_nuts_2013_shapes * Fix FileNotFoundError in rule retrieve_worldbank_urban_population * Fixed FileNotFoundError in rule retrieve_co2stop * Fix FileNotFoundError for rule download_wdpa * Fix FileNotFoundError for rule download_wdpa_marine * Change zip to zip_file in rule retrieve_aquifer_data_bgr * Remove unnecessary imports * Add release note * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add link to pull request * Fix FileNotFoundError for rule retrieve_eurostat_data * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove shadow directory from rule retrieve_eurostat_data * Add tempory file handling for rule retrieve_eurostat_data * Fix FileNotFoundError for rule retrieve_eurostat_household_data Also add management for temporary tarball file * Update release notes * Replace shadow directories with manual file deletion. * Update release notes. * Removed chmod for windows compatability. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Closes #1762
Changes proposed in this Pull Request
This request fixes
FileNotFoundErrorbugs preventing pypsa from being run as a Snakemake module.The cause of this bug was that intermediate zip files in rules were being saved in directories that didn't exist yet (without creating the parent directories). This didn't fail when using PyPSA-Eur as a standalone module, because the directory was the same as the rule's output file. However, when using PyPSA-Eur as a Snakemake module, this was not the case as Snakemake prepends a prefix to all the input and output files, but not to any file locations listed as parameters. The fix was to use Snakemake's built-in shadow directories and save intermediate zip files at the top level within these. This was fixed for many rules in
retrieve.smk, i.e.,retrieve_eez,retrieve_nuts_2021_shapes,retrieve_nuts_2013_shapes,retrieve_worldbank_urban_population,retrieve_co2stop,download_wdpa,download_wdpa_marine.Fixes detail
FileNotFoundErroras soon as a function looks for a file based on the location given in a param. Concretely, snakemake saves any input (including those fetched using the storage function) in the prefix directory (e.g.,pypsa-eur/data/your/file.here), and if you try to access this file using a location derived from a param (e.g.,data/your/file.here), you’ll get aFileNotFoundError. The fix is to never indicate a path relative to a param.tempfile.ziptozip_fileCommands that didn’t work that now work
snakemake pypsa-eur/data/eez/World_EEZ_v12_20231025_LR/eez_v12_lowres.gpkg --cores 1(calls ruleretrieve_eez)snakemake pypsa-eur/data/nuts/NUTS_RG_01M_2021_4326_LEVL_3.geojson --cores 1(calls ruleretrieve_nuts_2021_shapes)snakemake pypsa-eur/data/nuts/NUTS_RG_03M_2013_4326_LEVL_3.geojson --cores 1(calls ruleretrieve_nuts_2013_shapes)snakemake pypsa-eur/data/worldbank/API_SP.URB.TOTL.IN.ZS_DS2_en_csv_v2.csv --cores 1(calls ruleretrieve_worldbank_urban_population)snakemake pypsa-eur/data/CO2JRC_OpenFormats/CO2Stop_DataInterrogationSystem/Hydrocarbon_Storage_Units.csv --cores 1(calls ruleretrieve_co2stop)snakemake pypsa-eur/data/WDPA.gpkg --cores 1(calls ruledownload_wdpa)snakemake pypsa-eur/data/WDPA_WDOECM_marine.gpkg --cores 1(calls ruledownload_wdpa_marine)snakemake pypsa-eur/data/bgr/ihme1500_aquif_ec4060_v12_poly.shp --cores 1(calls ruleretrieve_aquifer_data_bgr)snakemake pypsa-eur/data/eurostat/Balances-April2023 --cores 1(calls rule retrieve_eurostat_data)More generally, the following overall commands now work
snakemake _pypsa_solve_sector_networksandsnakemake _pypsa_solve_elec_networksChecklist
envs/environment.yaml.config/config.default.yaml.doc/configtables/*.csv.doc/data_sources.rst.doc/release_notes.rstis added.