53 Commits

Author SHA1 Message Date
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
abd5d574e3 feat: raise InteractiveSessionError when prompting in non-interactive environment 2025-03-14 11:13:48 +01:00
Sigurd Spieckermann
ede686561d test: use helper function to load answers file data 2025-03-07 12:21:36 +01:00
Jairo Llopis
fd23923b5c
style(ruff-format): enable and reformat Python files
Until now, only linting was enabled. My failure.

I added this setting to widen the code style automation. I also enabled [keep-runtime-typing](https://docs.astral.sh/ruff/settings/#lint_pyupgrade_keep-runtime-typing) because we use Pydantic.

Finally, I executed the new formatting over all the project.
2024-12-03 13:59:00 +01:00
Sigurd Spieckermann
2421d77e08 fix: validate answers to secret questions 2024-09-21 06:52:16 +01:00
Sigurd Spieckermann
0258635da7 fix: support Git config without user identity 2024-07-30 13:40:17 +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
Sigurd Spieckermann
4ff30e8a98 feat: add support for validating multi-select choice answers 2024-03-09 20:06:02 +00: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
Axel H
99bdd11b68 feat(choices): support questionary checkbox for multiple choices using multiselect: true.
Fixes #218
2023-10-30 18:29:55 +00:00
Jairo Llopis
ec5e86995e feat: add -A as an alias for --skip-answered, and support it in recopy too 2023-09-04 22:28:54 +01:00
Oleksii Siechko
8619fc8a68
feat: add --skip-answered flag to avoid repeating recorded answers
This change addresses a usability issue troubling users when they run 'copier update'. Previously, each time 'copier update' was run, the user had to review all responses given in the answers file. This was a repetitive and laborious process, particularly for users dealing with extensive templates.

This PR introduces a new flag --skip-answered to improve the user experience and reduce friction during updates. The new flag allows users to bypass the review of questions already answered in the past. It automatically pulls responses from the answers file and presents only the newly added template questions to the user for their review.

`skip-answered` will skip all answered questions and ask user input only for new inputs if they are present.

Fixes #1178

Co-authored-by: Jairo Llopis <973709+yajo@users.noreply.github.com>
2023-09-03 21:15:49 +00:00
Sigurd Spieckermann
1e81fd5eca
feat: add support for computed values via skipped questions (#1220)
* feat: add support for computed values via skipped questions

* docs: apply review suggestions

Co-authored-by: Jairo Llopis <973709+yajo@users.noreply.github.com>

* docs: update inline comments

* docs: fix formatting

---------

Co-authored-by: Jairo Llopis <973709+yajo@users.noreply.github.com>
2023-07-08 10:36:21 +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
aca16a020b
fix: skip validating question and generating its default value when its skip condition is met
I've indirectly fixed the validation of answers to questions for which the skip condition is met. Before, a question with a truthy skip condition was not properly skipped such that (a) its default value (if present) was still validated and could cause a validation error or (b) an error was raised that the question was required although it should have been skipped. As a side effect of the previous implementation (which didn't properly skip questions), answers of skipped questions were recorded in the answers file which IMO makes no sense.

I've changed the way skipped questions are handled such that the skip condition is evaluated early and the question is immediately skipped when the skip condition is truthy. To prevent records of such answers in the answers file, e.g. when they originate from previous runs, when they are provided by the user via the `--data` flag, etc., any answers in the internal answers map are removed (or rather marked as removed). As a result, I needed to adapt a few tests and even removed one that specifically tested for the presence of those records in the answers file.

This new behavior should be backwards compatible and is more logical in my opinion. As a side effect, some slightly confusing code block could be removed which handled some special case of using a templated default answer.

Fixes #1125.
2023-05-02 15:45:44 +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
Sigurd Spieckermann
0411473414 fix: prevent name collision for question var name "value" 2022-09-02 09:03:04 +01:00
Paul Moore
05c5f09034
feat: simplify the format of the question prompt (#689)
Closes https://github.com/copier-org/copier/issues/674
2022-06-04 11:02:37 +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
Jacob Straszynski
600ebdb492
feat: raise CopierAnswersInterrupt on partial answers (#476)
* includes a unit-y test in it's own file, tests/test_interrupts.
* includes an integration test that verifies that we don't dump
  a stacktrace. E.g. this test will fail if CopierAnswersInterrupt no
  longer subclasses KeyboardInterrupt.
* update changelog with CopierAnswersInterrupt
2021-11-15 13:29:57 +00:00
Jairo Llopis
87b93ee558 fix: multiline default values prompted
When the question is YAML or JSON and it is multiline and has a default value, that one should be prompted in multiline mode automatically.

It includes a test that will always fail (thus it is skipped). Gotta fix that some day when I'm more pro in python-prompt-toolkit stuff. For the time being, manual test is enough and this works!

I also removed some garbage found here and there.

Fixes https://github.com/copier-org/copier/issues/298.
2021-07-10 11:45:51 +01:00
Jairo Llopis
7bbd0406b8 feat: do not ask for overwriting copier answers file
The copier answers file (`.copier-answers.yml` by default) should be updated always, and everybody is almost excessively warned to NOT touch that file by hand and let Copier handle it. Thus, it makes no sense to ask users whether it should be updated on conflict.

Fixes https://github.com/copier-org/copier/issues/325.
2021-07-02 16:28:57 +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
0002cd7317 Also consider none, null and ~ as false
Enhance #305 with null values.
2020-11-11 12:01:58 +00:00
Jairo Llopis
249e959145 Allow more types when casting values as booleans
Don't be so strict, because user input is sometimes unpredictable.
2020-11-11 11:48:00 +00:00
Jairo Llopis
c93ef75521 Fix wrong default choice
When updating a project, a choice answer never got a good default value. Now it's properly selected, and interactive behavior is tested.
2020-10-23 10:52:42 +00:00
Jairo Llopis
81e03a50e2 Revert "Remove support for custom lexers temporarily"
This reverts commit 598388af30e851c34fcd9bd76ee5aad2ce2fd039 because it's no longer needed with questionary 1.7.0.
2020-10-16 11:47:57 +00:00
Jairo Llopis
598388af30 Remove support for custom lexers temporarily
When https://github.com/tmbo/questionary/pull/70 gets fixed, this commit should be rolled back.

For now, I have to remove this support because [otherwise I cannot publish Copier to Pypi](https://github.com/copier-org/copier/runs/1241180809?check_suite_focus=true).
2020-10-14 07:07:42 +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
544c248bf1 Avoid templated defaults counting as init data
Before this patch, a templated default was counting as init data because it was different from the original default after rendereing, making copier believe the user provided an answer.

This patch fixes #230 by avoiding to parse questions that have no init data answer in the step of filling `data_from_init`. Those defaults will be used later as `data_from_asking_user` if needed.
2020-07-21 08:26:35 +00:00
Jairo Llopis
403183c78d Fix wrong prompt when updating
#221 introduced a regression that made the user prompt always display the default value from `copier.yml` file instead of the last answer from `.copier-answers.yml` when the latter one was available.

Here I fix that and test it too. Added a new dev dependency (pytest-timeout) to use it in tests that expect responses from STDIN and for some reason fail to obtain them do not hang in and endless loop.

I also removed the `conftest.py` file, which was only declaring a fixture that is no longer used and can actually be fixed easily using https://stackoverflow.com/a/51893526/1468388.

@Tecnativa TT23705
2020-06-23 09:33:43 +00: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
Juan-Pablo Scaletti
9b8ce8ad17
Merge pull request #54 from pykong/cleanup
Cleanup and move to Python 3.6
2019-08-20 13:26:24 -05:00
Juan-Pablo Scaletti
75d5f0000f
Merge pull request #52 from pykong/typing
Adding type annotations
2019-08-20 13:25:21 -05:00
Juan-Pablo Scaletti
5d15e9df2f Removes top __init__ file. Fix #56 2019-08-20 13:19:32 -05:00
Ben Felder
b5c8791b85 Cleanup up on tests. 2019-07-11 19:11:29 +02:00
Ben Felder
fa85a18bda Replaced format with f-strings. 2019-07-09 19:45:53 +02:00
Ben Felder
36b0eadbd8 Some more polishing. 2019-07-06 21:07:53 +02:00
Juan-Pablo Scaletti
1c490f0160 Take No for an answer 2019-06-15 02:34:15 -05:00
Juan-Pablo Scaletti
8dae107c7c can now have an undefined default 2019-04-17 17:47:34 -05:00
Juan-Pablo Scaletti
bf8852a222 fix tests 2019-04-17 16:54:14 -05: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