online-judge-tools / verification-helper

a testing framework for snippet libraries used in competitive programming
MIT License
231 stars 56 forks source link

Failled to resolve dependency to the Python standard libraries #414

Closed edomonndo closed 1 year ago

edomonndo commented 1 year ago

Summary / 概要

If user’s py files include the link to standard libraries, the check mark icon is not applied in the doc file.

Steps to reproduce / 再現方法

  1. Make a Python file with imports (e.g. import typing)
  2. Make appropriate test files
  3. Run oj-verify

environments:

Expected behavior / 期待される挙動

The links to standard libraries are ignored when making doc files.

Actual behavior / 実際の挙動

The links are not resolved and the the library page does not show verified with.

Other notes / その他

Please let me know if this issues could be resolved by config file or any other setting.

koba-e964 commented 1 year ago

I was able to reproduce the issue myself. After applying the following patch:

diff --git a/examples/python/hello_world.test.py b/examples/python/hello_world.test.py
index 70f187d..f67594c 100644
--- a/examples/python/hello_world.test.py
+++ b/examples/python/hello_world.test.py
@@ -1,5 +1,6 @@
 # verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/1/ITP1_1_A
 import examples.python.hello_world
+import os

 def main():
     print(examples.python.hello_world.get_hello_world())

running oj-verify run examples/python/hello_world.test.py resulted in the same error.

koba-e964 commented 1 year ago

The following simple patch should resolve this issue. (PR: https://github.com/online-judge-tools/verification-helper/pull/415)

diff --git a/onlinejudge_verify/languages/python.py b/onlinejudge_verify/languages/python.py
index d31d2f5..cd3c1a2 100644
--- a/onlinejudge_verify/languages/python.py
+++ b/onlinejudge_verify/languages/python.py
@@ -57,7 +57,7 @@ def _python_list_depending_files(path: pathlib.Path, basedir: pathlib.Path) -> L
     )
     try:
         executor = concurrent.futures.ThreadPoolExecutor()
-        future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)])
+        future = executor.submit(importlab.graph.ImportGraph.create, env, [str(path)], trim=True)
         if platform.uname().system == 'Windows':
             timeout = 5.0  # 1.0 sec causes timeout on CI using Windows
         else: