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

Migrate post-generation hook to pathlib #5648

Merged

Conversation

browniebroke
Copy link
Member

@browniebroke browniebroke commented Jan 18, 2025

Description

The post-generation hook makes heavy uses of path operations and Ruff suggests to migrate them to pathlib in #5613

These suggestions can't be fixed automatically by Ruff, so in that other PR, I asked Ruff to add a lot of noqa (with the --add-noa option) where there was issues. However, that makes the diff bigger that it should...

This PR intend to fix all the PTH issues from that script, and that script only.

Checklist:

  • I've made sure that tests are updated accordingly (especially if adding or updating a template option)
  • I've updated the documentation or confirm that my change doesn't require any updates

Rationale

Copy link
Collaborator

@foarsitter foarsitter left a comment

Choose a reason for hiding this comment

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

An abstraction for unlink & rmtree would further improve this script but may be out of scope

def delete_files(*args: Path): 
    for file in args:
        if file.isdir():
            shutil.rmtree(file)
        else:
            file.unlink()

@browniebroke
Copy link
Member Author

An abstraction for unlink & rmtree would further improve this script but may be out of scope

def delete_files(*args: Path): 
    for file in args:
        if file.isdir():
            shutil.rmtree(file)
        else:
            file.unlink()

Yes good idea, we do this all over the place 👍🏻

@browniebroke browniebroke merged commit a1105d9 into cookiecutter:master Jan 20, 2025
13 checks passed
@browniebroke browniebroke deleted the migrate-post-gen-hook-pathlib branch January 20, 2025 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants