Skip to content

Commit

Permalink
update _tools.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-black-tea committed Apr 12, 2023
1 parent 3237d83 commit cc5ccd5
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/linktools/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ def make_fget(mcs, key):
return lambda self: self.config.get(key)


class ToolExecError(Exception):
class ToolError(Exception):
pass


class ToolNotFound(ToolError):
pass


class ToolExecError(ToolError):
pass


Expand Down Expand Up @@ -374,9 +382,6 @@ def __repr__(self):


class ToolContainer(object):
system: str = property(lambda self: self.config["system"])
processor: str = property(lambda self: self.config["processor"])
architecture: str = property(lambda self: self.config["architecture"])

def __init__(self, env: BaseEnviron, **kwargs):
self.environ = env
Expand All @@ -385,6 +390,18 @@ def __init__(self, env: BaseEnviron, **kwargs):
self.config.setdefault("processor", platform.processor().lower())
self.config.setdefault("architecture", platform.architecture()[0].lower())

@property
def system(self) -> str:
return self.config["system"]

@property
def processor(self) -> str:
return self.config["processor"]

@property
def architecture(self) -> str:
return self.config["architecture"]

@cached_property
def items(self) -> Mapping[str, Tool]:
items = {}
Expand All @@ -399,8 +416,12 @@ def items(self) -> Mapping[str, Tool]:
def __iter__(self) -> Iterator[Tool]:
return iter(self.items.values())

def __getitem__(self, item) -> Union[Tool, None]:
return self.items[item] if item in self.items else None
def __getitem__(self, item) -> Tool:
if item not in self.items:
raise ToolNotFound(f"Not found tool {item}")
return self.items[item]

def __getattr__(self, item) -> Union[Tool, None]:
return self.items[item] if item in self.items else None
def __getattr__(self, item) -> Tool:
if item not in self.items:
raise ToolNotFound(f"Not found tool {item}")
return self.items[item]

0 comments on commit cc5ccd5

Please sign in to comment.