diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 359355ad1..7dfc29e19 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -95,6 +95,12 @@ def is_path(x: str) -> str: return x +def is_path_or_empty(x: str) -> str: + if x == '': + return x + return is_path(x) + + def allow_empty(x: str) -> str: return x @@ -222,7 +228,10 @@ def ask_user(d: Dict) -> None: 'selected root path.'))) print(__('sphinx-quickstart will not overwrite existing Sphinx projects.')) print() - sys.exit(1) + d['path'] = do_prompt(__('Please enter a new root path (or just Enter to exit)'), + '', is_path_or_empty) + if not d['path']: + sys.exit(1) if 'sep' not in d: print() diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 4ee5535cb..86c9cc6da 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -123,6 +123,7 @@ def test_quickstart_defaults(tempdir): assert (tempdir / 'Makefile').isfile() assert (tempdir / 'make.bat').isfile() + def test_quickstart_all_answers(tempdir): answers = { 'Root path': tempdir, @@ -251,12 +252,13 @@ def test_extensions(tempdir): exec(conffile.read_text(), ns) assert ns['extensions'] == ['foo', 'bar', 'baz'] + def test_exits_upon_existing_confpy(monkeypatch): # The code detects existing conf.py with isfile() so we mock it def mock_isfile(path): return True monkeypatch.setattr(path, 'isfile', mock_isfile) - + qs.term_input = mock_input({}) d = {} with pytest.raises(SystemExit):