-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement initial version of agent provider class (#93)
- Loading branch information
1 parent
de2c281
commit 4f31a85
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""binharness.agentprovider - AgentProvider class.""" | ||
|
||
from __future__ import annotations | ||
|
||
import abc | ||
from pathlib import Path | ||
|
||
|
||
class AgentProvider(abc.ABC): | ||
"""AgentProvider class.""" | ||
|
||
@abc.abstractmethod | ||
def get_agent_bin(self: AgentProvider, target_triplet: str | None = None) -> Path: | ||
"""Return a path to the agent binary for the given target triplet. | ||
If target_triplet is None, return the default agent binary. | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class DevEnvironmentAgentProvider(AgentProvider): | ||
"""DevEnvironmentAgentProvider class.""" | ||
|
||
path: Path | ||
target: str | ||
|
||
def __init__( | ||
self: DevEnvironmentAgentProvider, | ||
path: Path | None = None, | ||
target: str = "debug", | ||
) -> None: | ||
"""Initialize a DevEnvironmentAgentProvider. | ||
If path is not provided, the path will be set assuming the project is installed | ||
in development mode. | ||
""" | ||
if path is None: | ||
self.path = Path(__file__).parent.parent.parent | ||
else: | ||
self.path = path | ||
self.target = target | ||
|
||
def get_agent_bin( | ||
self: DevEnvironmentAgentProvider, target_triplet: str | None = None | ||
) -> Path: | ||
"""Return a path to the agent binary for the given target triplet.""" | ||
if target_triplet is None: | ||
return self.path / "target" / self.target / "bh_agent_server" | ||
return self.path / "target" / target_triplet / self.target / "bh_agent_server" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from binharness import DevEnvironmentAgentProvider | ||
|
||
|
||
def test_host_debug() -> None: | ||
provider = DevEnvironmentAgentProvider() | ||
assert ( | ||
provider.get_agent_bin() | ||
== Path(__file__).parent.parent.parent / "target" / "debug" / "bh_agent_server" | ||
) |