Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cwichel committed Apr 13, 2022
2 parents 180cd68 + 16aec63 commit 29460e4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion embutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
:license: The MIT License (MIT)
"""
# -------------------------------------
__version__ = '0.8.5'
__version__ = '0.8.6'
23 changes: 2 additions & 21 deletions embutils/repo/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"""
# -------------------------------------

import shutil as su
import subprocess as sp

from ..utils.common import TPPath
Expand All @@ -25,23 +24,6 @@


# -->> API <<--------------------------
def get_exec(name: str) -> Path:
"""
Get executable path.
:param str name: Executable name.
:return: Executable path.
:rtype: Path
:raises FileNotFoundError: Executable not found in PATH.
"""
find = su.which(name)
if find is None:
raise FileNotFoundError(f"Unable to find {name} executable on PATH!")
return Path(find)


def build_cubeide(
name: str, config: str, project: TPPath, workspace: TPPath, indexer: bool = False, clean: bool = True,
log: TPPath = None, pipe: bool = False, cwd: TPPath = None
Expand Down Expand Up @@ -73,7 +55,7 @@ def build_cubeide(
prj = Path.validate_dir(path=project, must_exist=True)
log = Path.validate_dir(path=log, none_ok=True)
# Prepare
exe = get_exec(name="stm32cubeidec")
exe = Path.which(name="stm32cubeidec")
idx = "" if indexer else "-no-indexer"
bld = "-cleanBuild" if clean else "-build"
# Execute
Expand Down Expand Up @@ -113,7 +95,7 @@ def build_iar(
# Prepare
bld = "-build" if clean else "-make"
# Execute
exe = get_exec(name="IarBuild")
exe = Path.which(name="IarBuild")
cmd = f"{exe} \"{prj}\" {bld} \"{config}\""
res = execute(cmd=cmd, pipe=pipe, log=log, cwd=cwd)
if not pipe and res.returncode:
Expand All @@ -123,7 +105,6 @@ def build_iar(

# -->> Export <<-----------------------
__all__ = [
"get_exec",
"build_cubeide",
"build_iar",
]
19 changes: 19 additions & 0 deletions embutils/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# -------------------------------------

import pathlib as pl
import shutil as su
import typing as tp

from .common import ENCODE, TPAny, TPByte, TPPath
Expand Down Expand Up @@ -63,6 +64,7 @@ def __new__(cls, *args, **kwargs) -> 'Path':
# Generate object and add extra functionalities
obj = pl.Path(*tuple(path))
setattr(obj.__class__, Path.reachable.__name__, Path.reachable)
setattr(obj.__class__, Path.which.__name__, staticmethod(Path.which))
setattr(obj.__class__, Path.validate.__name__, staticmethod(Path.validate))
setattr(obj.__class__, Path.validate_dir.__name__, staticmethod(Path.validate_dir))
setattr(obj.__class__, Path.validate_file.__name__, staticmethod(Path.validate_file))
Expand All @@ -77,6 +79,23 @@ def reachable(self) -> bool:
"""
return self.exists() or self.parent.exists()

@staticmethod
def which(name: str) -> "Path":
"""
Get executable path.
:param str name: Executable name.
:return: Executable path.
:rtype: Path
:raises FileNotFoundError: Executable not found in PATH.
"""
find = su.which(name)
if find is None:
raise FileNotFoundError(f"Unable to find {name} executable on PATH!")
return Path(find)

@staticmethod
def validate(
path: TPAny = None,
Expand Down
4 changes: 2 additions & 2 deletions embutils/utils/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


# -->> API <<--------------------------
def execute(cmd: str, cwd: TPPath = None, log: TPPath = None, pipe: bool = True) -> sp.CompletedProcess:
def execute(cmd: str, cwd: TPPath = None, log: TPPath = None, pipe: bool = True, **kwargs) -> sp.CompletedProcess:
"""
Execute the given command as a subprocess.
Expand All @@ -42,7 +42,7 @@ def execute(cmd: str, cwd: TPPath = None, log: TPPath = None, pipe: bool = True)
cwd = Path.validate_dir(path=cwd, none_ok=True)
log = Path.validate_dir(path=log, none_ok=True)
# Prepare
with sp.Popen(cmd, cwd=cwd, shell=True, close_fds=True, stdout=sp.PIPE, stderr=sp.PIPE) as proc:
with sp.Popen(cmd, cwd=cwd, shell=True, close_fds=True, stdout=sp.PIPE, stderr=sp.PIPE, **kwargs) as proc:
# Execute
if pipe:
# Piping needed...
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
version = "0.8.5"
version = "0.8.6"
name = "embutils"
license = "MIT"
readme = "README.md"
Expand Down

0 comments on commit 29460e4

Please sign in to comment.