27 Commits

Author SHA1 Message Date
Sigurd Spieckermann
ef5ea4b212 refactor: rename internal modules with a _ prefix 2025-04-22 13:52:51 +02:00
danieleades
1c2f8d8b08
style: use pathlib 2025-02-26 17:42:21 +01:00
jeanluc
5ac93ee199
fix(updating): do not recreate deleted paths on update (#1719)
Previously, paths that matched a pattern in `skip_if_exists` and that were deleted in the generated project were recreated during each update. This was expected, because the file now didn't exist, and thus it's considered new. However, it might be surprising to some, so docs are updated and a test now makes that an officially supported use case.

For the rest of files, they shouldn't be recreated, even if the template changed. A user that deletes the file is kind of expressing their will to ignore that file from now on. To recover it, they can just recopy the template.

BREAKING CHANGE: If you delete a file in your subproject, it will not be recreated if it changes in the template and you update the subproject. Recopy if you need it back.
2024-08-17 08:44:09 +02:00
Sigurd Spieckermann
0258635da7 fix: support Git config without user identity 2024-07-30 13:40:17 +02:00
Timothée Mazzucotelli
2fa73ddb2c fix: Normalize paths obtained from Git commands output 2023-11-22 15:34:24 +00:00
Sigurd Spieckermann
a82c0ad6bf
refactor: drop support for Python 3.7 (#1252) 2023-07-18 19:59:05 +01:00
Sigurd Spieckermann
5029b6e7a9
test: add type hints and clean up (#985)
* refactor(tests): add type hints and clean up

* fix: import `Protocol` from `typing-extensions` when using Python 3.7

* fix: import `Literal` from `typing-extensions` when using Python 3.7

* refactor(tests): create template and subproject directory using `tmp_path_factory` fixture

* refactor(tests): use OS-agnostic file path separator

* refactor(tests): use `/` separator for `skip_if_exists` paths

* style: fix formatting error

* refactor(tests): expect POSIX path for local repo URL
2023-03-21 16:31:11 +00:00
Jairo Llopis
67cc4ffde3
feat: nix support
- Provide a dev shell.
- Provide a nix package.
- Provide a nix flake.
- Development environment based on direnv.
- Docs.
- Configure Gitpod to use direnv and nix.
- Configure Cachix out of the box, and document how to use it.
- Add direnv and nix to CI.
- Satisfy some linters that came from Precommix, even when Precommix was later discarded.
- Mark some tests as impure.
- Run only pure tests when building Copier with Nix.
- Add poetry loader to direnv.
- Update contribution guide.
2023-01-18 09:40:08 +00:00
Jairo Llopis
e9557f75f7 test(pre-commit): fix false positives
The falsy return code was truthy when evaluated by Python.
2022-01-11 19:56:12 +01:00
Timothée Mazzucotelli
76d6c2f502
Fix temporary directory removal on Windows (#358)
* tests: Add temporary directory deletion tests

* ci: Run tests on Windows for Python 3.6 and 3.7 again

* fix: Implement more robust temporary directory deletion

* docs: Document temporary directory class and error handler

* chore: Update poetry.lock

* style: Format code

Co-authored-by: Timothée Mazzucotelli <timothee.mazzucotelli@externe.e-i.com>
2021-03-04 16:05:52 +00:00
Jairo Llopis
0441b86f0c
Refactor (#314)
* Refactor
* Fix #110.
* Rewrite test_config_exclude, test_config_exclude_overridden and test_config_include. These tests were badly designed, using a monkeypatch that would never happen in the real world, and actually producing false positives. I moved them to test_exclude.py and rewritten to test the what and not the how.
* Fix #214 by removing skip option. Relevant tests use the better skip_if_exists=["**"].
* Remove subdirectory flag from API/CLI. It was confusing and could lead to bad maintenance situations. Fixes #315.
* Remove extra_paths and fix #321
* Remember that you cannot use _copier_conf.src_path as a path now
* use dataclasses
* Create errors module, simplify some tests, fix many others
* Fix some tests, complete EnvOps removal
* Fix #214 and some tests related to it
* Reorder code
* Update docs and imports
* Modularize test_complex_questions
* Interlink worker and questionary a bit better
* Removal of Questionary class, which only had 1 meaningful method that is now merged into Worker to avoid circular dependencies.
* Fix #280 in a simple way: only user answers are type-casted inside API, and CLI transforms all `--data` using YAML always. Predictable.
* Use prereleases correctly.
* Reorder AnswersMap to have a more significative repr.
* Simpler cache for old `Question.get_choices()` method (renamed now).
* fix wrong test
* Fix test_subdirectory
* Fix test_tasks (and remove tests/demo_tasks)
* Fix path filter tests, and move it to test_exclude, where it belongs
* Make test_config pass
* Fix more wrongly designed tests
* Use cached_property backport if needed
* xfail test known to fail on mac
* force posix paths on windows
* Add typing_extensions for python < 3.8
* Sort dependencies in pyproject.toml
* Support python 3.6 str-to-datetime conversion
* Workaround https://bugs.python.org/issue43095
* xfail test_path_filter on windows
* Upgrade mkdocs and other dependencies to fix https://github.com/pawamoy/mkdocstrings/issues/222
* Add missing reference docs.
* Add workaround for https://github.com/pawamoy/mkdocstrings/pull/209
* Docs.
* Remove validators module
* Add workaround for https://github.com/pawamoy/mkdocstrings/issues/225
* Restore docs autorefs as explained in https://github.com/pawamoy/mkdocstrings/issues/226#issuecomment-775413562.
* Workaround https://github.com/pawamoy/pytkdocs/issues/86
2021-02-09 18:22:47 +00:00
Jairo Llopis
cda93273c1
Enhanced user input (#260)
* use a new toolkit for user prompting: questionary (patched).
* multiline questions.
* conditional questions.
* new toolkit for ui tests: pexpect.
* fix lots of tests.
* fix windows builds with newer poetry-dynamic-versioning.
* linters and mypy are now tests, to have faster ci.
* update deprecated ci commands.
* removed dependencies from old times.
* Remove toml 0.5+ syntax (dotted keys)
* Use powershell where syntax is compatible
* Change skip to xfail
* xfail pexpect tests on windows. I'm tired of trying to make it work
* more docs
* possibly something more.
2020-10-12 08:56:46 +01:00
Jairo Llopis
823f3a1935 Remove dst fixture
This is redundant with pytest's native `tmp_path` fixture, so we use that one instead now.
2020-06-23 07:58:03 +00:00
Jairo Llopis
f7aee2857d Remember answer procedence
- `ConfigData` objects now know where do answers come from.
- Their `.data` attribute is now a computed property that merges all those answer sources in priority order.
- To merge dicts, `ChainMap` is used extensively.
- `query_user_data` gets both `last_answer_data` and `forced_answers_data` instead of the single `answers_data` argument it got before.
- By knowing where does an answer come from, now Copier avoids asking something if the user already answered that from other source. For example, if you use `copier -d some_question=some_answer copy $src $dst`, then Copier will not ask you about `some_question` again, because you already answered that. 🎉
- All answer sources are deep-copied to avoid modifying mutable dicts and affecting further copier executions.
- A minimal amount of tests got updated as they were now supposed to fail with new behavior.
- Ignore flake8 `E501 line too long` errors. We use black, that's just unnecessarily annoying.

@Tecnativa TT23705
2020-06-18 09:24:58 +01:00
Ben Felder
251fe2b2fe
Remove unused imports in tools.py 2020-02-26 20:13:45 +01:00
Ben Felder
e7620aacce
Add test_create_path_filter 2020-02-26 17:03:44 +01:00
Jairo Llopis
fc6b364321
Reduce code complexity
As explained in #110, the dangling parameters for methods keep on complicating development.

A full code refactoring is too much work for now, but I did a little refactoring which consists in:

- Merge `Flags` into `ConfigData`, and remove anything related exclusively to flags.
- Any method that uses arguments from `ConfigData` gets instead a `conf: ConfigData` argument.
- `get_jinja_renderer()` removed; it's not useful as its little work can easily be done by `Renderer` itself.

This way, whenever we need a new config, we can just add it to `ConfigData` and use it more widely.

A full refactoring is still needed IMHO, where we have a main `Copier` class which handles its state and everything it needs (or it could be `CopierApp` instead), but that's more a design decision to be taken by the project leader.

@Tecnativa TT20357
2020-02-21 11:11:49 +00:00
Ben Felder
8054f925bb
Moved reference files to tests/reference_files/ 2019-09-29 01:49:51 +02:00
Ben Felder
b22488ff87
Formatted imports via isort. 2019-09-14 15:11:17 +02:00
Ben Felder
82ddf4adb7
Merged origin/master to solve conflicts. 2019-08-29 22:32:46 +02:00
Ben Felder
69760a583a Cleaned up imports. 2019-08-08 23:16:47 +02:00
Ben Felder
72ccdb66ba Moved config into its own submodule. 2019-07-20 22:55:51 +02:00
Ben Felder
4278dcb676 Moved default env options to conf. 2019-07-20 22:09:20 +02:00
Ben Felder
b5c8791b85 Cleanup up on tests. 2019-07-11 19:11:29 +02:00
Juan-Pablo Scaletti
5b52b37662 pathlib.Path ALL the paths! 2019-04-03 23:22:25 -05:00
Juan-Pablo Scaletti
9c9f5e7821 black-styled 2019-03-07 22:07:51 -05:00
Juan-Pablo Scaletti
5cea5d7ac7 Voodoo -> Copier 2019-02-11 22:32:34 -05:00