Commit 7b3c944f authored by Kirill Smelkov's avatar Kirill Smelkov

Merge branch 'y/fixup' into next

* y/fixup:
  gpython: Fix thinko when rejecting unknown -X option
  gpython: Fix `gpython -X gpython.runtime=threads` to spawn subinterpreters with threads runtime by default
  gpython: tests: Factorize test_Xruntime
  golang_str: fix UCS2 builds
  setup: py.bench needs py on py3
parents 29862085 cd2f71c3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2018-2022 Nexedi SA and Contributors. # Copyright (C) 2018-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -221,8 +221,9 @@ cdef (int, int) _utf8_decode_rune(const uint8_t[::1] s): ...@@ -221,8 +221,9 @@ cdef (int, int) _utf8_decode_rune(const uint8_t[::1] s):
if _ucs2_build and len(r) == 2: if _ucs2_build and len(r) == 2:
try: try:
return _xuniord(r), l return _xuniord(r), l
# e.g. TypeError: ord() expected a character, but string of length 2 found # py: TypeError: ord() expected a character, but string of length 2 found
except TypeError: # cy: ValueError: only single character unicode strings can be converted to Py_UCS4, got length 2
except (TypeError, ValueError):
l -= 1 l -= 1
continue continue
......
...@@ -395,7 +395,7 @@ def main(): ...@@ -395,7 +395,7 @@ def main():
sys._xoptions['gpython.runtime'] = gpy_runtime sys._xoptions['gpython.runtime'] = gpy_runtime
else: else:
raise RuntimeError('gpython: unknown -X option %s' % opt) raise RuntimeError('gpython: unknown -X option %s' % arg)
continue continue
...@@ -409,6 +409,11 @@ def main(): ...@@ -409,6 +409,11 @@ def main():
argv = [sys.argv[0]] + argv_ + igetopt.argv argv = [sys.argv[0]] + argv_ + igetopt.argv
# propagate those settings as defaults to subinterpreters, so that e.g.
# sys.executable spawned from under `gpython -X gpython.runtime=threads`
# also uses "threads" runtime by default.
os.environ['GPYTHON_RUNTIME'] = gpy_runtime
# init initializes according to selected runtime # init initializes according to selected runtime
# it is called after options are parsed and sys.path is setup correspondingly. # it is called after options are parsed and sys.path is setup correspondingly.
# this way golang and gevent are imported from exactly the same place as # this way golang and gevent are imported from exactly the same place as
......
...@@ -355,20 +355,31 @@ def test_pymain_run_via_relpath(): ...@@ -355,20 +355,31 @@ def test_pymain_run_via_relpath():
out2 = pyout(['./__init__.py'] + argv, pyexe=sys._gpy_underlying_executable, cwd=here) out2 = pyout(['./__init__.py'] + argv, pyexe=sys._gpy_underlying_executable, cwd=here)
assert out1 == out2 assert out1 == out2
# verify -X gpython.runtime=... # verify -X gpython.runtime=...
@gpython_only @gpython_only
def test_Xruntime(runtime): def test_Xruntime(runtime):
_xopt_assert_in_subprocess('gpython.runtime', runtime,
assert_gevent_activated if runtime != 'threads' else \
assert_gevent_not_activated)
# _xopt_assert_in_subprocess runs tfunc in subprocess interpreter spawned with
# `-X xopt=xval` and checks that there is no error.
#
# It is also verified that tfunc runs ok in sub-subprocess interpreter spawned
# _without_ `-X ...`, i.e. once given -X setting is inherited by spawned interpreters.
def _xopt_assert_in_subprocess(xopt, xval, tfunc):
XOPT = xopt.upper().replace('.','_') # gpython.runtime -> GPYTHON_RUNTIME
env = os.environ.copy() env = os.environ.copy()
env.pop('GPYTHON_RUNTIME', None) # del env.pop(XOPT, None) # del
argv = [] argv = []
if runtime != '': if xval != '':
argv += ['-X', 'gpython.runtime='+runtime] argv += ['-X', xopt+'='+xval]
prog = 'from gpython import gpython_test as t; ' prog = import_t = 'from gpython import gpython_test as t; '
if runtime != 'threads': prog += 't.%s(); ' % tfunc.__name__
prog += 't.assert_gevent_activated(); ' prog += import_t # + same in subprocess
else: prog += "t.pyrun(['-c', '%s t.%s(); ']); " % (import_t, tfunc.__name__)
prog += 't.assert_gevent_not_activated(); '
prog += 'print("ok")' prog += 'print("ok")'
argv += ['-c', prog] argv += ['-c', prog]
......
...@@ -154,7 +154,7 @@ class develop(XInstallGPython, _develop): ...@@ -154,7 +154,7 @@ class develop(XInstallGPython, _develop):
# requirements of packages under "golang." namespace # requirements of packages under "golang." namespace
R = { R = {
'cmd.pybench': {'pytest'}, 'cmd.pybench': {'pytest', 'py ; python_version >= "3"'},
'pyx.build': {'setuptools', 'wheel', 'cython < 3', 'setuptools_dso >= 2.8'}, 'pyx.build': {'setuptools', 'wheel', 'cython < 3', 'setuptools_dso >= 2.8'},
'x.perf.benchlib': {'numpy'}, 'x.perf.benchlib': {'numpy'},
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment