File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 88from importlib import import_module
99from itertools import chain
1010from pathlib import Path , PurePath
11+ import sys
1112from typing import TYPE_CHECKING , Any
1213from unittest .mock import patch
1314from zipfile import ZipFile
1415
16+ import jpype
17+
1518import scyjava
1619import scyjava .config
1720import stubgenj
@@ -70,11 +73,6 @@ def generate_stubs(
7073 """
7174 import jpype
7275
73- # FIXME: either remove the _JImportLoader from sys.meta_path after this is done
74- # (if it wasn't there to begin with), or replace the import_module calls below
75- # with a more direct JPackage call
76- import jpype .imports
77-
7876 startJVM = jpype .startJVM
7977
8078 scyjava .config .endpoints .extend (endpoints )
@@ -99,7 +97,16 @@ def _patched_start(*args: Any, **kwargs: Any) -> None:
9997 logger .info (f"Generating stubs for: { prefixes } " )
10098 logger .info (f"Writing stubs to: { output_dir } " )
10199
102- jmodules = [import_module (prefix ) for prefix in prefixes ]
100+ metapath = sys .meta_path
101+ try :
102+ import jpype .imports
103+
104+ jmodules = [import_module (prefix ) for prefix in prefixes ]
105+ finally :
106+ # remove the jpype.imports magic from the import system
107+ # if it wasn't there to begin with
108+ sys .meta_path = metapath
109+
103110 stubgenj .generateJavaStubs (
104111 jmodules ,
105112 useStubsSuffix = False ,
Original file line number Diff line number Diff line change 55from unittest .mock import patch
66
77import jpype
8- import jpype .imports
98
109import scyjava
1110from scyjava ._stubs import _cli
You can’t perform that action at this time.
0 commit comments