Skip to content

Support command line options in EDITOR/GIT_EDITOR #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions blurb/blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,29 @@ def test(*args):
print(tests_run, "tests passed.")


def resolve_command(s):
# "unquoted path to editor"?
if os.path.exists(s):
return [s]
# "'quoted path to editor' -with -options"?
args = shlex.split(s, posix=os.name == 'posix')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned two new things today! The "posix" argument to shlex.split, and os.name is usually "posix".

if os.path.exists(args[0]):
return args
raise ValueError("Cannot find editor")


def find_editor():
# Try relevant environment variables; if set, the value must be valid.
for var in 'GIT_EDITOR', 'EDITOR':
editor = os.environ.get(var)
if editor is not None:
return editor
value = os.environ.get(var)
if value is None:
continue
try:
return resolve_command(value)
except ValueError as e:
error('Invalid %r environment variable %r: %s.' % (var, value, e))

# If not configured, fallback to platform specific user friendly editor.
if sys.platform == 'win32':
fallbacks = ['notepad.exe']
else:
Expand All @@ -864,7 +882,7 @@ def find_editor():
else:
found_path = shutil.which(fallback)
if found_path and os.path.exists(found_path):
return found_path
return [found_path]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug fix folded in with the rest of the PR? I appreciate it, I just want to double-check. It doesn't look like the rest of the PR touches found_path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks like a bug fix, I can split it to another PR if you like.

error('Could not find an editor! Set the EDITOR environment variable.')


Expand All @@ -874,11 +892,12 @@ def add():
Add a blurb (a Misc/NEWS entry) to the current CPython repo.
"""

editor = find_editor()
editor_command = find_editor()

handle, tmp_path = tempfile.mkstemp(".rst")
os.close(handle)
atexit.register(lambda : os.unlink(tmp_path))
editor_command.append(tmp_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like your new code is doing nice things, but then doesn't use them. editor_command is ignored after this line; I was assuming it should replace "args".

Also, the code now appends tmp_path twice. This line adds one, and then line 913 in the original (line 932 after your patch is applied) appends tmp_path to "args".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editor_command is used in line 837. I don't see the append you mention. I'll need to rebase and test this again, lot of time has passed since I sent this :-)


def init_tmp_with_template():
with open(tmp_path, "wt", encoding="utf-8") as f:
Expand Down