Skip to content

Fix last one hardcoded unversioned python command #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions jupyter_packaging/setupbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ def run(cmd, **kwargs):
log.info('> ' + list2cmdline(cmd))
kwargs.setdefault('shell', os.name == 'nt')
if not isinstance(cmd, (list, tuple)):
cmd = shlex.split(cmd)
cmd_path = which(cmd[0])
if not cmd_path:
raise ValueError("Aborting. Could not find cmd (%s) in path. "
"If command is not expected to be in user's path, "
"use an absolute path." % cmd[0])
cmd[0] = cmd_path
cmd = shlex.split(cmd, posix=os.name!='nt')
if not os.path.isabs(cmd[0]):
# If a command is not an absolute path find it first.
cmd_path = which(cmd[0])
if not cmd_path:
raise ValueError("Aborting. Could not find cmd (%s) in path. "
"If command is not expected to be in user's path, "
"use an absolute path." % cmd[0])
cmd[0] = cmd_path
return subprocess.check_call(cmd, **kwargs)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_utility_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from unittest.mock import patch
import pytest
import sys

from setuptools.dist import Distribution
from jupyter_packaging.setupbase import __file__ as path
Expand Down Expand Up @@ -28,7 +29,7 @@ def run(self):


def test_run():
assert pkg.run('python --version') == 0
assert pkg.run(sys.executable + ' --version') == 0

with pytest.raises(ValueError):
pkg.run('foobarbaz')
Expand Down