From 09fa3aeeb05639fd4fa251a928cbdea1328958ea Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Wed, 3 Jan 2024 18:42:04 +0100 Subject: [PATCH] migrate `editor` to a newer, up to date implementation --- poetry.lock | 62 ++++++++++++++----- pyproject.toml | 2 +- src/inquirer/render/console/_editor.py | 4 +- .../integration/console_render/test_editor.py | 22 +++---- 4 files changed, 62 insertions(+), 28 deletions(-) diff --git a/poetry.lock b/poetry.lock index 878d17d3..d095ca4b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -297,6 +297,26 @@ tomli = {version = "*", markers = "python_version < \"3.11\""} conda = ["pyyaml"] pipenv = ["pipenv (<=2022.12.19)"] +[[package]] +name = "editor" +version = "1.5.1" +description = "🖋 Open the default text editor 🖋" +category = "main" +optional = false +python-versions = ">=3.8" +files = [] +develop = false + +[package.dependencies] +runs = "*" +xmod = "*" + +[package.source] +type = "git" +url = "https://github.com/Cube707/editor" +reference = "HEAD" +resolved_reference = "75c7c0c59ef7776a340eeafc0fe7b5228f257eb2" + [[package]] name = "filelock" version = "3.13.1" @@ -833,19 +853,6 @@ files = [ [package.extras] diagrams = ["jinja2", "railroad-diagrams"] -[[package]] -name = "python-editor" -version = "1.0.4" -description = "Programmatically open an editor, capture the result." -category = "main" -optional = false -python-versions = "*" -files = [ - {file = "python-editor-1.0.4.tar.gz", hash = "sha256:51fda6bcc5ddbbb7063b2af7509e43bd84bfc32a4ff71349ec7847713882327b"}, - {file = "python_editor-1.0.4-py2-none-any.whl", hash = "sha256:5f98b069316ea1c2ed3f67e7f5df6c0d8f10b689964a4a811ff64f0106819ec8"}, - {file = "python_editor-1.0.4-py3-none-any.whl", hash = "sha256:1bf6e860a8ad52a14c3ee1252d5dc25b2030618ed80c022598f00176adc8367d"}, -] - [[package]] name = "pytz" version = "2023.3.post1" @@ -1069,6 +1076,21 @@ files = [ {file = "ruamel.yaml.clib-0.2.8.tar.gz", hash = "sha256:beb2e0404003de9a4cab9753a8805a8fe9320ee6673136ed7f04255fe60bb512"}, ] +[[package]] +name = "runs" +version = "1.2.0" +description = "🏃 Run a block of text as a subprocess 🏃" +category = "main" +optional = false +python-versions = ">=3.8" +files = [ + {file = "runs-1.2.0-py3-none-any.whl", hash = "sha256:ec6fe3b24dfa20c5c4e5c4806d3b35bb880aad0e787a8610913c665c5a7cc07c"}, + {file = "runs-1.2.0.tar.gz", hash = "sha256:8804271011b7a2eeb0d77c3e3f556e5ce5f602fa0dd2a31ed0c1222893be69b7"}, +] + +[package.dependencies] +xmod = "*" + [[package]] name = "safety" version = "2.3.5" @@ -1449,6 +1471,18 @@ files = [ {file = "wcwidth-0.2.12.tar.gz", hash = "sha256:f01c104efdf57971bcb756f054dd58ddec5204dd15fa31d6503ea57947d97c02"}, ] +[[package]] +name = "xmod" +version = "1.8.0" +description = "🌱 Turn any object into a module 🌱" +category = "main" +optional = false +python-versions = ">=3.8" +files = [ + {file = "xmod-1.8.0-py3-none-any.whl", hash = "sha256:11ae15c4e14d4cd7f62131d269053ad0e16199fc2aeda9431a375038c06f11ac"}, + {file = "xmod-1.8.0.tar.gz", hash = "sha256:429ff6bbfdcc2864f1d3a640d09349aeff880150c0a0da2efb51e0d85b8ec447"}, +] + [[package]] name = "zipp" version = "3.17.0" @@ -1468,4 +1502,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.8.1" -content-hash = "f3a2817f41dd03b75b6237b0c934b4380d236cb89fe0cd7b778c64c864f6fc61" +content-hash = "ffed4447f67c7eeaa4f8bd6a2a47a3a001fe4227cdb62164ee9d25d6b80ee038" diff --git a/pyproject.toml b/pyproject.toml index f4866fc0..d70b3b7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ classifiers = [ python = ">=3.8.1" blessed = ">=1.19.0" readchar = ">=3.0.6" -python-editor = ">=1.0.4" +editor = { git = "https://github.com/Cube707/editor" } # ">=1.5.1" # TODO: waiting for https://github.com/rec/editor/pull/8 [tool.poetry.dev-dependencies] bandit = ">=1.7.4" diff --git a/src/inquirer/render/console/_editor.py b/src/inquirer/render/console/_editor.py index 01b66b26..324e5091 100644 --- a/src/inquirer/render/console/_editor.py +++ b/src/inquirer/render/console/_editor.py @@ -28,8 +28,8 @@ def process_input(self, pressed): raise KeyboardInterrupt() if pressed in (key.CR, key.LF, key.ENTER): - data = editor.edit(contents=self.question.default or "") - raise errors.EndOfInput(data.decode("utf-8")) + data = editor(text=self.question.default or "") + raise errors.EndOfInput(data) raise errors.ValidationError( "You have pressed unknown key! " "Press to open editor or " "CTRL+C to exit." diff --git a/tests/integration/console_render/test_editor.py b/tests/integration/console_render/test_editor.py index 5ed89a22..eeb56b95 100644 --- a/tests/integration/console_render/test_editor.py +++ b/tests/integration/console_render/test_editor.py @@ -16,9 +16,9 @@ def setUp(self): def tearDown(self): self.base_teardown() - @patch("editor.edit") - def test_basic_render(self, edit): - edit.return_value = b"Some text" + @patch("inquirer.render.console._editor.editor") + def test_basic_render(self, editor): + editor.return_value = "Some text" stdin = [key.ENTER] message = "Foo message" variable = "Bar variable" @@ -30,11 +30,11 @@ def test_basic_render(self, edit): self.assertEqual("Some text", result) self.assertInStdout(message) - self.assertTrue(edit.called) + self.assertTrue(editor.called) - @patch("editor.edit") + @patch("inquirer.render.console._editor.editor") def test_ignore_true_should_return(self, edit): - edit.return_value = b"Some text" + edit.return_value = "Some text" stdin = [key.ENTER] message = "Foo message" variable = "Bar variable" @@ -49,10 +49,10 @@ def test_ignore_true_should_return(self, edit): self.assertNotInStdout(message) self.assertFalse(edit.called) - @patch("editor.edit") + @patch("inquirer.render.console._editor.editor") def test_validation_fails(self, edit): stdin = [key.ENTER, key.ENTER] - edit.side_effect = [b"Only one line", b"Two\nLines\nCool"] + edit.side_effect = ["Only one line", "Two\nLines\nCool"] message = "Insert number" variable = "foo" @@ -70,10 +70,10 @@ def val(_, x): self.assertInStdout("Entered value is not a valid foo") self.assertTrue(edit.called) - @patch("editor.edit") + @patch("inquirer.render.console._editor.editor") def test_validation_fails_with_custom_error(self, edit): stdin = [key.ENTER, key.ENTER] - edit.side_effect = [b"Only one line", b"Two\nLines\nCool"] + edit.side_effect = ["Only one line", "Two\nLines\nCool"] message = "Insert number" variable = "foo" @@ -94,7 +94,7 @@ def val(_, x): self.assertInStdout("Some bad reason") self.assertTrue(edit.called) - @patch("editor.edit") + @patch("inquirer.render.console._editor.editor") def test_ctrl_c_breaks_execution(self, edit): stdin = [key.CTRL_C] message = "Foo message"