Skip to content

Commit

Permalink
fix apidetector in env, ignore main module
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Feb 5, 2024
1 parent 4bbb22a commit 23da422
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ jobs:
- name: Test Extraction in Temp env
continue-on-error: false
run: |
aexpy -vvv extract ./cache/distribution1.json ./cache/api3.json --no-temp
aexpy -vvv extract ./cache/distribution1.json ./cache/api4.json --temp
aexpy -vvv preprocess -r -p generator-oj-problem@0.0.1 -P 3.8 ./cache ./cache/distribution3.json
aexpy -vvv extract ./cache/distribution3.json ./cache/api3.json --no-temp
aexpy -vvv extract ./cache/distribution3.json ./cache/api4.json --temp
- name: Test Difference
continue-on-error: false
run: |
Expand Down Expand Up @@ -111,8 +112,9 @@ jobs:
- name: Test Extraction in Env
continue-on-error: false
run: |
docker run -v ${{ github.workspace }}/cache:/data aexpy/aexpy -vvv extract /data/distribution1.json /data/api3.json --temp
docker run -v ${{ github.workspace }}/cache:/data aexpy/aexpy -vvv extract /data/distribution1.json /data/api4.json --no-temp
docker run -v ${{ github.workspace }}/cache:/data aexpy/aexpy -vvv preprocess -r -p generator-oj-problem@0.0.1 -P 3.8 /data /data/distribution3.json
docker run -v ${{ github.workspace }}/cache:/data aexpy/aexpy -vvv extract /data/distribution3.json /data/api3.json --temp
docker run -v ${{ github.workspace }}/cache:/data aexpy/aexpy -vvv extract /data/distribution3.json /data/api4.json --no-temp
- name: Test Difference
continue-on-error: false
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/aexpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import pathlib

__version__ = "0.2.0"
__version__ = "0.2.1"


LOGGING_FORMAT = "%(levelname)s %(asctime)s %(name)s [%(pathname)s:%(lineno)d:%(funcName)s]\n%(message)s\n"
Expand Down
14 changes: 9 additions & 5 deletions src/aexpy/apidetector/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ def onerror(name):
for sub in pkgutil.walk_packages(
path=module.__path__, prefix=module.__name__ + ".", onerror=onerror
):
submoduleName = sub[1]
if submoduleName.endswith(".__main__"):
logger.debug(f"Ignore {submoduleName}.")
continue
try:
logger.debug(f"Import {sub[1]}.")
submodule = importlib.import_module(sub[1])
logger.debug(f"Imported {sub[1]}: {submodule}.")
logger.debug(f"Import {submoduleName}.")
submodule = importlib.import_module(submoduleName)
logger.debug(f"Imported {submoduleName}: {submodule}.")
modules.append(submodule)
except Exception as ex:
logger.error(f"Failed to import {sub[1]}", exc_info=ex)
logger.error(f"Failed to import {submoduleName}", exc_info=ex)
except SystemExit as ex:
logger.error(f"Failed to import {sub[1]}", exc_info=ex)
logger.error(f"Failed to import {submoduleName}", exc_info=ex)
except Exception as ex:
logger.error(f"Failed to import {name}", exc_info=ex)
except SystemExit as ex:
Expand Down
18 changes: 13 additions & 5 deletions src/aexpy/extracting/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import shutil
import subprocess
from datetime import datetime, timedelta
from pathlib import Path
from typing import Callable, override
import json
import tempfile

from pydantic import TypeAdapter

Expand Down Expand Up @@ -60,11 +62,17 @@ class BaseExtractor(EnvirontmentExtractor):
def extractInEnv(self, result, runner):
assert result.distribution

subres = runner.runPythonText(
f"-m aexpy.apidetector",
cwd=getAppDirectory().parent,
input=result.distribution.model_dump_json(),
)
with tempfile.TemporaryDirectory() as tmpdir:

# pydantic will failed if run in app directory under python 3.12 in another python
self.logger.info(f"Copy from {getAppDirectory()} to {tmpdir}")
shutil.copytree(getAppDirectory(), Path(tmpdir) / "aexpy")

subres = runner.runPythonText(
f"-m aexpy.apidetector",
cwd=tmpdir,
input=result.distribution.model_dump_json(),
)

logProcessResult(self.logger, subres)

Expand Down

0 comments on commit 23da422

Please sign in to comment.