Skip to content

Commit a8fca04

Browse files
pipcl.py: with graal try to cope with none as well as abi3.
Not sure this actually works, but might be useful. Also added venv_*() fns.
1 parent ad8289f commit a8fca04

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

pipcl.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,15 +641,19 @@ def build_wheel(self,
641641
wheel = newfiles.get_one()
642642
wheel_leaf = os.path.basename(wheel)
643643
python_major_minor = run(f'{shlex.quote(python_native)} -c "import platform; import sys; sys.stdout.write(str().join(platform.python_version_tuple()[:2]))"', capture=1)
644-
cpabi = f'cp{python_major_minor}-abi3'
645-
assert cpabi in wheel_leaf, f'Expected wheel to be for {cpabi=}, but {wheel=}.'
644+
cpabi_regex = f'cp{python_major_minor}-((abi3)|(none))'
646645
graalpy_ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
647646
log1(f'{graalpy_ext_suffix=}')
648647
m = re.match(r'\.graalpy(\d+[^\-]*)-(\d+)', graalpy_ext_suffix)
649648
gpver = m[1]
650649
cpver = m[2]
651650
graalpy_wheel_tag = f'graalpy{cpver}-graalpy{gpver}_{cpver}_native'
652-
name = wheel_leaf.replace(cpabi, graalpy_wheel_tag)
651+
log0(f'{cpabi_regex=}')
652+
log0(f'{graalpy_wheel_tag=}')
653+
log0(f'{wheel_leaf=}')
654+
name = re.sub(cpabi_regex, graalpy_wheel_tag, wheel_leaf)
655+
log0(f'{name=}')
656+
assert name != wheel_leaf, f'Did not find {cpabi_regex=} in {wheel_leaf=}.'
653657
destination = f'{wheel_directory}/{name}'
654658
log0(f'### Graal build: copying {wheel=} to {destination=}')
655659
# Copying results in two wheels which appears to confuse pip, showing:
@@ -3129,6 +3133,63 @@ def sysconfig_python_flags():
31293133
return includes_, ldflags_
31303134

31313135

3136+
def venv_in(path=None):
3137+
'''
3138+
If path is None, returns true if we are in a venv. Otherwise returns true
3139+
only if we are in venv <path>.
3140+
'''
3141+
if path:
3142+
return os.path.abspath(sys.prefix) == os.path.abspath(path)
3143+
else:
3144+
return sys.prefix != sys.base_prefix
3145+
3146+
3147+
def venv_run(args, path, recreate=True, clean=False):
3148+
'''
3149+
Runs Python command inside venv and returns termination code.
3150+
3151+
Args:
3152+
args:
3153+
List of args or string command.
3154+
path:
3155+
Name of venv.
3156+
recreate:
3157+
If false we do not run `<sys.executable> -m venv <path>` if <path>
3158+
already exists. This avoids a delay in the common case where <path>
3159+
is already set up, but fails if <path> exists but does not contain
3160+
a valid venv.
3161+
clean:
3162+
If true we first delete <path>.
3163+
'''
3164+
if clean:
3165+
log(f'Removing any existing venv {path}.')
3166+
assert path.startswith('venv-')
3167+
shutil.rmtree(path, ignore_errors=1)
3168+
if recreate or not os.path.isdir(path):
3169+
run(f'{sys.executable} -m venv {path}')
3170+
3171+
if isinstance(args, str):
3172+
args_string = args
3173+
elif platform.system() == 'Windows':
3174+
# shlex not reliable on Windows.
3175+
# Use crude quoting with "...". Seems to work.
3176+
args_string = ''
3177+
for i, arg in enumerate(args):
3178+
assert '"' not in arg
3179+
if i:
3180+
args_string += ' '
3181+
args_string += f'"{arg}"'
3182+
else:
3183+
args_string = shlex.join(args)
3184+
3185+
if platform.system() == 'Windows':
3186+
command = f'{path}\\Scripts\\activate && python {args_string}'
3187+
else:
3188+
command = f'. {path}/bin/activate && python {args_string}'
3189+
e = run(command, check=0)
3190+
return e
3191+
3192+
31323193
if __name__ == '__main__':
31333194
# Internal-only limited command line support, used if
31343195
# graal_legacy_python_config is true.

0 commit comments

Comments
 (0)