Skip to content

Commit 1898d25

Browse files
committed
Allow to specify a list of imports
1 parent 1cce6d0 commit 1898d25

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

jupyter_releaser/cli.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ def main(force):
184184
)
185185
]
186186

187-
python_target_options = [
187+
python_imports_options = [
188188
click.option(
189-
"--python-target",
190-
envvar="RH_PYTHON_TARGET",
191-
default="",
192-
help="The Python package import to check for; default to the Python package name.",
189+
"--check-imports",
190+
envvar="RH_CHECK_IMPORTS",
191+
default=[],
192+
multiple=True,
193+
help="The Python packages import to check for; default to the Python package name.",
193194
)
194195
]
195196

@@ -412,16 +413,16 @@ def build_python(dist_dir, python_packages):
412413

413414
@main.command()
414415
@add_options(dist_dir_options)
415-
@add_options(python_target_options)
416+
@add_options(python_imports_options)
416417
@use_checkout_dir()
417-
def check_python(dist_dir, python_target):
418+
def check_python(dist_dir, python_imports):
418419
"""Check Python dist files"""
419420
for dist_file in glob(f"{dist_dir}/*"):
420421
if Path(dist_file).suffix not in [".gz", ".whl"]:
421422
util.log(f"Skipping non-python dist file {dist_file}")
422423
continue
423-
test_cmd = f'python -c "import {python_target}"' if python_target else ""
424-
python.check_dist(dist_file, test_cmd)
424+
425+
python.check_dist(dist_file, python_imports=python_imports)
425426

426427

427428
@main.command()

jupyter_releaser/python.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ def build_dist(dist_dir, clean=True):
3434
util.run(f"python setup.py bdist_wheel --dist-dir {dest}", quiet=True)
3535

3636

37-
def check_dist(dist_file, test_cmd=""):
37+
def check_dist(dist_file, test_cmd="", python_imports=None):
3838
"""Check a Python package locally (not as a cli)"""
3939
dist_file = util.normalize_path(dist_file)
4040
util.run(f"twine check {dist_file}")
4141

42-
if not test_cmd:
42+
test_commands = []
43+
44+
if test_cmd:
45+
test_commands.append(test_cmd)
46+
elif python_imports is not None:
47+
test_commands.extend([f'python -c "import {name}"' for name in python_imports])
48+
else:
4349
# Get the package name from the dist file name
4450
name = re.match(r"(\S+)-\d", osp.basename(dist_file)).groups()[0]
4551
name = name.replace("-", "_")
46-
test_cmd = f'python -c "import {name}"'
52+
test_commands.append(f'python -c "import {name}"')
4753

4854
# Create venvs to install dist file
4955
# run the test command in the venv
@@ -60,11 +66,12 @@ def check_dist(dist_file, test_cmd=""):
6066
util.run(f"{bin_path}/python -m pip install -q -U pip")
6167
util.run(f"{bin_path}/pip install -q {dist_file}")
6268
try:
63-
util.run(f"{bin_path}/{test_cmd}")
69+
for cmd in test_commands:
70+
util.run(f"{bin_path}/{cmd}")
6471
except CalledProcessError as e:
6572
if test_cmd == "":
6673
util.log(
67-
'You may need to set "python_target" to an appropriate Python package name in the config file.'
74+
'You may need to set "check_imports" to appropriate Python package names in the config file.'
6875
)
6976
raise e
7077

jupyter_releaser/tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_list_envvars(runner):
163163
post-version-message: RH_POST_VERSION_MESSAGE
164164
post-version-spec: RH_POST_VERSION_SPEC
165165
python-packages: RH_PYTHON_PACKAGES
166-
python-target: RH_PYTHON_TARGET
166+
check-imports: RH_CHECK_IMPORTS
167167
ref: RH_REF
168168
release-message: RH_RELEASE_MESSAGE
169169
repo: RH_REPOSITORY
@@ -439,7 +439,7 @@ def test_check_python(py_package, runner, build_mock, git_prep):
439439
def test_check_python_different_names(
440440
monkeypatch, py_package_different_names, runner, build_mock, git_prep
441441
):
442-
monkeypatch.setenv("RH_PYTHON_TARGET", "foobar")
442+
monkeypatch.setenv("RH_CHECK_IMPORTS", "foobar")
443443
runner(["build-python"])
444444
runner(["check-python"])
445445

0 commit comments

Comments
 (0)