Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable configfile specification for mock_snakemake #1135

Merged

Conversation

yerbol-akhmetov
Copy link
Collaborator

@yerbol-akhmetov yerbol-akhmetov commented Oct 9, 2024

Changes proposed in this Pull Request

Good day. Here I propose to enable specification of configfile while using mock_snakemake. It is particularly useful when debugging the scenario with its own run name. Currently, the files are searched in resources/ or networks/ folders as example. If user had already prepared files in folders under run name, it is not visible. Overwriting config file is enabled in snakemake<8 with overwrite_config parameter, which takes dictionary.

Checklist

  • I consent to the release of this PR's code under the AGPLv3 license and non-code contributions under CC0-1.0 and CC-BY-4.0.
  • I tested my contribution locally and it seems to work fine.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great again @yerbol-akhmetov !!!
I've added a minor comment; I'd merge the PRs with squash and merge if it is ok for you as it would leave flexibility for the merge issue that is open.

if isinstance(configfile, str):
with open(configfile, "r") as file:
configfile = yaml.safe_load(file)
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than else, maybe "elif not isinstance(configfile, dict)" or drop the if case?
By default it is none, so the else case may not be necessary but a dictionary may be provided as well as input.
What do you think?

Almost ready to merge :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davide-f, thanks for the feedback. I have initially meant to omit else case, because default if None. But then I thought what if the user gives something other than str, it can cause error. Therefore I have added additional else with None. Similar thing I have noticed in PyPSA-Eur. Maybe it is better then drop else case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davide-f, thanks for the feedback. I have initially meant to omit else case, because default if None. But then I thought what if the user gives something other than str, it can cause error. Therefore I have added additional else with None. Similar thing I have noticed in PyPSA-Eur.

Let's drop it :) that function is not used by the normal user.
If provided a wrong input, probably it is safe for the code to through an error rather than silently fix it.
Great contribution!

Copy link
Collaborator Author

@yerbol-akhmetov yerbol-akhmetov Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davide-f, ok, thanks, understood.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have dropped else condition, while keeping if, so to make sure, config is read only if the path is given as string.

@davide-f
Copy link
Member

@yerbol-akhmetov apologies, by merging the other PR this has let to conflicts. Can you fix it?
As you do that, I squash and merge this too.
I don't want to do that to avoid being co-author of the PR while you worked on it.

@yerbol-akhmetov
Copy link
Collaborator Author

@yerbol-akhmetov apologies, by merging the other PR this has let to conflicts. Can you fix it? As you do that, I squash and merge this too. I don't want to do that to avoid being co-author of the PR while you worked on it.

Thanks, @davide-f. I have resolved the merge conflicts and updated the branch with main.

@davide-f davide-f merged commit 489ff8f into pypsa-meets-earth:main Oct 16, 2024
3 of 4 checks passed
@yerbol-akhmetov yerbol-akhmetov deleted the config_mock_snakemake branch October 16, 2024 14:34
davide-f pushed a commit to davide-f/pypsa-earth that referenced this pull request Oct 20, 2024
…#1135)

* enable configfile for mock_snakemake

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add release notes

* drop else condition

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
davide-f pushed a commit to davide-f/pypsa-earth that referenced this pull request Oct 20, 2024
…#1135)

* enable configfile for mock_snakemake

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add release notes

* drop else condition

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
GbotemiB pushed a commit to drifter089/pypsa-earth that referenced this pull request Oct 22, 2024
…#1135)

* enable configfile for mock_snakemake

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add release notes

* drop else condition

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants