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

Split Python Packages options and collect under common dir #16

Closed
wants to merge 20 commits into from

Conversation

jorgepiloto
Copy link
Member

@jorgepiloto jorgepiloto commented Mar 11, 2022

Solves for #14 and will allow to start working on #10. This PR sets the base for creating any kind of template and reusing common files. New design is based on the following ideas:

  • All family templates are collected under the same directory (e.g. templates/python, templates/fortran).
  • The common/ directory contains shared resources across different family templates (e.g. templates/python/common).
  • A cookiecutter.json is provided inside the templates/family/common/ and holds basic private variables. This ensures new families of templates need to override these vars in their custom cookiecutter.json.

Before merging this:

  • Have a test dir per family template and a test script per each one of its members.
  • Test project integrity and baked projects in the CI.
  • Update doc about new usage and addition of new templates. Check README.rst too.
  • Fix .pre-commit-config.yaml so it does not interfere with template files.

@jorgepiloto
Copy link
Member Author

jorgepiloto commented Mar 11, 2022

About cookiecutter template inheritance: cookiecutter/cookiecutter#1485

@jorgepiloto
Copy link
Member Author

I'm facing some problems when trying to perform a "tree copy" of the common directory. See this warning in the official shutil docs.

@jorgepiloto
Copy link
Member Author

I'm facing some problems when trying to perform a "tree copy" of the common directory. See this warning in the official shutil docs.

Solved locally! It was not a problem related with shutil but avoiding cookiecutter from parsing a literal {{...}}.

@jorgepiloto
Copy link
Member Author

jorgepiloto commented Mar 14, 2022

Problem: Once the cookiecutter context is initialized, additional copied files by the pre_gen_project.py are not rendered. This is because when the context starts it cannot be modified and those files are not present yet.

Solution: Create a function called bake_template which creates a temporary template directory. This temporary template will combine the common/ and the desired template/ files before executing the cookiecutter context.

I'm planning to take advantage of the tempfile module for this. Fingers crossed... 🤞🏽

Edit: It worked! 🚀

@jorgepiloto
Copy link
Member Author

jorgepiloto commented Mar 15, 2022

For the CI, I think the following approach should work:

  • Add a flag in tox.ini so particular templates can be tested (e.g. `tox -e py310-keep-output-python).
  • Add a .github/workflows/template_family.yml for testing baked projects (only linux-based in matrix.os).

@jorgepiloto
Copy link
Member Author

Smoke tests in Python 3.7 are failing because shutil.copytree(dir_exist_ok=True) was introduced in Python+3.8.

@jorgepiloto jorgepiloto deleted the feat/pkg_level branch March 15, 2022 17:10
@jorgepiloto jorgepiloto mentioned this pull request Mar 15, 2022
11 tasks
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.

None yet

1 participant