Skip to content

Commit

Permalink
Add attributes to module sys. Related to issue #2286.
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreQuentel committed Oct 24, 2023
1 parent 6b1735a commit 43b6b8a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
27 changes: 24 additions & 3 deletions www/src/Lib/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def audit(event, *args):

byteorder = 'little'

copyright = """Copyright (c) 2001-2023 Python Software Foundation.
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved."""

dont_write_bytecode = True

exec_prefix = __BRYTHON__.brython_path
Expand Down Expand Up @@ -128,8 +140,15 @@ def set_int_max_str_digits(value):

prefix = __BRYTHON__.brython_path

pycache_prefix = None

stdlib_module_names = frozenset(__BRYTHON__.stdlib_module_names)

def unraisablehook(unraisable, /):
pass # not applicable to Brython, here for compliance

__unraisablehook__ = unraisablehook

version = '.'.join(str(x) for x in __BRYTHON__.version_info[:3])
version += " (default, %s) \n[Javascript 1.5] on Brython" \
% __BRYTHON__.compiled_date
Expand Down Expand Up @@ -209,13 +228,15 @@ def __eq__(self, other):

SimpleNamespace.__module__ = "types"

hexversion = ((__BRYTHON__.version_info[0] << 24) +
( __BRYTHON__.version_info[1] << 16) +
( __BRYTHON__.version_info[2] << 8))

implementation = SimpleNamespace(
name = 'Brython',
cache_tag = f'cpython-{__BRYTHON__.version_info[0]}{__BRYTHON__.version_info[1]}',
version = version_info,
hexversion = ((__BRYTHON__.version_info[0] << 24) +
( __BRYTHON__.version_info[1] << 16) +
( __BRYTHON__.version_info[2] << 8))
hexversion = hexversion
)

hash_info = make_dataclass('hash_info')(
Expand Down
4 changes: 2 additions & 2 deletions www/src/brython.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ $B.stdlib_module_names=Object.keys($B.stdlib)})(__BRYTHON__)
;
__BRYTHON__.implementation=[3,12,0,'dev',0]
__BRYTHON__.version_info=[3,12,0,'final',0]
__BRYTHON__.compiled_date="2023-10-24 15:17:58.006629"
__BRYTHON__.timestamp=1698153478006
__BRYTHON__.compiled_date="2023-10-24 21:35:33.657812"
__BRYTHON__.timestamp=1698176133657
__BRYTHON__.builtin_module_names=["_aio","_ajax","_ast","_base64","_binascii","_cmath","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_random","_sre","_sre1","_sre_utils","_string","_strptime","_svg","_symtable","_tokenize","_webcomponent","_webworker","_zlib_utils","array","builtins","dis","encoding_cp932","hashlib","html_parser","marshal","math","module1","modulefinder","posix","python_re","python_re1","python_re2","unicodedata"]
;
;(function($B){var _b_=$B.builtins
Expand Down
2 changes: 1 addition & 1 deletion www/src/brython_stdlib.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions www/src/version_info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__BRYTHON__.implementation = [3, 12, 0, 'dev', 0]
__BRYTHON__.version_info = [3, 12, 0, 'final', 0]
__BRYTHON__.compiled_date = "2023-10-24 15:17:58.006629"
__BRYTHON__.timestamp = 1698153478006
__BRYTHON__.compiled_date = "2023-10-24 21:35:33.657812"
__BRYTHON__.timestamp = 1698176133657
__BRYTHON__.builtin_module_names = ["_aio",
"_ajax",
"_ast",
Expand Down
2 changes: 2 additions & 0 deletions www/tests/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,7 @@ def traceFn(frame, event, arg):
for attr in ['name', 'cache_tag', 'version', 'hexversion']:
assert hasattr(sys.implementation, attr)

assert hasattr(sys, 'pycache_prefix')

# remove trace for next tests
sys.settrace(None)

0 comments on commit 43b6b8a

Please sign in to comment.