8000 MAINT: Use importlib over raw imports of tools · lesteve/numpy@29e47fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 29e47fb

Browse files
committed
MAINT: Use importlib over raw imports of tools
1 parent c5daed5 commit 29e47fb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

.spin/cmds.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import json
99
import pathlib
10+
import importlib
1011

1112
import click
1213
from spin import util
@@ -23,6 +24,14 @@
2324
)
2425

2526

27+
def _get_numpy_tools(filename):
28+
filepath = pathlib.Path('tools', filename)
29+
spec = importlib.util.spec_from_file_location(filename.stem, filepath)
30+
module = importlib.util.module_from_spec(spec)
31+
spec.loader.exec_module(module)
32+
return module
33+
34+
2635
@click.command()
2736
@click.option(
2837
"-t", "--token",
@@ -47,7 +56,7 @@ def changelog(ctx, token, revision_range):
4756
try:
4857
from github.GithubException import GithubException
4958
from git.exc import GitError
50-
from tools.changelog import main as generate_changelog
59+
changelog = _get_numpy_tools(pathlib.Path('changelog.py'))
5160
except ModuleNotFoundError as e:
5261
raise click.ClickException(
5362
f"{e.msg}. Install the missing packages to use this command."
@@ -57,7 +66,7 @@ def changelog(ctx, token, revision_range):
5766
bold=True, fg="bright_green",
5867
)
5968
try:
60-
generate_changelog(token, revision_range)
69+
changelog.main(token, revision_range)
6170
except GithubException as e:
6271
raise click.ClickException(
6372
f"GithubException raised with status: {e.status} "

0 commit comments

Comments
 (0)
0