Loading src/features/mise.py +30 −2 Changes for src/features/mise.py: 30 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ from json import loads from os import environ from pathlib import Path from re import MULTILINE, search, sub from typing import Any, Dict, List, Optional, Tuple # Components Loading @@ -27,7 +28,12 @@ class Mise: # Arguments @staticmethod def arguments(config: str) -> List[str]: def arguments(config: str, specification: str = '') -> List[str]: # Use default configuration if config and specification \ and Path(config).expanduser().resolve() == Mise.target(specification): return [] # Use global configuration if config and Path(config).expanduser().resolve() == Mise.config_global(): Loading Loading @@ -85,8 +91,9 @@ class Mise: return None # Install packages in the configuration file specification: str = f'{package}@{version}' # pragma: no cover return Commands.mise( # pragma: no cover ['use'] + Mise.arguments(config) + [f'{package}@{version}']) ['use'] + Mise.arguments(config, specification) + [specification]) # Configuration @staticmethod Loading Loading @@ -154,6 +161,27 @@ class Mise: # Check if running from mise return bool(Mise.installation()) # Target @staticmethod def target(specification: str) -> Optional[Path]: # Detect default configuration file output: str = Commands.output(Mise.BINARY, [ 'use', '--dry-run', specification, ], errors=True) match = search( r'^mise would \w+ (.+) \(', sub(r'\x1b\[[0-9;]*m', '', output), MULTILINE, ) if match: # pragma: no cover return Path(match.group(1)).expanduser().resolve() # Fallback return None # Tool @staticmethod def tool(path: str) -> Optional[Tuple[str, str]]: Loading src/package/updates.py +4 −1 Changes for src/package/updates.py: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -155,7 +155,10 @@ class Updates: package_install: str = '' if Mise.managed(): package_install = ' '.join(['mise', 'use'] + [ # pragma: no cover quote(argument) for argument in Mise.arguments(Mise.config()) quote(argument) for argument in Mise.arguments( Mise.config(), f'{Mise.package(name)}@latest', ) ]) elif Platform.PATH_SEPARATOR + 'pipx' + Platform.PATH_SEPARATOR in Version.path(): package_install = 'pipx upgrade' # pragma: no cover Loading src/system/commands.py +16 −2 Changes for src/system/commands.py: 16 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -69,7 +69,21 @@ class Commands: # Output @staticmethod def output(binary: str, arguments: List[str], quiet: bool = False) -> str: def output( binary: str, arguments: List[str], quiet: bool = False, errors: bool = False, ) -> str: # Variables stderr: Optional[int] = None # Redirect errors if errors: stderr = subprocess.STDOUT elif quiet: stderr = subprocess.DEVNULL # Get system output try: Loading @@ -77,7 +91,7 @@ class Commands: args=[binary] + arguments, cwd=None, shell=False, stderr=subprocess.DEVNULL if quiet else None, stderr=stderr, ).strip().decode() except subprocess.CalledProcessError as err: return str(err.output.decode()) Loading Loading
src/features/mise.py +30 −2 Changes for src/features/mise.py: 30 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ from json import loads from os import environ from pathlib import Path from re import MULTILINE, search, sub from typing import Any, Dict, List, Optional, Tuple # Components Loading @@ -27,7 +28,12 @@ class Mise: # Arguments @staticmethod def arguments(config: str) -> List[str]: def arguments(config: str, specification: str = '') -> List[str]: # Use default configuration if config and specification \ and Path(config).expanduser().resolve() == Mise.target(specification): return [] # Use global configuration if config and Path(config).expanduser().resolve() == Mise.config_global(): Loading Loading @@ -85,8 +91,9 @@ class Mise: return None # Install packages in the configuration file specification: str = f'{package}@{version}' # pragma: no cover return Commands.mise( # pragma: no cover ['use'] + Mise.arguments(config) + [f'{package}@{version}']) ['use'] + Mise.arguments(config, specification) + [specification]) # Configuration @staticmethod Loading Loading @@ -154,6 +161,27 @@ class Mise: # Check if running from mise return bool(Mise.installation()) # Target @staticmethod def target(specification: str) -> Optional[Path]: # Detect default configuration file output: str = Commands.output(Mise.BINARY, [ 'use', '--dry-run', specification, ], errors=True) match = search( r'^mise would \w+ (.+) \(', sub(r'\x1b\[[0-9;]*m', '', output), MULTILINE, ) if match: # pragma: no cover return Path(match.group(1)).expanduser().resolve() # Fallback return None # Tool @staticmethod def tool(path: str) -> Optional[Tuple[str, str]]: Loading
src/package/updates.py +4 −1 Changes for src/package/updates.py: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -155,7 +155,10 @@ class Updates: package_install: str = '' if Mise.managed(): package_install = ' '.join(['mise', 'use'] + [ # pragma: no cover quote(argument) for argument in Mise.arguments(Mise.config()) quote(argument) for argument in Mise.arguments( Mise.config(), f'{Mise.package(name)}@latest', ) ]) elif Platform.PATH_SEPARATOR + 'pipx' + Platform.PATH_SEPARATOR in Version.path(): package_install = 'pipx upgrade' # pragma: no cover Loading
src/system/commands.py +16 −2 Changes for src/system/commands.py: 16 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -69,7 +69,21 @@ class Commands: # Output @staticmethod def output(binary: str, arguments: List[str], quiet: bool = False) -> str: def output( binary: str, arguments: List[str], quiet: bool = False, errors: bool = False, ) -> str: # Variables stderr: Optional[int] = None # Redirect errors if errors: stderr = subprocess.STDOUT elif quiet: stderr = subprocess.DEVNULL # Get system output try: Loading @@ -77,7 +91,7 @@ class Commands: args=[binary] + arguments, cwd=None, shell=False, stderr=subprocess.DEVNULL if quiet else None, stderr=stderr, ).strip().decode() except subprocess.CalledProcessError as err: return str(err.output.decode()) Loading