Skip to content

Commit

Permalink
Fix Python 3.9 compatibility for dev env (#113)
Browse files Browse the repository at this point in the history
Fixes #112
  • Loading branch information
lkubb authored Nov 23, 2024
1 parent 1c063d9 commit 0861e88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/+py39.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed development environment compatibility with Python 3.9
19 changes: 13 additions & 6 deletions project/tools/helpers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import shlex
import shutil
import subprocess
import sys
from contextlib import contextmanager
from dataclasses import dataclass
from dataclasses import field
from pathlib import Path
from typing import Union


class CommandNotFound(RuntimeError):
Expand All @@ -28,8 +30,8 @@ class ProcessResult:
"""

retcode: int
stdout: str | bytes
stderr: str | bytes
stdout: Union[str, bytes]
stderr: Union[str, bytes]
argv: tuple

def check(self, retcode=None):
Expand Down Expand Up @@ -198,7 +200,7 @@ class Command:
A command object, can be instantiated directly. Does not follow ``Local``.
"""

exe: Executable | str
exe: Union[Executable, str]
args: tuple[str, ...] = ()

def __post_init__(self):
Expand Down Expand Up @@ -263,13 +265,20 @@ def run(self, *args, check=True, env=None, **kwargs):
return ret


# Should be imported from here.
local = Local()


@dataclass(frozen=True)
class LocalCommand(Command):
"""
Command returned by Local()["some_command"]. Follows local contexts.
"""

_local: Local = field(kw_only=True, repr=False)
if sys.version_info >= (3, 10):
_local: Local = field(kw_only=True, repr=False, default=local)
else:
_local: Local = field(repr=False, default=local)

def _which(self, exe):
return shutil.which(exe, path=self._local._env.get("PATH", ""))
Expand All @@ -280,7 +289,5 @@ def _get_env(self, overrides=None):
return base


# Should be imported from here.
local = Local()
# We must assume git is installed
git = local["git"]

0 comments on commit 0861e88

Please sign in to comment.