From d9c95d5a1b1824fb58b16b7edeacdc5cad896e90 Mon Sep 17 00:00:00 2001 From: Joshua Greenhalgh Date: Fri, 3 May 2019 17:06:09 +0200 Subject: [PATCH 1/3] Update editor.py Add default args for using vscode --- editor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/editor.py b/editor.py index 6fc73f1..b44ad3c 100755 --- a/editor.py +++ b/editor.py @@ -46,6 +46,9 @@ def get_editor_args(editor): elif editor == 'nano': return ['-R'] + + elif editor == 'code': + return ["-w", "-n"] else: return [] From 3bfd564813d4e35267db46f1e2d4ce4e53fd91bf Mon Sep 17 00:00:00 2001 From: Philip Bergen Date: Thu, 20 Jan 2022 16:00:19 -0800 Subject: [PATCH 2/3] Move the import of disutils.spawn into the scope where it is actually being used so that inquirer can mostly function on default ubuntu python. --- editor.py | 17 +++++++++++++---- setup.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/editor.py b/editor.py index b44ad3c..39cc942 100755 --- a/editor.py +++ b/editor.py @@ -8,8 +8,6 @@ import os.path import subprocess import tempfile -from distutils.spawn import find_executable - __all__ = [ 'edit', @@ -17,7 +15,7 @@ 'EditorError', ] -__version__ = '1.0.4' +__version__ = '1.0.5' class EditorError(RuntimeError): @@ -46,7 +44,7 @@ def get_editor_args(editor): elif editor == 'nano': return ['-R'] - + elif editor == 'code': return ["-w", "-n"] @@ -55,6 +53,17 @@ def get_editor_args(editor): def get_editor(): + # The import from distutils needs to be here, at this low level to + # prevent import of 'editor' itself from breaking inquirer. This + # has to do with ubuntu (debian) python packages artificially + # separated from distutils. + # + # If this import is at top level inquirer breaks on ubuntu until + # the user explicitly apt-get install python3-distutils. With the + # import here it will only break if the code is utilizing the + # inquirer editor prompt. + from distutils.spawn import find_executable + # Get the editor from the environment. Prefer VISUAL to EDITOR editor = os.environ.get('VISUAL') or os.environ.get('EDITOR') if editor: diff --git a/setup.py b/setup.py index d1a9081..b0faf89 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -__VERSION__ = '1.0.4' +__VERSION__ = '1.0.5' from setuptools import setup From 5023fafd265add111b29baca59b07f140daf75b7 Mon Sep 17 00:00:00 2001 From: Branch Vincent Date: Sun, 8 Oct 2023 12:52:53 -0700 Subject: [PATCH 3/3] support python 3.12 Python 3.12 has removed `distutils`: https://docs.python.org/3.12/whatsnew/3.12.html#removed --- editor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/editor.py b/editor.py index 39cc942..54a3760 100755 --- a/editor.py +++ b/editor.py @@ -62,7 +62,10 @@ def get_editor(): # the user explicitly apt-get install python3-distutils. With the # import here it will only break if the code is utilizing the # inquirer editor prompt. - from distutils.spawn import find_executable + try: + from distutils.spawn import find_executable + except ImportError: + from shutil import which as find_executable # Get the editor from the environment. Prefer VISUAL to EDITOR editor = os.environ.get('VISUAL') or os.environ.get('EDITOR')