Skip to content

Commit a60c290

Browse files
Merge pull request hexylena#69 from bernt-matthias/topic/dropins2
make loading of original module work also for environments containing "argparse2tool"
2 parents e327657 + 32505d7 commit a60c290

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

argparse2tool/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
pass
77

88

9-
__version__ = '0.4.8'
9+
__version__ = '0.4.9'
1010

1111

1212
def load_argparse():
1313
ARGPARSE_NUMBER = 1
14-
return load_conflicting_package('argparse', 'argparse2tool', ARGPARSE_NUMBER)
14+
return load_conflicting_package('argparse', 'argparse2tool/dropins', ARGPARSE_NUMBER)
15+
16+
17+
def load_click():
18+
CLICK_NUMBER = 5
19+
return load_conflicting_package('click', 'argparse2tool/dropins', CLICK_NUMBER)
1520

1621

1722
def load_conflicting_package(name, not_name, module_number):
@@ -37,10 +42,9 @@ def load_conflicting_package(name, not_name, module_number):
3742
for path in sys.path:
3843
try:
3944
(f, pathname, desc) = imp.find_module(name, [path])
40-
if not_name not in pathname and desc[2] == module_number:
41-
imp.load_module(random_name, f, pathname, desc)
42-
return sys.modules[random_name]
43-
except Exception:
44-
# Many sys.paths won't contain the module of interest
45-
pass
45+
except ImportError:
46+
continue
47+
if not_name not in pathname and desc[2] == module_number:
48+
imp.load_module(random_name, f, pathname, desc)
49+
return sys.modules[random_name]
4650
return None

argparse2tool/dropins/click/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
from click import click_cwl_translation as cct
66
from argparse2tool.cmdline2cwl import cwl_tool as cwlt
7-
from argparse2tool import load_conflicting_package
7+
from argparse2tool import load_click
88
from argparse2tool.cmdline2cwl import Arg2CWLParser
99

10-
CLICK_NUMBER = 5
11-
click = load_conflicting_package('click', 'argparse2tool', CLICK_NUMBER)
10+
click = load_click()
1211
__selfmodule__ = sys.modules[__name__]
1312
# This fetches a reference to ourselves
1413

examples/example-click.cwl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env cwl-runner
2-
# This tool description was generated automatically by argparse2tool ver. 0.4.8
2+
# This tool description was generated automatically by argparse2tool ver. 0.4.9
33
# To generate again: $ example-click.py --generate_cwl_tool
44
# Help: $ example --help_arg2cwl
55

0 commit comments

Comments
 (0)