- 22 Sep, 2020 4 commits
-
-
Kirill Smelkov authored
This continues 6b4990f6 (gpython: Fix pymain to properly setup sys.path[0]) - now we add test and verify that gpython actually sets sys.path in the same way as underlying python does: - don't add directory of gpython to sys.path - for `gpython file` add to sys.path[0] realpath(dir(file)) instead of dir(file) (see PySys_SetArgvEx for the reference, and else - if we do not make this change - added test breaks) - for `gpython -m mod` add to sys.path[0] realpath('') instead of ''. This exactly matches PY3 behaviour, while PY2 behaviour is to add '' However PY3 behaviour * is more sane, and * fixes test_defer_excchain_traceback on py27-gevent -> so we stick to it. Now all tests pass again.
-
Kirill Smelkov authored
GPython preimports golang and gevent, but until now, it was preimporting them before adjusting sys.path according to given -c/-m/file/... And this was leading to difference in behaviour with standard Python where e.g. `import golang` might result in different files loaded if e.g. golang/ is there on cwd and -c/-m was given. -> Rework gpython startup so that golang/gevent preimport happens after sys.path initialization. This fixes `tox -e py27-gevent` which was previously failing on test_defer_excchain_dump_pytest / test_defer_excchain_dump_ipython because dumped paths were different than expected ones. It, however, breaks test_defer_excchain_traceback on py27-gevent. -> We'll do more fixups to sys.path handling in the next patch which will fix that failure as well.
-
Kirill Smelkov authored
We'll need this in the next patch, where golang/gevent preimport will be moved from "before call to pymain", to "in between option parsing and interpreter start".
-
Kirill Smelkov authored
We'll need warnings control in the next patch to fix Pytest integration wrt python3-dbg with `-W ignore::DeprecationWarning`.
-
- 21 Sep, 2020 1 commit
-
-
Kirill Smelkov authored
Reorganize parsiong of command line options so that first all options are parsed in a loop, and only after that a module/file/command is executed. This is needed as preparatory step for next patch: there we'll add support for -W, and `-W arg` can be given multiple times and has to be processed multiple times by creating multiple corresponding warning filters. Because those warning filters has to be applied uniformly to all 4 codepaths of execution phase (-m/-c/file/interactive console), it makes sense to move execution phase to after options parsing and inject common runtime preparatory steps right before that. This logic generally applies not only to -W, but to all other python options - e.g. -Q,-u,...
-
- 30 Jul, 2020 4 commits
-
-
Kirill Smelkov authored
Until now gpython was always activating gevent on startup + adding goodness such as "always UTF-8 default encoding"; go, chan, b/u and friends available from builtin namespace, etc... While those goodness are sometimes useful on their own, it is not always appropriate to force a project to switch from threads to gevent. For this reason add a flag to select which runtime - either gevent or threads - gpython should use. gpython -Xgpython.runtime=gevent selects gevent, while gpython -Xgpython.runtime=threads selects threads. Gevent remains the default. It is also possible to specify desired runtime via $GPYTHON_RUNTIME environment variable. /reviewed-on !5
-
Kirill Smelkov authored
Restructure code a bit to prepare it for the next patch. Plain code movement. /reviewed-on !5
-
Kirill Smelkov authored
On CPython: $ python -V Python 2.7.18 $ gpython -V GPython 0.0.6.post2 [gevent 20.6.2] / CPython 2.7.18 On PyPy: $ python -V Python 3.6.9 (2ad108f17bdb, Apr 07 2020, 02:59:05) [PyPy 7.3.1 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] $ gpython -V GPython 0.0.6.post2 [gevent 20.5.0] / PyPy 7.3.1 / Python 3.6.9 /reviewed-on !5
-
Kirill Smelkov authored
And same for -m<module> - becuase Python supports it this way. Before the patch: $ python '-cprint "hello world"' hello world $ gpython '-cprint "hello world"' unknown option: '-cprint "hello world"' After the patch: $ python '-cprint "hello world"' hello world $ gpython '-cprint "hello world"' hello world /reviewed-on !5
-
- 07 Jul, 2020 1 commit
-
-
Kirill Smelkov authored
kirr@deco:~$ python3.8 -v import _frozen_importlib # frozen import _imp # builtin import '_thread' # <class '_frozen_importlib.BuiltinImporter'> import '_warnings' # <class '_frozen_importlib.BuiltinImporter'> import '_weakref' # <class '_frozen_importlib.BuiltinImporter'> import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'> import '_io' # <class '_frozen_importlib.BuiltinImporter'> import 'marshal' # <class '_frozen_importlib.BuiltinImporter'> import 'posix' # <class '_frozen_importlib.BuiltinImporter'> import _thread # previously loaded ('_thread') import '_thread' # <class '_frozen_importlib.BuiltinImporter'> import _weakref # previously loaded ('_weakref') import '_weakref' # <class '_frozen_importlib.BuiltinImporter'> # installing zipimport hook import 'time' # <class '_frozen_importlib.BuiltinImporter'> <-- NOTE import 'zipimport' # <class '_frozen_importlib.FrozenImporter'> # installed zipimport hook See https://github.com/python/cpython/commit/79d1c2e6c9d1 for details (`import time` in zipimport.py)
-
- 29 May, 2020 1 commit
-
-
Kirill Smelkov authored
Gevent is major component gpython builds on - it deserves to be included into version and is handy to know if one hits a bug with gpython - to see in which particular runtime environment the bug was hit. Before: $ gpython Python 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] [GPython 0.0.6.post2] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> After: $ gpython Python 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] [GPython 0.0.6.post2] [gevent 20.5.1] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> /cc @gabriel, @jerome /proposed-for-review-on: !4
-
- 10 Feb, 2020 1 commit
-
-
Kirill Smelkov authored
The first step to expose errors and error chaining to Python: - Add pyerror that wraps a pyx/nogil C-level error and is exposed as golang.error at py level. - py errors must be compared by ==, not by "is" - Add (py) errors.New to create a new error from text. - a C-level error that has .Unwrap, is exposed with .Unwrap at py level, but full py-level chaining will be implemented in a follow-up patch. - py error does not support inheritance yet. Top-level documentation is TODO.
-
- 04 Feb, 2020 1 commit
-
-
Kirill Smelkov authored
With Python3 I've got tired to constantly use .encode() and .decode(); getting exception if original argument was unicode on e.g. b.decode(); getting exception on raw bytes that are invalid UTF-8, not being able to use bytes literal with non-ASCII characters, etc. So instead of this pain provide two functions that make sure an object is either bytes or unicode: - b converts str/unicode/bytes s to UTF-8 encoded bytestring. Bytes input is preserved as-is: b(bytes_input) == bytes_input Unicode input is UTF-8 encoded. The encoding always succeeds. b is reverse operation to u - the following invariant is always true: b(u(bytes_input)) == bytes_input - u converts str/unicode/bytes s to unicode string. Unicode input is preserved as-is: u(unicode_input) == unicode_input Bytes input is UTF-8 decoded. The decoding always succeeds and input information is not lost: non-valid UTF-8 bytes are decoded into surrogate codes ranging from U+DC80 to U+DCFF. u is reverse operation to b - the following invariant is always true: u(b(unicode_input)) == unicode_input NOTE: encoding _and_ decoding *never* fail nor loose information. This is achieved by using 'surrogateescape' error handler on Python3, and providing manual fallback that behaves the same way on Python2. The naming is chosen with the idea so that b(something) resembles b"something", and u(something) resembles u"something". This, even being only a part of strings solution discussed in [1], should help handle byte- and unicode- strings in more robust and distraction free way. Top-level documentation is TODO. [1] zodbtools!13
-
- 03 Oct, 2019 1 commit
-
-
Kirill Smelkov authored
sys is imported in the beginning of main, so there is no need to import it the second time in the middle of main. The bug was there since gpython day1 - since 32a21d5b (gpython: Python interpreter with support for lightweight threads).
-
- 26 Aug, 2019 4 commits
-
-
Kirill Smelkov authored
-
Kirill Smelkov authored
pyrun runs command without piping output. pyout runs command and returns its output.
-
Kirill Smelkov authored
We'll need to use this utility in other places; golang_test is the central place for testing utilities.
-
Kirill Smelkov authored
gpython/gpython_test.py:23: 'subprocess' imported but unused gpython/gpython_test.py:24: 'six.PY3' imported but unused
-
- 14 May, 2019 1 commit
-
-
Kirill Smelkov authored
- we are going to introduce golang.time, and from inside there without `from __future__ import absolute_imports` it won't be possible to import needed stdlib's time. - we were already doing `from __future__ import print_function`, but only in some files. -> It makes sense to apply updated __future__ usage uniformly.
-
- 24 Mar, 2019 1 commit
-
-
Kirill Smelkov authored
pypy-gevent runtests: commands[0] | gpython -m pytest gpython/ golang/ Traceback (most recent call last): File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/bin/gpython", line 10, in <module> sys.exit(main()) File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gpython/__init__.py", line 153, in main _ = monkey.patch_all() # XXX sys=True ? File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 976, in patch_all patch_thread(Event=Event, _warnings=_warnings) File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 178, in ignores return func(*args, **kwargs) File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 588, in patch_thread _patch_existing_locks(threading_mod) File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 492, in _patch_existing_locks if o._RLock__owner is not None: AttributeError: 'thread.RLock' object has no attribute '_RLock__owner' It will be fixed on next Gevent release, however until then the crash is there and we have to workaround: we can skip patching existing locks as it will be the same behaviour of next Gevent release, since its just not possible to patch locks created via instantiated C-level classes: https://github.com/gevent/gevent/commit/d0e04658 We are doing monkey-patching very early, so it should be safe.
-
- 19 Mar, 2019 1 commit
-
-
Kirill Smelkov authored
PyPy7 always pre-imports the time module. Without the change tests were failing: Traceback (most recent call last): File "/home/kirr/src/tools/go/pygolang/.tox/pypy3-gevent/bin/gpython", line 10, in <module> sys.exit(main()) File "/home/kirr/src/tools/go/pygolang/.tox/pypy3-gevent/site-packages/gpython/__init__.py", line 145, in main '\n\n\t%s\n\nsys.modules:\n\n\t%s' % (bad, sysmodv)) RuntimeError: gpython: internal error: the following modules are pre-imported, but must be not: ['time'] sys.modules: ['__future__', '__main__', '__pypy__', '__pypy__._pypydatetime', '__pypy__.builders', '__pypy__.intop', '__pypy__.os', '__pypy__.thread', '__pypy__.time', '_ast', '_bootlocale', '_codecs', '_collections', '_collections_abc', '_continuation', '_csv', '_frozen_importlib', '_frozen_importlib_external', '_imp', '_io', '_locale', '_multibytecodec', '_operator', '_rawffi', '_rawffi.alt', '_signal', '_sre', '_structseq', '_thread', '_warnings', '_weakref', '_weakrefset', 'abc', 'array', 'builtins', 'codecs', 'copyreg', 'encodings', 'encodings.aliases', 'encodings.ascii', 'encodings.latin_1', 'encodings.utf_8', 'errno', 'gc', 'genericpath', 'gpython', 'marshal', 'os', 'os.path', 'posix', 'posixpath', 'pwd', 're', 'site', 'sre_compile', 'sre_constants', 'sre_parse', 'stat', 'sys', 'time', 'unicodedata']
-
- 13 Mar, 2019 1 commit
-
-
Kirill Smelkov authored
Pymain was not adding e.g. directory of executed file to sys.path, and as the result if there were e.g. 2 files dir/hello.py # imports world dir/world.py running `gpython dir/hello.py` would fail to import world. The case for interactive console was also failing to setup sys.argv as empty, so it was containing ['/path/to/gpython']. It was also, contrary to standard python, unconditionally showing '>>>' prompt even when stdin was not a tty. Fix all that and add a test to cover pymain functionality.
-
- 16 Jan, 2019 1 commit
-
-
Kirill Smelkov authored
Provide gpython interpreter, that sets UTF-8 as default encoding, integrates gevent and puts go, chan, select etc into builtin namespace. Please see details in the documentation added by this patch. pymain was taken from kirr/go123@7a476082 (go123: tracing/pyruntraced: New tool to run Python code with tracepoints activated (draft))
-