1797 Commits

Author SHA1 Message Date
Jairo Llopis
6dd69a957f
Support custom templates suffix
The `.tmpl` suffix doesn't seem to be a very widely adopted standard on the Jinja world. Others like `.jinja` or `.j2` usually have better IDE integration.

It's not like `.tmpl` is a wrong default, so here I'm leaving it as a default but letting template developers to change it to another one that fits better their environment.

Apart from this, if you really had to produce any `.tmpl` files in your copies, having files that ended with `.tmpl.tmpl` seemed a bit weird, while now you can change that suffix to whatever fits better your project.

@Tecnativa TT20357
2020-01-23 11:30:56 +00:00
Jairo Llopis
7e3a5611a9
Merge pull request #109 from Tecnativa/handle-keyboardinterrupt
Handle KeyboardInterrupt elegantly
2020-01-21 13:55:15 +00:00
Jairo Llopis
488946981a
Handle KeyboardInterrupt elegantly
Without this patch, a full traceback is printed when the user hits <kbd>Ctrl</kbd> + <kbd>C</kbd>.

Now it's more elegant. Other exceptions supported also.

@Tecnativa TT20357
2020-01-21 13:47:21 +00:00
Ben Felder
0fcb9dbc50
Merge pull request #108 from Tecnativa/rename-copierlog
Rename copierlog to copier-answers across the codebase
2020-01-14 10:25:35 +01:00
Jairo Llopis
87104e36a5
Rename copierlog to copier-answers across the codebase
The initial implementation in https://github.com/pykong/copier/pull/103 was calling the file logfile, but it was renamed to copier-answers later.

However I discovered there are still a few remainders of the old implementation.

Here I remove them.

@Tecnativa TT20357
2020-01-14 09:27:33 +01:00
Ben Felder
99d1741069
Merge pull request #107 from Tecnativa/params-extended
Add advanced questions format
2020-01-13 16:59:56 +01:00
Jairo Llopis
9f6a185aa8
Disable builds cache
They were breaking some builds weirdly.
2020-01-13 11:38:24 +01:00
Jairo Llopis
2241d8fcb9
Add advanced questions format
Fix #89 and fix #89 by adding a new extended syntax to make prompts way more usable.

Leverages plumbum's helpers, so prompt code is removed from Copier codebase, making it smaller BTW.

See README and the new test to understand the new features.

@Tecnativa TT20357
2020-01-13 10:49:59 +01:00
Jairo Llopis
f8673465ba
Improve autoformatting
Continues the job started in #104:

- Configure more languages for VSCode to format on save.
- Recommend extensions for VSCode.
- Remove settings from `.prettierrc.yml` that are duplicated in `.editorconfig` (which prettier uses by default).
2020-01-09 13:34:57 +00:00
Ben Felder
4ccf28aa8f
Merge pull request #104 from Tecnativa/auto-coding-standards
Auto coding standards (pre-commit and similar)
2019-12-12 14:43:57 +01:00
Jairo Llopis
906216fba8 Configure vscode
With these settings, we enable debugging, and developing in vscode is easier.
2019-12-10 11:52:41 +00:00
Jairo Llopis
5b48f352a4 Fix new checks
- Add ignore comment on `BaseModel` instances that are correctly following what `pydantic` wants, to let flake8-bugbear be happy.
- Remove unused import.
2019-12-10 11:52:05 +00:00
Jairo Llopis
0a952b7680 Run pre-commit for the 1st time
OK, now this diff is very big, but it's actually modifying only style, not code functions themselves. From now on, this won't have to happen again.

Basically I just ran `pre-commit run --all-files` and committed that. I hope you like how it looks now!
2019-12-10 11:47:30 +00:00
Jairo Llopis
2ff11656e2 Specific configurations for files that need no EOF
Pre-commit by default adds a single `\n` EOF to all files, but we have some tests that make sure that isn't done by Copier itself.

This specific behavior is committed separately to keep track of it. I'm adding an exclusion filter for files named `whatever.noeof.suffix`, and those are skipped by the `end-of-file-fixer` hook.

Also tests had to be changed accordingly. Nothing too special.
2019-12-10 11:45:41 +00:00
Jairo Llopis
a549638c3c Add pre-commit
For those new to pre-commit, tl;dr:

- `pre-commit install` will enable a git hook to forbid committing violating code.
- If `git commit` fails, just `git commit -a` again.

This beautiful tool will convert all our source code to a pleasure to be read and written.

Some insights:

- `make install` now enables pre-commit by default.
- Important hooks:
  - Black, the 21th century Python code autoformatter.
  - isort, to sort imports automatically.
  - mypy, which was also being used anyways.
  - Prettier, for non-python files (markdown and YAML in this repo).
  - Flake8 with bugbear, which reveals some extra coding mistakes.
  - Other common checkers & fixers.
- Used as linter in travis.
- Replaced `make flake` for `make lint`.
2019-12-10 11:45:41 +00:00
Ben Felder
75be70e63a
Merge pull request #106 from Tecnativa/copierlog-update
Basic support for automatic copy updates
2019-12-09 16:08:56 +01:00
Jairo Llopis
899f5d6a66
Basic support for automatic copy updates
This is a totally breaking PR. It had to come sooner or later...

Before this patch, copier had some ugly problems:

- If a file was called `--exclude`, you couldn't add it to `--extra-paths` due to using `nargs='*'` in an option. It is a weird thing that `ArgumentParser` allows to do, but can potentially lead to unfixable problems.
- Argument parsing was a little bit handycraft work.

Meet [Plumbum](https://plumbum.readthedocs.io/), the swiss army knife for CLI packages:

- CLI has been refactored as a plumbum application.
- Tests for CLI parsing removed, since they were incompatible and we are using a well-tested CLI parsing library now after all.
- The application now includes 2 subcommands: `copy` and `update`.
- If called without args, or with 1, it will use `update`.
- If called with 2 args, it will use `copy` (this preserves old usage unchanged, unless you are copying from a template called `copy` or `update`; in such corner case, just call it as `copier copy copy destination` instead).
- `copier --help` and `copier --help-all` are more useful now.

And you might be wondering... Adding such a big dependency just for that? Well, actually plumbum supports more than just CLI applications: supports sane execution of local & remote commands, sane output coloring, sane user prompting... Possibly it will make Copier go to the next level as we keep on using it more. Just take a look at its docs! You'll love it 😉

Of course, all that new CLI had to be reflected in API changes:

- `src_path` is now optional (`None` by default). In such case, copier will try to guess the `src_path` from the `.copier-answers.yml` file in the copy, or fail otherwise.
- `dst_path` is also now optional (`.` by default), meaning that without a `src_path`, you'll be trying to copy anything else to current `$PWD`.
- The builtin `_log` variable, which contains all necessary data for copy updates, now has also a `_src_path` key that points to the original source. This only happens when it was copied from a git repo or from an absolute path in the local disk, as relative paths are not easily reproducible in next updates (they depend on the user's CWD when running copier).
- A new `original_src_path` variable goes around, indicating the git repo or abs system path passed to `src_path` on the initial call. This is just to be stored in `_log` as explained.

```bash
copier gh:example/template destination
cd destination
echo my changes >> anywhere
git commit -m changing .
copier # Equals to `copier update .`
git commit -m 'copier update' .
```

🎉 You're updated!

This is an importan step to complete #88.

@Tecnativa TT20357
2019-12-05 13:51:55 +00:00
Ben Felder
82b1e22a3b
Merge pull request #103 from Tecnativa/copierlog
Add .copier-answers.yml to remember last answers
2019-12-03 16:14:44 +01:00
Jairo Llopis
a6643ffa58
Add .copier-answers.yml to remember last answers
- If the copy destination exists and has a `.copier-answers.yml`, all questions asked in the template `copier.yml` file will get the answer found in `.copier-answers.yml` by default.
- For now, there are no `_private` variables in the copier-answers, but in the future there might be, so I'm documenting that now.
- Add docs for some of Copier's hidden features.
- Add `to_nice_yaml` filter, to be able to dump beautiful YAML. [This name matches that on Ansible](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data) just in case somebody wants to share templates among both engines, although do not take that as an official support statement.
- Add a test that copies a folder with default data, then copies with altered data, and then copies again with default data and still the altered values have been used.
- This is a partial improvement towards completion of #88.

@Tecnativa TT20357
2019-11-28 13:12:46 +00:00
Ben Felder
e95a7699fb
Merge pull request #98 from Tecnativa/fix-94
Skip files and folders if their names evaluate to ""
2019-11-20 16:14:13 +01:00
Ben Felder
b71d089db7
Merge pull request #100 from Tecnativa/comments-syntax
New Jinja defaults, document how to restore them
2019-11-20 16:09:06 +01:00
Jairo Llopis
23f78419e8
New Jinja defaults, document how to restore them
- Alter comments syntax to match project templating syntax: `[# This is a comment now #]`.
- Document and test the way to restore Jinja2 default syntax. This is not obvious otherwise.
- Update Jinja docs location.

@Tecnativa TT20357
2019-11-20 10:26:39 +00:00
Jairo Llopis
fe0c072c83
Skip files and folders if their names evaluate to ""
Fix #94.
2019-11-20 08:15:25 +00:00
Ben Felder
e13dcee75c
Merge pull request #99 from Tecnativa/fix-91
Ignore $file if $file.tmpl exists
2019-11-19 17:33:50 +01:00
Jairo Llopis
f27986b1ee
Ignore $file if $file.tmpl exists
Fix #91.
2019-11-19 13:35:21 +00:00
Jairo Llopis
f779a96ff4
Remove unused type comments to fix travis 2019-11-19 13:27:49 +00:00
Juan-Pablo Scaletti
c099dad20b Update the URLs in the README 2019-10-28 11:11:22 -05:00
Juan-Pablo Scaletti
61d532f94c
Merge pull request #81 from pykong/refactor_render
Refactoring to render
2019-10-06 20:37:32 -05:00
Juan-Pablo Scaletti
e2a1365804
Merge pull request #70 from pykong/yaml_regex
Basing config file identification on regex
2019-10-06 20:34:59 -05:00
Ben Felder
8e69af7679
Upped pydantic version. 2019-10-04 21:22:10 +02:00
Ben Felder
25ab88f1c5
Upped pydantic version. 2019-10-04 21:03:34 +02:00
Ben Felder
06ccd92de3
Fixed unresolved symbol in printf_exception. 2019-10-04 20:54:41 +02:00
Ben Felder
1e8603701a
Merge branch 'master' into refactor_render 2019-10-04 20:46:03 +02:00
Ben Felder
3b88ae8c0d
Adapted ConfigData to pydantic 1.0. 2019-10-04 20:42:05 +02:00
Juan-Pablo Scaletti
4202cfb172
Merge pull request #82 from pykong/refs
Moving reference files to own folder
2019-10-03 15:21:24 -05:00
Juan-Pablo Scaletti
be4c17c2a4
Merge pull request #80 from pykong/skip_force
Enforcing mutual exclusivity of skip and force.
2019-10-03 15:20:19 -05:00
Juan-Pablo Scaletti
8a98aa4a5c
Merge pull request #76 from pykong/hardening_cli
Tests and refactorings for CLI
2019-10-03 15:19:51 -05:00
Juan-Pablo Scaletti
ae40126ff1
Merge pull request #73 from pykong/more_cleanups
Miscellaneous improvements
2019-10-03 15:18:52 -05:00
Juan-Pablo Scaletti
65499b18d6
Merge pull request #72 from pykong/better_configfile_error
Improvements to config file related exceptions.
2019-10-03 15:18:22 -05:00
Ben Felder
736f34cc5c
Merge branch 'master' into hardening_cli 2019-10-02 20:23:56 +02:00
Ben Felder
94b91857b2
Merge branch 'master' into more_cleanups 2019-10-02 20:16:55 +02:00
Ben Felder
8054f925bb
Moved reference files to tests/reference_files/ 2019-09-29 01:49:51 +02:00
Ben Felder
813d5acc3c
Some cleanups to signatures. 2019-09-29 01:18:42 +02:00
Ben Felder
0242b4041d
Cleanups to prompt_bool. 2019-09-29 00:08:48 +02:00
Ben Felder
a71ceda1df
Moved style to dedicated class. 2019-09-29 00:00:39 +02:00
Ben Felder
1a1b46d032
Refactored rendering helpers. 2019-09-28 22:44:52 +02:00
Ben Felder
fa9b96fe7f
Refactored file identity check. 2019-09-28 22:26:49 +02:00
Ben Felder
e7647f548d
Refactored render_file. 2019-09-28 21:49:37 +02:00
Ben Felder
900b445e31
Moved handling of quiet flag to printf. 2019-09-28 18:54:40 +02:00
Ben Felder
42c13f822b
Enforcing mutual exclusivity of skip and force. 2019-09-28 15:26:11 +02:00