-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add an OS specific helper for replacing characters for file separators #692
Comments
I don't think the distinction between Linux and Windows is relevant: indeed, the point of this issue is to provide a way to create directory structures without tasks, and the suggestion is to provide a context variable (for example |
I see. You were pushing to add a feature where we can do this as a task in |
IIUC, what @yajo suggested is that Copier natively supports creating arbitrarily deep directories without tasks, yes, by allowing writers to use a |
umm... this works for me. You can use forward slash on Windows, no problem. |
Oh, and I had to add one line to copier, as it doesn't create parent directories for rendered files. |
In the PR 6e06df7 there's a test for this behaviour. It passes |
Yes definitely. And it makes sense that it doesn't need to be a special character, since filenames will use the variable and not the character (slash) itself :) |
Introducing a global variable would break existing templates for anyone who already uses that name, regardless of what name we pick. So it would be a breaking change, unless there's a configuration variable: _separator_key: os_sep WDYT? |
I think the risk of clashing with the name of an answer in someone's template is very low, especially if we prefix it with an underscore. But I'll let @yajo decide 🙂 |
Ah, I didn't think of adding a prefixed variable. Yeah, that works. In that case, how about exposing a subset of |
Ha, very interesting idea 🤔 |
There's https://pypi.org/project/jinja2-getenv-extension/ so we shouldn't need this. |
…` to allow generating dynamic directory structures * feat(Worker): make sure the parent directory of the target file exists before writing to it * feat(_copier_conf): add directory separator (os.sep) to _copier_conf Fix #692
From a discussion we had about creating a directory structure, it was proposed to use
replace(".", "/")
in a task script. As this is specific to unix like filesystems it would be nice to have a helper that is OS specific. On Windows it will be\
and on unix like OS' it'll be/
.The working example (unix specific) is
A nice alternative, as proposed by @yajo & @pawamoy would be
The text was updated successfully, but these errors were encountered: