Skip to content

Commit

Permalink
windows: work around weird bug in exec/Path
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Feb 16, 2021
1 parent 313fd25 commit 8ec3a24
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/promnesia/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import List, Tuple, Optional, Dict, Sequence, Iterable, Iterator
from pathlib import Path
from datetime import datetime
from subprocess import check_call
from .compat import check_call
from tempfile import TemporaryDirectory


Expand Down Expand Up @@ -174,7 +174,7 @@ def config_check(args) -> None:


def _config_check(cfg: Path) -> Iterable[Exception]:
from subprocess import run
from .compat import run

logger.info('config: %s', cfg)

Expand Down Expand Up @@ -231,7 +231,7 @@ def cli_doctor_db(args) -> None:
sys.exit(1)
cmd = [bro, str(db)]
logger.debug(f'Running {cmd}')
from subprocess import Popen
from .compat import Popen
Popen(cmd)


Expand Down
4 changes: 2 additions & 2 deletions src/promnesia/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def file(cls, path: PathIsh, line: Optional[int]=None, relative_to: Optional[Pat
@lru_cache(1)
def _detect_mime_handler() -> str:
def exists(what: str) -> bool:
from subprocess import run, PIPE
from .compat import run, PIPE
try:
r = run(f'xdg-mime query default x-scheme-handler/{what}'.split(), stdout=PIPE)
except FileNotFoundError:
Expand Down Expand Up @@ -419,7 +419,7 @@ def traverse(root: Path, *, follow: bool=True) -> Iterable[Path]:
yield from (Path(r) / f for f in files)
return

from subprocess import Popen, PIPE
from .compat import Popen, PIPE
cmd = ['find', *find_args(root, follow=follow)]
# try to use fd.. it cooperates well with gitignore etc, also faster than find
for x in ('fd', 'fd-find', 'fdfind'): # has different names on different dists..
Expand Down
27 changes: 27 additions & 0 deletions src/promnesia/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path
from typing import Union, Sequence, List, TYPE_CHECKING

PathIsh = Union[Path, str]


Paths = Sequence[PathIsh]

# TLDR: py37 on windows has an annoying bug.. https://github.com/karlicoss/promnesia/issues/91#issuecomment-701051074
def _fix(args: Paths) -> List[str]:
return list(map(str, args))

import subprocess

def run(args: Paths, **kwargs) -> subprocess.CompletedProcess:
return subprocess.run(_fix(args), **kwargs)

def check_call(args: Paths, **kwargs) -> None:
subprocess.check_call(_fix(args), **kwargs)

def check_output(args: Paths, **kwargs) -> bytes:
return subprocess.check_output(_fix(args), **kwargs)

def Popen(args: Paths, **kwargs) -> subprocess.Popen:
return subprocess.Popen(_fix(args), **kwargs)

PIPE = subprocess.PIPE
2 changes: 1 addition & 1 deletion src/promnesia/sources/shellcmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
import re
from subprocess import check_call, check_output
from ..compat import check_call, check_output
from typing import Optional
from urllib.parse import unquote

Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/sources/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pathlib import Path
import re
from subprocess import check_call
from ..compat import check_call
from typing import Iterable

from ..common import Extraction, PathIsh, get_tmpdir, slugify
Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/sources/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pathlib import Path
import re
from subprocess import check_call, run
from ..compat import check_call, run
from typing import Iterable

from ..common import Extraction, PathIsh, get_tmpdir, slugify, get_logger
Expand Down

0 comments on commit 8ec3a24

Please sign in to comment.