33 Commits

Author SHA1 Message Date
Sigurd Spieckermann
2491c0681b refactor: re-expose API with deprecation warnings on non-public API imports 2025-04-22 13:52:51 +02:00
Sigurd Spieckermann
ef5ea4b212 refactor: rename internal modules with a _ prefix 2025-04-22 13:52:51 +02:00
Sigurd Spieckermann
b42a032f7b style: fix formatter and linter errors 2025-04-22 12:20:23 +02:00
Sigurd Spieckermann
8815034a93 fix: restore access to full rendering context in prompt phase 2025-03-11 14:17:30 +01:00
Sigurd Spieckermann
ede686561d test: use helper function to load answers file data 2025-03-07 12:21:36 +01:00
Axel H.
c46c599c00 test(warnings): assert FutureWarnings are raised 2025-03-03 14:37:27 +01:00
Axel H.
1dabe8eb1e
feat(context): expose a _copier_phase context variable 2025-03-02 16:40:57 +01:00
Sigurd Spieckermann
b5ef194328 feat: add support for dynamic choices 2024-10-18 19:41:34 +01:00
Sigurd Spieckermann
0258635da7 fix: support Git config without user identity 2024-07-30 13:40:17 +02:00
Sigurd Spieckermann
51fdd3b9a4 fix(updating): unset invalid last answers 2024-04-20 07:40:48 +01:00
Sigurd Spieckermann
69662e3a7c fix: render default list items for multi-select choice questions 2024-04-18 15:37:21 +02:00
Sigurd Spieckermann
8904d4c179 test: remove useless file in test template tree 2024-04-16 18:19:05 +02:00
danieleades
0c6b0b96fe
build(typing): enable 'strict' mypy linting (#1527)
---------

Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
2024-03-23 12:58:20 +01:00
danieleades
878c4d4f40
style: add 'flake-future-annotations' lint group (#1506)
* add ruff 'flake8-future-annotations' (FA) lint group
2024-02-22 06:19:17 +00:00
Jairo Llopis
6996b9cc7a feat: add recopy command and function
This new command allows to reapply a template, keeping old answers but discarding subproject evolution.

It is useful when there are bugs replaying an old version of the template, or when the subproject has drifted too much from the template and you need to reset it.

BREAKING CHANGE: All CLI calls to Copier must now include the subcommand as the 1st argument. For example, `copier` must become now `copier update`; also `copier ./tpl ./dst` must become `copier copy ./tpl ./dst`.

BREAKING CHANGE: All flags must go after the subcommand now. For example, `copier -r HEAD update ./dst` must now become `copier update -r HEAD ./dst` or `copier update ./dst -r HEAD`.

BREAKING CHANGE: Automatic mode removed. Since now subcommands are required, the automatic mode is removed.

BREAKING CHANGE: Deprecated `copier.copy` function is removed. Use `copier.run_copy`, `copier.run_update` or `copier.run_recopy` explicitly as needed.

Fix https://github.com/copier-org/copier/issues/1081
Close https://github.com/copier-org/copier/issues/1082
2023-05-17 11:56:13 +01:00
Sigurd Spieckermann
f6f37ab4fb
feat: support conditional choices (#1010)
Choices can now be validated with a custom inline jinja template.

Disabled choices won't be selectable, and they display a message telling why.
2023-05-04 09:13:18 +01:00
Sigurd Spieckermann
065d6ba1d0
fix: require answer for questions without default value (#958)
When questions didn't have a default answer, the interactive behavior was confusing.

Fixes https://github.com/copier-org/copier/issues/355.

BREAKING CHANGE: All default answers must be explicit now.
2023-04-07 08:09:27 +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
Paul Moore
c5d46100a6
tests: refactor the tests to only depend on the prompt format in one place (#682)
* refactor(tests): refactor the tests to only depend on the prompt format in one place

* Address review comments
2022-05-28 08:42:19 +00:00
David Stanek
004c90ffc9 test: fix date comparison not working in my timezone
The now() template builtin is being used in the test and is an alias
for datetime.utcnow(). The now however, just uses datetime.now(). This
means that my datetime.now() will always make this test fail.

Signed-off-by: David Stanek <dstanek@dstanek.com>
2022-02-09 20:48:55 +00:00
Jairo Llopis
7b7a0b4f34 fix(mypy): 💚 add missing typing
Includes workarounds for https://github.com/tmbo/questionary/pull/191 and https://github.com/samuelcolvin/pydantic/pull/3175.
2022-01-11 19:56:12 +01:00
Timothée Mazzucotelli
3425db5b96 tests: Use datetime.fromisoformat 2021-12-17 22:22:37 +01:00
Dennis Roche
a1fcccf906 test: Replace force=True with defaults=True, overwrite=True 2021-07-02 15:34:51 +01:00
Jairo Llopis
3b63b6057b fix: restore templated choice keys and types
Last commit removed some false positives in tests and revealed these regressions.

Some tests are modified to reveal reality.
2021-06-11 07:19:46 +01:00
Jairo Llopis
5411276c8b fix: wrong usage of expect_exact([...])
I was expecting that calls in this form matched all strings in sequence. It turns out that [the docs][1] clearly state that it only tries to match one of them.

Thus, fixing the tests to avoid false positives.

[1]: https://pexpect.readthedocs.io/en/stable/api/pexpect.html?highlight=expect_exact#pexpect.spawn.expect_exact
2021-06-11 07:19:46 +01:00
Jairo Llopis
0500a617c0 test: make spawned processes debuggable
Implement the workaround from https://github.com/microsoft/debugpy/issues/596#issuecomment-824643237 to allow debugging pexpect subprocesses.
2021-04-23 17:45:25 +01:00
Jairo Llopis
1482de4972
wip 2021-03-05 17:33:11 +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
a15da2d511 Run updated pre-commit 2020-10-16 11:47:57 +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
Timothée Mazzucotelli
59f1f3a8ee Add prompt templating 2020-04-29 12:45:42 +02:00