Skip to content

Commit c271a8f

Browse files
snomiaoweb-flowclaude
committed
refactor: use shopen instead of manual launch_editor (ported from insanum#767)
Replace the hand-rolled launch_editor utility (which tried editor/EDITOR/ xdg-open/open in sequence) with the shopen library. Removes subprocess and os imports from utils.py. Conflict-resolved against main. Co-Authored-By: David Barnett <noreply@github.com> Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent a11d2c9 commit c271a8f

3 files changed

Lines changed: 4 additions & 23 deletions

File tree

gcalcli/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
from argparse import ArgumentTypeError
4141
from collections import namedtuple
4242

43+
import shopen
44+
4345
from . import config, env, utils
4446
from .argparsers import get_argument_parser, handle_unparsed
4547
from .exceptions import GcalcliError
@@ -347,7 +349,7 @@ def main():
347349
config_filepath.parent.mkdir(parents=True, exist_ok=True)
348350
with open(config_filepath, 'w') as f:
349351
f.write(EMPTY_CONFIG_TOML)
350-
utils.launch_editor(config_filepath)
352+
shopen.open(config_filepath, 'edit')
351353

352354
elif parsed_args.command == 'util':
353355
if parsed_args.subcommand == 'config-schema':

gcalcli/utils.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
from collections import OrderedDict
33
import json
44
import locale
5-
import os
65
import pathlib
76
import pickle
87
import re
9-
import subprocess
108
import time
119
from datetime import datetime, timedelta
1210
from typing import Any, Tuple
@@ -207,26 +205,6 @@ def localize_datetime(dt):
207205
return dt.astimezone(tzlocal())
208206

209207

210-
def launch_editor(path: str | os.PathLike):
211-
if hasattr(os, 'startfile'):
212-
os.startfile(path, 'edit')
213-
return
214-
for editor in (
215-
'editor',
216-
os.environ.get('EDITOR', None),
217-
'xdg-open',
218-
'open',
219-
):
220-
if not editor:
221-
continue
222-
try:
223-
subprocess.call((editor, path))
224-
return
225-
except OSError:
226-
pass
227-
raise OSError(f'No editor/launcher detected on your system to edit {path}')
228-
229-
230208
def shorten_path(path: pathlib.Path) -> pathlib.Path:
231209
"""Try to shorten path using special characters like ~.
232210

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies = [
3535
"platformdirs",
3636
"pydantic",
3737
"python-dateutil",
38+
"shopen >= 0.2.2",
3839
"tomli; python_version < '3.11'",
3940
"truststore",
4041
]

0 commit comments

Comments
 (0)