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

WIP - Folder inheritance #79

Closed
wants to merge 3 commits into from
Closed

WIP - Folder inheritance #79

wants to merge 3 commits into from

Conversation

pykong
Copy link
Collaborator

@pykong pykong commented Sep 23, 2019

WIP - Do not merge yet.

What this is about

This PR introduces an inheritance mechanism for template folders. Now we can have multiple child templates that inherit files and subfolders from a single parent. Thereby the need to duplicate the same set of files and subfolders among many templates is eliminated resulting in much DRYer templates.

The implementation rests upon the new optional _extends setting which defines a path to a parent template folder. If _extends is a given then the referenced parent folder is rendered to the destination path before the child folder.
Conflicts will be either resolved manually via the prompting mechanism or by giving skip / force flags.

This is some wickedly powerful feature. Maybe this is something other packages do not possess (I do not know, but could be a good selling point). I was surprised by how well it turned out working with only minimally invasive modifications to the code. Still, I am testing this further and try to evaluate all corner cases and pitfalls. Eventually, we could release this as an experimental feature.

TODO:

  • Processing copier.yml of the parent template folder
    • Preventing same tasks to run on each level
    • What options should be passed from child to parent?
  • Validate against path collision
  • Write more tests
  • Remove extra_paths
  • Update docs
  • Add extends to cli args
  • Rename extends for consistency? (maybe to parent_path)

Closes: #67

@@ -0,0 +1 @@
_extends: ./tests/demo_inheritance/conflicted/parent
Copy link
Member

Choose a reason for hiding this comment

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

If this works as it is written here, I'd consider this a bug.

You cannot predict from which folder the user will launch copier. Instead, all paths should always be relative to the very copier.yml file that defines them.

So, in this case, this should be:

Suggested change
_extends: ./tests/demo_inheritance/conflicted/parent
_extends: ../parent

... because from this copier.yml file, the parent folder is found there.

Also have you considered the possibility of extending several at once? We could define this as a list:

Suggested change
_extends: ./tests/demo_inheritance/conflicted/parent
_extends:
- ../parent

The same applies for other test cases here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yajo Thx. I will investigate this. Please consider opening a short issue if you think there is indeed a bug or potential improvement here, so we can properly track things.

Copy link
Member

Choose a reason for hiding this comment

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

Well, this is WIP, I don't think I need another issue, isn't it?

@@ -108,7 +116,7 @@ def copy(
Skip files that already exist, without asking

- quiet (bool):
Suppress the status output
Suppress the status outputm
Copy link
Member

Choose a reason for hiding this comment

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

Typo

@pykong
Copy link
Collaborator Author

pykong commented Feb 26, 2020

I am no longer pursuing this PR.
Closing this in favor of only transcluding from other config files: #117

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.

Sharing identical files between templates
2 participants