brython 3.14.3__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- brython/__init__.py +1 -0
- brython/__main__.py +294 -0
- brython/data/README.txt +13 -0
- brython/data/brython.js +38538 -0
- brython/data/brython_stdlib.js +3 -0
- brython/data/demo.html +1272 -0
- brython/data/index.html +18 -0
- brython/data/unicode.txt +41056 -0
- brython/list_modules.py +725 -0
- brython/make_file_system.py +60 -0
- brython/make_package.py +121 -0
- brython/python_minifier.py +165 -0
- brython-3.14.3.dist-info/METADATA +34 -0
- brython-3.14.3.dist-info/RECORD +16 -0
- brython-3.14.3.dist-info/WHEEL +5 -0
- brython-3.14.3.dist-info/entry_points.txt +2 -0
brython/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '3.14.3'
|
brython/__main__.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"""This script creates the basic structure of a Brython project in the
|
|
2
|
+
current directory.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import argparse
|
|
8
|
+
import pathlib
|
|
9
|
+
|
|
10
|
+
implementation = "3.14.3"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
parser = argparse.ArgumentParser()
|
|
15
|
+
subparsers = parser.add_subparsers(title='subcommands', dest='subcommand',
|
|
16
|
+
help="Use --help with any subcommand to see more details")
|
|
17
|
+
|
|
18
|
+
# Init
|
|
19
|
+
init_parser = subparsers.add_parser('install', aliases=['init'],
|
|
20
|
+
help='Install Brython in an empty directory',
|
|
21
|
+
description='Initialize an empty directory with basic Brython files '
|
|
22
|
+
'(brython.js, brython_stdlib.js etc)')
|
|
23
|
+
init_parser.add_argument('--install-dir', default=os.getcwd(),
|
|
24
|
+
help='Install Brython to this directory (default to current dir)')
|
|
25
|
+
init_parser.add_argument('--no-demo', action='store_true',
|
|
26
|
+
help="Do not install demo file demo.html")
|
|
27
|
+
|
|
28
|
+
# Update
|
|
29
|
+
update_parser = subparsers.add_parser('update',
|
|
30
|
+
help='Update Brython scripts (brython.js, brython_stdlib.js)',
|
|
31
|
+
description="Replace brython scripts in selected dir "
|
|
32
|
+
"with latest known to brython-cli")
|
|
33
|
+
|
|
34
|
+
update_parser.add_argument('--update-dir',
|
|
35
|
+
help='Update Brython scripts in this directory '
|
|
36
|
+
'(default to current dir)')
|
|
37
|
+
|
|
38
|
+
# Add package
|
|
39
|
+
add_package_parser = subparsers.add_parser('add_package',
|
|
40
|
+
help="Add already-installed Python package to Brython project",
|
|
41
|
+
description="Add an already-installed, pure-Python package "
|
|
42
|
+
"from current CPython environment "
|
|
43
|
+
"into current Brython project's ./Lib/site-packages")
|
|
44
|
+
|
|
45
|
+
add_package_parser.add_argument('package', help="package name")
|
|
46
|
+
add_package_parser.add_argument('--dest-dir',
|
|
47
|
+
help="Optionally specify alternate destination dir")
|
|
48
|
+
|
|
49
|
+
# Make package
|
|
50
|
+
make_package_parser = subparsers.add_parser('make_package',
|
|
51
|
+
help="Make a browser loadable Python package script",
|
|
52
|
+
description="Make a loadable {package_name}.brython.js package file "
|
|
53
|
+
"from regular python package")
|
|
54
|
+
|
|
55
|
+
make_package_parser.add_argument('package_name',
|
|
56
|
+
help="name used to import this package. as in (`import {package_name}`)")
|
|
57
|
+
make_package_parser.add_argument('--src-dir', metavar='SOURCE_DIR',
|
|
58
|
+
default=os.getcwd(),
|
|
59
|
+
help="package source dir (defaults to current dir)")
|
|
60
|
+
make_package_parser.add_argument('--exclude-dirs', nargs='+', metavar='EXCLUDE_DIR',
|
|
61
|
+
help="directories under src-dir to exclude")
|
|
62
|
+
make_package_parser.add_argument('-o', '--output-path',
|
|
63
|
+
help="package file output path (defaults to {package_name}.brython.js in source dir)")
|
|
64
|
+
|
|
65
|
+
# Make modules
|
|
66
|
+
make_modules_parser = subparsers.add_parser('make_modules',
|
|
67
|
+
help="Create brython_modules.js with all the modules used by the application",
|
|
68
|
+
description="Create brython_modules.js with all the modules used by the application")
|
|
69
|
+
|
|
70
|
+
make_modules_parser.add_argument('-o', '--output-path',
|
|
71
|
+
help='Optionally specify modules file output path')
|
|
72
|
+
|
|
73
|
+
make_modules_parser.add_argument('--reset', help='Reset brython_modules.js to stdlib',
|
|
74
|
+
action="store_true")
|
|
75
|
+
|
|
76
|
+
make_modules_parser.add_argument('--modules_paths',
|
|
77
|
+
help='Location of file with linefeed-separated list of paths')
|
|
78
|
+
|
|
79
|
+
# Server
|
|
80
|
+
start_server_parser = subparsers.add_parser('start_server',
|
|
81
|
+
help="Start development server",
|
|
82
|
+
description="Start development server")
|
|
83
|
+
|
|
84
|
+
start_server_parser.add_argument('port', nargs="?", default=8000, type=int,
|
|
85
|
+
help='Start development server on given port')
|
|
86
|
+
|
|
87
|
+
start_server_parser.add_argument('--bind', metavar='ADDRESS', default='localhost',
|
|
88
|
+
help='Address on which server should listen (default: localhost)')
|
|
89
|
+
|
|
90
|
+
# Others
|
|
91
|
+
make_dist_parser = subparsers.add_parser('make_dist',
|
|
92
|
+
help="Make a Python (PyPI) distribution",
|
|
93
|
+
description="Make a Python distribution https://brython.info/static_doc/en/deploy.html")
|
|
94
|
+
|
|
95
|
+
make_file_system_parser = subparsers.add_parser('make_file_system',
|
|
96
|
+
help="Make a virtual file system",
|
|
97
|
+
description="Make a virtual file system")
|
|
98
|
+
|
|
99
|
+
make_file_system_parser.add_argument('vfs_name',
|
|
100
|
+
help='Name of the file system')
|
|
101
|
+
make_file_system_parser.add_argument('prefix', nargs='?',
|
|
102
|
+
help='Prefix for file paths')
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
parser.add_argument('--version', help='Brython version number',
|
|
106
|
+
action="store_true")
|
|
107
|
+
|
|
108
|
+
args = parser.parse_args()
|
|
109
|
+
|
|
110
|
+
match args.subcommand:
|
|
111
|
+
|
|
112
|
+
case 'add_package':
|
|
113
|
+
print('add package {}...'.format(args.package))
|
|
114
|
+
package = __import__(args.package)
|
|
115
|
+
package_file = package.__file__
|
|
116
|
+
package_dir = os.path.dirname(package_file)
|
|
117
|
+
lib_dir = os.path.join(os.getcwd(), 'Lib')
|
|
118
|
+
if not os.path.exists(lib_dir):
|
|
119
|
+
os.mkdir(lib_dir)
|
|
120
|
+
dest_dir = os.path.join(lib_dir, 'site-packages') if (not args.dest_dir) else args.dest_dir
|
|
121
|
+
if not os.path.exists(dest_dir):
|
|
122
|
+
os.mkdir(dest_dir)
|
|
123
|
+
|
|
124
|
+
if os.path.splitext(package_dir)[1] == '.egg':
|
|
125
|
+
import zipfile
|
|
126
|
+
zf = zipfile.ZipFile(package_dir)
|
|
127
|
+
for info in zf.infolist():
|
|
128
|
+
if info.filename.startswith(('__pycache__', 'EGG-INFO')):
|
|
129
|
+
continue
|
|
130
|
+
zf.extract(info, dest_dir)
|
|
131
|
+
print('extract', info.filename)
|
|
132
|
+
zf.close()
|
|
133
|
+
print('done')
|
|
134
|
+
elif not package_dir.split(os.sep)[-1] == "site-packages":
|
|
135
|
+
print('copy folder', package_dir)
|
|
136
|
+
dest_dir = os.path.join(dest_dir, args.package)
|
|
137
|
+
if os.path.exists(dest_dir):
|
|
138
|
+
shutil.rmtree(dest_dir)
|
|
139
|
+
shutil.copytree(package_dir, dest_dir)
|
|
140
|
+
else:
|
|
141
|
+
print('copy single file', package_file)
|
|
142
|
+
shutil.copyfile(package_file, os.path.join(dest_dir,
|
|
143
|
+
os.path.basename(package_file)))
|
|
144
|
+
|
|
145
|
+
case 'install' | 'init':
|
|
146
|
+
print('Installing Brython {}'.format(implementation))
|
|
147
|
+
|
|
148
|
+
data_path = os.path.join(os.path.dirname(__file__), 'data')
|
|
149
|
+
install_dir = args.install_dir
|
|
150
|
+
install_dir_files = os.listdir(install_dir)
|
|
151
|
+
|
|
152
|
+
if install_dir_files and 'brython.js' in install_dir_files:
|
|
153
|
+
override = input(
|
|
154
|
+
'brython.js is already present in this directory.'
|
|
155
|
+
' Override ? (Y/N)'
|
|
156
|
+
)
|
|
157
|
+
if override.lower() != 'y':
|
|
158
|
+
import sys
|
|
159
|
+
print('exiting')
|
|
160
|
+
sys.exit()
|
|
161
|
+
|
|
162
|
+
for path in os.listdir(data_path):
|
|
163
|
+
# note: here '/' is pathlib.Path join operator
|
|
164
|
+
if args.no_demo and \
|
|
165
|
+
(path.endswith('.html') or path == 'README.txt'):
|
|
166
|
+
continue
|
|
167
|
+
dest_path = pathlib.Path(install_dir) / pathlib.Path(path)
|
|
168
|
+
try:
|
|
169
|
+
shutil.copyfile(os.path.join(data_path, path), dest_path)
|
|
170
|
+
except shutil.SameFileError:
|
|
171
|
+
print(f'{path} has not been moved. Are the same file.')
|
|
172
|
+
|
|
173
|
+
print('done')
|
|
174
|
+
|
|
175
|
+
case 'update':
|
|
176
|
+
print('Update Brython scripts to version {}'.format(implementation))
|
|
177
|
+
# here '/' is Path join operator
|
|
178
|
+
data_path = pathlib.Path(os.path.dirname(__file__)) / 'data'
|
|
179
|
+
update_dir = pathlib.Path(args.update_dir)
|
|
180
|
+
|
|
181
|
+
# Update only specific safe files, as user may have customized index.html etc
|
|
182
|
+
for path in ['brython.js', 'brython_stdlib.js']:
|
|
183
|
+
dest_path = pathlib.Path(update_dir) / pathlib.Path(path)
|
|
184
|
+
shutil.copyfile(os.path.join(data_path, path), dest_path)
|
|
185
|
+
|
|
186
|
+
case 'make_modules':
|
|
187
|
+
if args.reset:
|
|
188
|
+
print('Reset brython_modules.js to local standard distribution')
|
|
189
|
+
stdlib_file_path = pathlib.Path.cwd() / 'brython_stdlib.js'
|
|
190
|
+
modules_file_path = (
|
|
191
|
+
args.output_path if args.output_path
|
|
192
|
+
else pathlib.Path.cwd() / 'brython_modules.js')
|
|
193
|
+
shutil.copyfile(stdlib_file_path, modules_file_path)
|
|
194
|
+
else:
|
|
195
|
+
print('Create brython_modules.js with all the modules used by the '
|
|
196
|
+
'application')
|
|
197
|
+
from . import list_modules
|
|
198
|
+
|
|
199
|
+
print('searching brython_stdlib.js...')
|
|
200
|
+
stdlib_dir, stdlib = list_modules.load_stdlib_sitepackages()
|
|
201
|
+
|
|
202
|
+
print('finding packages...')
|
|
203
|
+
if args.modules_paths is not None:
|
|
204
|
+
if not os.path.exists(args.modules_paths):
|
|
205
|
+
raise FileNotFoundError(
|
|
206
|
+
f'Modules path "{args.modules_paths}" not found')
|
|
207
|
+
user_modules = list_modules.load_user_modules(args.modules_paths)
|
|
208
|
+
finder = list_modules.ModulesFinder(stdlib=stdlib, user_modules=user_modules)
|
|
209
|
+
finder.inspect()
|
|
210
|
+
path = os.path.join(stdlib_dir, "brython_modules.js")
|
|
211
|
+
output_path = path if (not args.output_path) else args.output_path
|
|
212
|
+
finder.make_brython_modules(output_path)
|
|
213
|
+
|
|
214
|
+
case 'make_dist':
|
|
215
|
+
print('Make a Python distribution for the application')
|
|
216
|
+
from . import list_modules
|
|
217
|
+
|
|
218
|
+
print('searching brython_stdlib.js...')
|
|
219
|
+
stdlib_dir, stdlib = list_modules.load_stdlib_sitepackages()
|
|
220
|
+
|
|
221
|
+
print('finding packages...')
|
|
222
|
+
user_modules = list_modules.load_user_modules()
|
|
223
|
+
finder = list_modules.ModulesFinder(stdlib=stdlib, user_modules=user_modules)
|
|
224
|
+
finder.inspect()
|
|
225
|
+
path = os.path.join(stdlib_dir, "brython_modules.js")
|
|
226
|
+
finder.make_brython_modules(path)
|
|
227
|
+
finder.make_setup()
|
|
228
|
+
print('done')
|
|
229
|
+
|
|
230
|
+
case 'make_file_system':
|
|
231
|
+
print('Create a Javascript file for all the files in the directory')
|
|
232
|
+
from .make_file_system import make
|
|
233
|
+
make(args.vfs_name, args.prefix)
|
|
234
|
+
print('done')
|
|
235
|
+
|
|
236
|
+
case 'make_package':
|
|
237
|
+
package_name = args.package_name
|
|
238
|
+
package_path = args.src_dir
|
|
239
|
+
exclude_dirs = args.exclude_dirs
|
|
240
|
+
output_path = args.output_path
|
|
241
|
+
from . import make_package
|
|
242
|
+
make_package.make(package_name, package_path, exclude_dirs, output_path)
|
|
243
|
+
print("done")
|
|
244
|
+
|
|
245
|
+
case 'start_server':
|
|
246
|
+
# start development server
|
|
247
|
+
from aiohttp import web
|
|
248
|
+
|
|
249
|
+
app = web.Application()
|
|
250
|
+
|
|
251
|
+
async def root_handler(request):
|
|
252
|
+
return web.HTTPFound('/index.html')
|
|
253
|
+
|
|
254
|
+
app.router.add_route('*', '/', root_handler)
|
|
255
|
+
app.add_routes([web.static('/', os.getcwd())])
|
|
256
|
+
|
|
257
|
+
web.run_app(app, port=args.port, host=args.bind)
|
|
258
|
+
|
|
259
|
+
print("Brython development server. "
|
|
260
|
+
"Not meant to be used in production.")
|
|
261
|
+
|
|
262
|
+
print("For a different port provide start_server PORT. (ex 8888, 8080).")
|
|
263
|
+
print("For a different listening address provide command-line option "
|
|
264
|
+
"'--bind ADDRESS' (ex 'localhost', '0.0.0.0').")
|
|
265
|
+
print("Press CTRL+C to Quit.\n")
|
|
266
|
+
|
|
267
|
+
case None:
|
|
268
|
+
# # Note: This may be uncommented when compat mode is removed
|
|
269
|
+
# Arguments independent of subcommand
|
|
270
|
+
# if args.version:
|
|
271
|
+
# print('Brython version', implementation)
|
|
272
|
+
|
|
273
|
+
# For totally clueless -> print_help
|
|
274
|
+
import sys
|
|
275
|
+
if len(sys.argv[1:]) == 0:
|
|
276
|
+
parser.print_help()
|
|
277
|
+
|
|
278
|
+
# Compatibility mode (old style)
|
|
279
|
+
warning = ("Option --{0} will be deprecated in the next release. "
|
|
280
|
+
"Please use `brython-cli {0}` instead (see '--help')")
|
|
281
|
+
warning1 = ("Option --{0} will be deprecated in the next release. "
|
|
282
|
+
"Please use `brython-cli {1}` instead (see '--help')")
|
|
283
|
+
|
|
284
|
+
if args.version:
|
|
285
|
+
print('Brython version', implementation)
|
|
286
|
+
|
|
287
|
+
case _:
|
|
288
|
+
print("This subcommand is unknown or not yet implemented")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
if __name__ == "__main__":
|
|
292
|
+
main()
|
|
293
|
+
|
|
294
|
+
|
brython/data/README.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
To run the demo, you can open the file demo.html from the browser "File/Open..." menu.
|
|
2
|
+
|
|
3
|
+
Another option is to start the built-in Python HTTP server by
|
|
4
|
+
|
|
5
|
+
python -m http.server
|
|
6
|
+
|
|
7
|
+
The default port is 8000. To specify another port:
|
|
8
|
+
|
|
9
|
+
python -m http.server 8080
|
|
10
|
+
|
|
11
|
+
Then load http://localhost:<port>/demo.html in the browser address bar.
|
|
12
|
+
|
|
13
|
+
For more information please visit http://brython.info.
|