Skip to content

Commit

Permalink
Update hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
lyashevska committed Jul 4, 2024
1 parent dbf5c4c commit 6e30f0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ code_of_conduct_email:
default: "{{ email }}"

_subdirectory: template
_tasks:
- python pre_gen_project.py

# Optional questions
32 changes: 21 additions & 11 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Note: cookiecutter first makes the main level directory using
# directory_name from cookiecutter.json before running this hook

{{ cookiecutter.update({
"package_name": cookiecutter.package_name.lower().replace(" ", "_").replace("-", "_"),
"directory_name": cookiecutter.directory_name.lower().replace(" ", "-"),
"full_name": cookiecutter.full_name.replace('\"', '\\\"'),
"repository": "git@github.com:" + cookiecutter.github_organization + "/" + cookiecutter.directory_name.lower().replace(" ", "-"),
"repository_url": "https://github.com/" + cookiecutter.github_organization + "/" + cookiecutter.directory_name.lower().replace(" ", "-"),
"package_short_description": cookiecutter.package_short_description.replace('\"', '\\\"')
}) }}
import os
import yaml

def update_config():
with open("copier.yml") as f:
config = yaml.safe_load(f)

config.update({
"package_name": config["package_name"].lower().replace(" ", "_").replace("-", "_"),
"directory_name": config["directory_name"].lower().replace(" ", "-"),
"full_name": config["full_name"].replace('\"', '\\\"'),
"repository": "git@github.com:" + config["github_organization"] + "/" + config["directory_name"].lower().replace(" ", "-"),
"repository_url": "https://github.com/" + config["github_organization"] + "/" + config["directory_name"].lower().replace(" ", "-"),
"package_short_description": config["package_short_description"].replace('\"', '\\\"')
})

with open("copier.yml", "w") as f:
yaml.safe_dump(config, f)

if __name__ == "__main__":
update_config()

0 comments on commit 6e30f0a

Please sign in to comment.