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

feat: modify copy commit processing rule #237

Merged
merged 13 commits into from
Nov 30, 2023

Conversation

doneachh
Copy link
Collaborator

Closes # (if applicable).

Changes proposed in this Pull Request

Added a copy commit function, which stores the commit id and commit message of pypsa earth sec and the submodule in the n.meta of the .nc file

Checklist

  • I tested my contribution locally and it seems to work fine.
  • Code and workflow changes are sufficiently documented.
  • Newly introduced dependencies are added to envs/environment.yaml and envs/environment.docs.yaml.
  • Changes in configuration options are added in all of config.default.yaml, config.tutorial.yaml, and test/config.test1.yaml.
  • Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • 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.

@doneachh doneachh linked an issue Sep 14, 2023 that may be closed by this pull request
@doneachh
Copy link
Collaborator Author

@energyLS please review! :)

@doneachh
Copy link
Collaborator Author

Hey @davide-f :)
implemented the copy commit feature for pypsa-earth sec as well. Can you review it here as well? 🙏

scripts/helpers.py Outdated Show resolved Hide resolved
scripts/helpers.py Outdated Show resolved Hide resolved
@doneachh
Copy link
Collaborator Author

@davide-f tried to implement the review aspects like in pypsa-earth: Somehow it doesnt work here. As soon as we import scripts.helpers in the Snakefile of pypsa-earth sec we get an error that we dont find the module scripts._helpers in the Snakefile of pypsa earth. I dont understand why this is happening. Do you have an idea? :)

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.

A little comment but that does not explain the issue.
I think there is the need to check it better.
May you try to test locally if that is reproducible also by updating the version of the subworkflow to the latest commit?

scripts/helpers.py Outdated Show resolved Hide resolved
@davide-f
Copy link
Member

As additional comment, in PyPSA-Earth we do have:

import sys
sys.path.append("./scripts")

May be good to check if that's necessary to have in pypsa-earth and whether it's absence in -sec may lead to issues

Unfortunately these weird behaviours are most likely due to the subworkflows that are not well maintained...

@doneachh
Copy link
Collaborator Author

Hi @davide-f,
sorry for my late response: Checked

import sys
sys.path.append("./scripts")

adding it in the snakefile of pypsa-earth-sec, which didnt work.
Also i tried to remove it in the snakefile of pypsa-earth, which didnt work as well.
Do you have another idea of how to fix it? Otherwise i would suggest to copy the commit not already in the beginning of the snakefile and copy it in the solve_network function - this would work out :)

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.

A comment, let me know your thoughts :)
P.S. I fixed the merge conflicts, feel free to force-push the commit or pull them :)

Comment on lines 578 to 592
_logger = logging.getLogger(__name__)
try:
last_commit_message = (
subprocess.check_output(
["git", "log", "-n", "1", "--pretty=format:%H %s"],
cwd=path,
stderr=subprocess.STDOUT,
)
.decode()
.strip()
)
return last_commit_message
except subprocess.CalledProcessError as e:
_logger.warning(f"Error executing Git: {e}")
return None
Copy link
Member

Choose a reason for hiding this comment

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

According to the documentation, it seems that the cwd option overrides the cwd.

It may be a good idea to create a backup of cwd and restore it after the execution in an error-proven way.

To do this, for example, we may:

  1. before the try, initialize the last_commit_message to None and store cwd in a local variable
  2. in the try/except, drop the return statements
  3. after the try/except, restore the original cwd path
  4. return the last_commit_message

This may be worth trying to check if it solves the problem.
It may be good to reflect these changes into pypsa-earth as well, once validated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @davide-f ,
thanks for the solution approach. Sadly it seems not to work.
Do you have any other ideas? Im pretty much empty with solution ideas.

@davide-f
Copy link
Member

Hello! :D

So, I've locally tested your PR and I made it run by removing the "scripts." in the pypsa-earth Snakefile in the imports like "from scripts._helpers".
Could you investigate if that works also for the standard pypsa-earth?
Once verified, you could create a PR in pypsa-earth where we revise the setup of the get_commit function and also revise the snakefile as done here.

I think we are close to finalize :)

@doneachh
Copy link
Collaborator Author

Hi @davide-f :)
the removement of "scripts." works! 👍
Thanks for your help - how do we continue with this PR as it only works with the modified submodule?

@doneachh
Copy link
Collaborator Author

Hi @davide-f :D
Merged main into the branch and updated the submodule!
Thank you so much for your help :)

@davide-f
Copy link
Member

davide-f commented Nov 29, 2023

super :) CI is also passing.
I think this PR can be merged

@energyLS
Copy link
Collaborator

super :) CI is also passing. I think this PR can be merged

@davide-f then I will merge it? :)

@davide-f
Copy link
Member

super :) CI is also passing. I think this PR can be merged

@davide-f then I will merge it? :)

Yeah :D

@energyLS energyLS merged commit faa76ef into main Nov 30, 2023
4 checks passed
@davide-f davide-f deleted the 234-modify-copy-commit-processing-rule branch February 5, 2024 18:29
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.

Modify copy commit processing rule
3 participants