Skip to content

Commit

Permalink
pipcl.py: improved diagnostics if python dev tools not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Feb 2, 2024
1 parent c2363f5 commit ce17ebb
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions pipcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1715,25 +1715,35 @@ def run( command, capture=False, check=1):
When running the command, on Windows newlines are replaced by
spaces; otherwise each line is terminated by a backslash character.
capture:
If true, we return output from command.
If true, we include the command's output in our return value.
check:
If true we raise an exception on error; otherwise we include the
command's returncode in our return value.
Returns:
None on success, otherwise raises an exception.
check capture Return
--------------------------
false false returncode
false true (returncode, output)
true false None or raise exception
true true output or raise exception
'''
lines = _command_lines( command)
nl = '\n'
log2( f'Running: {nl.join(lines)}')
sep = ' ' if windows() else '\\\n'
command2 = sep.join( lines)
if capture:
return subprocess.run(
command2,
shell=True,
capture_output=True,
check=check,
encoding='utf8',
).stdout
cp = subprocess.run(
command2,
shell=True,
stdout=subprocess.PIPE if capture else None,
stderr=subprocess.STDOUT if capture else None,
check=check,
encoding='utf8',
)
if check:
return cp.stdout if capture else None
else:
subprocess.run( command2, shell=True, check=check)
return (cp.returncode, cp.stdout) if capture else cp.returncode


def darwin():
Expand Down Expand Up @@ -1817,9 +1827,10 @@ def __init__(self):
else:
python_config = f'{python_exe}-config'
log1(f'Using {python_config=}.')
self.includes = run( f'{python_config} --includes', capture=1).strip()
#if darwin():
# self.ldflags =
try:
self.includes = run( f'{python_config} --includes', capture=1).strip()
except Exception as e:
raise Exception('We require python development tools to be installed.') from e
self.ldflags = run( f'{python_config} --ldflags', capture=1).strip()
if linux():
# It seems that with python-3.10 on Linux, we can get an
Expand Down

0 comments on commit ce17ebb

Please sign in to comment.