Skip to content

Commit 883e072

Browse files
authored
Add more default python dist checks (#481)
1 parent 7c464a6 commit 883e072

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
run: |
7474
set -eux
7575
pip install -e .
76-
python -m jupyter_releaser.actions.generate-changelog
76+
python -m jupyter_releaser.actions.generate_changelog
7777
cat CHANGELOG_ENTRY.md
7878
# Check for version entry contents
7979
cat CHANGELOG_ENTRY.md | grep -q "#234"
@@ -84,7 +84,7 @@ jobs:
8484
export RH_CONVERT_TO_RST=true
8585
sudo apt-get install pandoc
8686
pip install pypandoc
87-
python -m jupyter_releaser.actions.generate-changelog
87+
python -m jupyter_releaser.actions.generate_changelog
8888
cat CHANGELOG_ENTRY.md
8989
9090
test_minimum_versions:

jupyter_releaser/cli.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,19 @@ def main(force):
289289
click.option(
290290
"--pydist-check-cmd",
291291
envvar="RH_PYDIST_CHECK_CMD",
292-
default="pipx run twine check --strict",
292+
default="pipx run twine check --strict {dist_file}",
293293
help="The command to use to check a python distribution file",
294294
),
295+
click.option(
296+
"--pydist-extra-check-cmds",
297+
envvar="RH_EXTRA_PYDIST_CHECK_CMDS",
298+
default=[
299+
"pipx run 'validate-pyproject[all]' pyproject.toml",
300+
"pipx run check-wheel-contents --ignore W002 {dist_dir}",
301+
],
302+
multiple=True,
303+
help="Extra checks to run against the pydist file",
304+
),
295305
click.option(
296306
"--pydist-resource-paths",
297307
envvar="RH_PYDIST_RESOURCE_PATHS",
@@ -446,7 +456,9 @@ def build_python(dist_dir, python_packages):
446456
@add_options(check_imports_options)
447457
@add_options(pydist_check_options)
448458
@use_checkout_dir()
449-
def check_python(dist_dir, check_imports, pydist_check_cmd, pydist_resource_paths):
459+
def check_python(
460+
dist_dir, check_imports, pydist_check_cmd, pydist_extra_check_cmds, pydist_resource_paths
461+
):
450462
"""Check Python dist files"""
451463
for dist_file in glob(f"{dist_dir}/*"):
452464
if Path(dist_file).suffix not in [".gz", ".whl"]:
@@ -457,6 +469,7 @@ def check_python(dist_dir, check_imports, pydist_check_cmd, pydist_resource_path
457469
dist_file,
458470
python_imports=check_imports,
459471
check_cmd=pydist_check_cmd,
472+
extra_check_cmds=pydist_extra_check_cmds,
460473
resource_paths=pydist_resource_paths,
461474
)
462475

jupyter_releaser/python.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ def check_dist(
3232
dist_file,
3333
test_cmd="",
3434
python_imports=None,
35-
check_cmd="pipx twine check --strict",
35+
check_cmd="pipx run twine check --strict {dist_file}",
36+
extra_check_cmds=None,
3637
resource_paths=None,
3738
):
3839
"""Check a Python package locally (not as a cli)"""
3940
resource_paths = resource_paths or []
4041
dist_file = util.normalize_path(dist_file)
41-
util.run(f"{check_cmd} {dist_file}")
42+
dist_dir = os.path.dirname(dist_file) # used for check cmds.
43+
44+
for cmd in [check_cmd] + list(extra_check_cmds or []):
45+
util.run(cmd.format(**locals()))
4246

4347
test_commands = []
4448

jupyter_releaser/tee.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ def run(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess:
147147

148148
check = kwargs.get("check", False)
149149

150-
loop = asyncio.get_event_loop_policy().get_event_loop()
150+
try:
151+
loop = asyncio.get_event_loop()
152+
except Exception:
153+
loop = asyncio.new_event_loop()
154+
asyncio.set_event_loop(loop)
151155
result = loop.run_until_complete(_stream_subprocess(cmd, **kwargs))
152156
atexit.register(loop.close)
153157

jupyter_releaser/tests/test_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def test_list_envvars(runner):
156156
post-version-message: RH_POST_VERSION_MESSAGE
157157
post-version-spec: RH_POST_VERSION_SPEC
158158
pydist-check-cmd: RH_PYDIST_CHECK_CMD
159+
pydist-extra-check-cmds: RH_EXTRA_PYDIST_CHECK_CMDS
159160
pydist-resource-paths: RH_PYDIST_RESOURCE_PATHS
160161
python-packages: RH_PYTHON_PACKAGES
161162
ref: RH_REF

0 commit comments

Comments
 (0)