Skip to content

Commit

Permalink
support interact worker
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Mar 13, 2024
1 parent bb37ad3 commit 15d4770
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/aexpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from functools import cache

__version__ = "0.4.3"
__version__ = "0.4.4"

COMMIT_ID = "<GIT_COMMIT>"
SHORT_COMMIT_ID = COMMIT_ID[:7]
Expand Down
26 changes: 6 additions & 20 deletions src/aexpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,10 @@

import click

from . import (
__version__,
BUILD_DATE,
SHORT_COMMIT_ID,
initializeLogging,
runInContainer,
)
from .models import (
ApiDescription,
ApiDifference,
Distribution,
ProduceState,
Product,
Release,
Report,
)
from . import (BUILD_DATE, SHORT_COMMIT_ID, __version__, initializeLogging,
runInContainer)
from .models import (ApiDescription, ApiDifference, Distribution, ProduceState,
Product, Release, Report)
from .producers import ProduceContext, produce
from .services import ServiceProvider, getService, loadServiceFromCode

Expand Down Expand Up @@ -290,10 +278,8 @@ def extractCore(
elif temp:
envBuilder = service.environmentBuilder(logger=context.logger)
else:
from .environments import (
CurrentEnvironment,
SingleExecutionEnvironmentBuilder,
)
from .environments import (CurrentEnvironment,
SingleExecutionEnvironmentBuilder)

envBuilder = SingleExecutionEnvironmentBuilder(
CurrentEnvironment(context.logger), context.logger
Expand Down
10 changes: 2 additions & 8 deletions src/aexpy/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
from pathlib import Path
from typing import IO, Callable, Literal, overload, override

from ..models import (
ApiDescription,
ApiDifference,
CoreProduct,
Distribution,
Product,
Report,
)
from ..models import (ApiDescription, ApiDifference, CoreProduct, Distribution,
Product, Report)
from ..utils import ensureDirectory


Expand Down
4 changes: 2 additions & 2 deletions src/aexpy/services.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from contextlib import contextmanager
from logging import Logger

from . import __version__, SHORT_COMMIT_ID
from . import SHORT_COMMIT_ID, __version__
from .diffing import Differ
from .environments import ExecutionEnvironment, ExecutionEnvironmentBuilder
from .extracting import Extractor
from .models import (ApiDescription, ApiDifference, Distribution, Product,
Report)
Report)
from .preprocessing import Preprocessor
from .producers import ProduceContext, produce
from .reporting import Reporter
Expand Down
6 changes: 5 additions & 1 deletion src/aexpy/tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ def runimage(
from .workers import AexPyDockerWorker

worker = AexPyDockerWorker(
cwd=volume, verbose=clictx.verbose, compress=clictx.gzip, tag=tag
cwd=volume,
verbose=clictx.verbose,
compress=clictx.gzip,
tag=tag,
interact=clictx.interact,
)

result = worker.run(list(args), capture_output=False)
Expand Down
39 changes: 24 additions & 15 deletions src/aexpy/tools/workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ...extracting import Extractor
from ...io import StreamProductSaver
from ...models import (ApiDescription, ApiDifference, Distribution, Product,
Report)
Report)
from ...producers import Producer
from ...reporting import Reporter

Expand Down Expand Up @@ -42,10 +42,12 @@ def __init__(
verbose: int = 0,
compress: bool = False,
cwd: Path | None = None,
interact: bool = False,
logger: Logger | None = None,
) -> None:
self.verbose = min(5, max(0, verbose))
self.compress = compress
self.interact = interact
self.logger = logger or logging.getLogger()
self.cwd = cwd or Path(os.getcwd()).resolve()

Expand All @@ -59,6 +61,8 @@ def run(self, /, args: list[str], **kwargs) -> subprocess.CompletedProcess[bytes
args = (
self.getCommandPrefix()
+ (["-" + "v" * self.verbose] if self.verbose > 0 else [])
+ (["--interact"] if self.interact else [])
+ (["--gzip"] if self.compress else [])
+ args
)
self.logger.debug(f"Worker run args: {args}")
Expand Down Expand Up @@ -149,11 +153,12 @@ def __init__(
verbose: int = 0,
compress: bool = False,
cwd: Path | None = None,
interact: bool = False,
logger: Logger | None = None,
*,
tag: str = "",
) -> None:
super().__init__(verbose, compress, cwd, logger)
super().__init__(verbose, compress, cwd, interact, logger)
self.tag = tag or self.defaultTag()

def getImageTag(self, /, version: str):
Expand All @@ -165,23 +170,27 @@ def getCommandPrefix(self, /):

try:
import pwd
uid = os.getuid() # type: ignore

uid = os.getuid() # type: ignore
gid = pwd.getpwuid(uid).pw_gid # type: ignore
user = f"{uid}:{gid}"
except Exception:
pass

return [
"docker",
"run",
"-i",
"-v",
f"{str(self.cwd.resolve())}:/data",
"-u",
user,
"--rm",
self.tag,
] + (["--gzip"] if self.compress else [])

return (
[
"docker",
"run",
"-i",
"-v",
f"{str(self.cwd.resolve())}:/data",
"-u",
user,
"--rm",
]
+ (["-t"] if self.interact else [])
+ [self.tag]
)

@override
def resolvePath(self, /, path):
Expand Down
6 changes: 3 additions & 3 deletions src/aexpy/tools/workers/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from typing import Callable, override

from ...environments import (CurrentEnvironment, ExecutionEnvironmentBuilder,
SingleExecutionEnvironmentBuilder)
SingleExecutionEnvironmentBuilder)
from ...models import ApiDescription, Distribution
from ...producers import ProduceContext
from . import (AexPyDockerWorker, AexPyWorker, WorkerDiffer,
WorkerExtractor, WorkerReporter)
from ...services import ServiceProvider
from . import (AexPyDockerWorker, AexPyWorker, WorkerDiffer, WorkerExtractor,
WorkerReporter)


class WorkerServiceProvider(ServiceProvider):
Expand Down

0 comments on commit 15d4770

Please sign in to comment.