pkglist.append('.'.join(path)) elif not dirnames: filenames = [] for filename in filenames: mod_name, ext = os.path.splitext(filename) if ext != '.py': continue path = dirpath[len(pypath) + len(os.sep):].split( os.sep) + [mod_name] if not path[0]: path = path[1:] mod_name = '.'.join(path).lstrip('.') if filename == '__init__.py': mod_name = '.'.join(path[:-1]).lstrip('.') mod_path = 'Lib/' + '/'.join(path) if not git.in_index(mod_path): print(mod_path, 'not in index') continue if filename == '__init__.py': pkglist.append(mod_name) else: pylist.append(mod_name) pylist.sort() out.write("var pylist = ['%s']\n" % "','".join(pylist)) pkglist.sort() out.write("for(var i = 0; i < pylist.length; i++)" + "{$B.stdlib[pylist[i]] = ['py']}\n\n") jspath = os.path.join(libfolder, 'libs') jslist = [] for dirpath, dirnames, filenames in os.walk(jspath):
def process(filename, exclude_dirs=['test','site-packages']): """Process a VFS filename for Brython.""" print("Generating {}".format(filename)) nb = 0 nb_err = 0 main_root = os.path.dirname(filename) VFS = {} for stdlib_dir in ("libs", "Lib"): lib_path = os.path.join(main_root, stdlib_dir) for root, _dir, files in os.walk(lib_path): flag = False root_elts = root.split(os.sep) for exclude in exclude_dirs: if exclude in root_elts: flag = True continue if flag: continue # skip these modules if '__pycache__' in _dir: _dir.remove("__pycache__") nb += 1 if stdlib_dir == "Lib": if root == lib_path: package = [] else: package = root[len(lib_path) + 1:].split(os.sep) for _file in files: ext = os.path.splitext(_file)[1] if ext not in ('.js', '.py'): continue if re.match(r'^module\d+\..*$', _file): continue if not git.in_index(_file): continue nb += 1 file_name = os.path.join(root, _file) with open(file_name, encoding='utf-8') as f: data = f.read() if ext == '.py': data = python_minifier.minify(data, preserve_lines=True) path_elts = package[:] if os.path.basename(filename) != "__init__.py": path_elts.append(os.path.basename(file_name)[:-3]) fqname = ".".join(path_elts) with open(os.path.join(root, file_name), encoding="utf-8") as f: tree = ast.parse(f.read()) visitor = Visitor(lib_path, package) visitor.visit(tree) imports = sorted(list(visitor.imports)) vfs_path = os.path.join(root, _file).replace(main_root, '') vfs_path = vfs_path.replace("\\", "/") if vfs_path.startswith('/libs/crypto_js/rollups/'): if _file not in ('md5.js', 'sha1.js', 'sha3.js', 'sha224.js', 'sha256.js', 'sha384.js', 'sha512.js'): continue mod_name = vfs_path[len(stdlib_dir) + 2:].replace('/', '.') mod_name, ext = os.path.splitext(mod_name) is_package = mod_name.endswith('__init__') if ext == ".py": if is_package: mod_name = mod_name[:-9] VFS[mod_name] = [ext, data, imports, 1] else: VFS[mod_name] = [ext, data, imports] else: VFS[mod_name] = [ext, data] print("adding {}".format(mod_name)) print('{} files, {} errors'.format(nb, nb_err)) with open(filename, "w") as out: out.write('__BRYTHON__.use_VFS = true;\n') out.write('__BRYTHON__.VFS={}\n\n'.format(json.dumps(VFS)))
def process(filename, exclude_dirs=['test','site-packages']): """Process a VFS filename for Brython.""" print("Generating {}".format(filename)) nb = 0 nb_err = 0 main_root = os.path.dirname(filename) VFS = {} for stdlib_dir in ("libs", "Lib"): lib_path = os.path.join(main_root, stdlib_dir) for root, _dir, files in os.walk(lib_path): flag = False root_elts = root.split(os.sep) for exclude in exclude_dirs: if exclude in root_elts: flag = True continue if flag: continue # skip these modules if '__pycache__' in _dir: _dir.remove("__pycache__") nb += 1 if stdlib_dir == "Lib": if root == lib_path: package = [] else: package = root[len(lib_path) + 1:].split(os.sep) for _file in files: ext = os.path.splitext(_file)[1] if ext not in ('.js', '.py'): continue if re.match(r'^module\d+\..*$', _file): continue if not git.in_index(_file): print(_file, "not in git index") continue nb += 1 file_name = os.path.join(root, _file) with open(file_name, encoding='utf-8') as f: data = f.read() if ext == '.py': data = python_minifier.minify(data, preserve_lines=True) path_elts = package[:] if os.path.basename(filename) != "__init__.py": path_elts.append(os.path.basename(file_name)[:-3]) fqname = ".".join(path_elts) with open(os.path.join(root, file_name), encoding="utf-8") as f: tree = ast.parse(f.read()) visitor = Visitor(lib_path, package) visitor.visit(tree) imports = sorted(list(visitor.imports)) vfs_path = os.path.join(root, _file).replace(main_root, '') vfs_path = vfs_path.replace("\\", "/") if vfs_path.startswith('/libs/crypto_js/rollups/'): if _file not in ('md5.js', 'sha1.js', 'sha3.js', 'sha224.js', 'sha256.js', 'sha384.js', 'sha512.js'): continue mod_name = vfs_path[len(stdlib_dir) + 2:].replace('/', '.') mod_name, ext = os.path.splitext(mod_name) is_package = mod_name.endswith('__init__') if ext == ".py": if is_package: mod_name = mod_name[:-9] VFS[mod_name] = [ext, data, imports, 1] else: VFS[mod_name] = [ext, data, imports] else: VFS[mod_name] = [ext, data] print("adding {}".format(mod_name)) print('{} files, {} errors'.format(nb, nb_err)) with open(filename, "w") as out: out.write('__BRYTHON__.use_VFS = true;\n') out.write('var scripts = {}\n'.format(json.dumps(VFS))) out.write('__BRYTHON__.update_VFS(scripts)\n')
path = dirpath[len(pypath)+len(os.sep):].split(os.sep) pkglist.append('.'.join(path)) elif not dirnames: filenames = [] for filename in filenames: mod_name, ext = os.path.splitext(filename) if ext != '.py': continue path = dirpath[len(pypath)+len(os.sep):].split(os.sep)+[mod_name] if not path[0]: path = path[1:] mod_name = '.'.join(path).lstrip('.') if filename == '__init__.py': mod_name = '.'.join(path[:-1]).lstrip('.') mod_path = 'Lib/'+'/'.join(path) if not git.in_index(mod_path): print(mod_path, 'not in index') continue if filename == '__init__.py': pkglist.append(mod_name) else: pylist.append(mod_name) pylist.sort() out.write("var pylist = ['%s']\n" % "','".join(pylist)) pkglist.sort() out.write( "for(var i = 0; i < pylist.length; i++)" + "{$B.stdlib[pylist[i]] = ['py']}\n\n") jspath = os.path.join(libfolder, 'libs') jslist = []
if '.git' in dirnames: dirnames.remove('.git') for dirname in dirnames: if dirname == 'dist': continue if "site-packages" in dirpath: continue path = dirpath[len(brython_stdlib_folder) + 1:] python_path = os.path.join(python_stdlib_folder, path) if path.startswith('Lib\\test'): continue if not git.in_index(path.replace("\\", "/")): continue if path: valid = [ f for f in filenames if os.path.splitext(f)[1] not in ['.pyc'] ] valid = [ v for v in valid if git.in_index(os.path.join(path, v).replace("\\", "/")) ] valid = [v for v in valid if v.startswith('_')] + \ [v for v in valid if not v.startswith('_')] if valid: