#abs_path = os.path.join(os.getcwd(),'src',folder,path)
                print('add',path,dirpath[len(base):])
                wfunc(os.path.join(dirpath,path),
                    arcname=os.path.join(name,dirpath[len(base)+1:],path))

    arc.close()

import sys
sys.path.append("scripts")

try:
  import make_VFS
except ImportError:
  print("Cannot find make_VFS, so we won't make py_VFS.js")
  sys.exit()

make_VFS.process("src/py_VFS.js")

# changelog file
try:
    _in = open('dist/changelog.txt').read()
    out = open('dist/changelog_%s.txt' %now,'w')
    first = 'Changes in Brython version %s' %now
    out.write('%s\n' %first)
    out.write('%s\n\n' %('='*len(first)))
    out.write(_in)
    out.close()
except:
    print("Warning - no changelog file")

示例#2
0
# Generate page comparing Brython dist and CPython stdlib
import make_stdlib_list

# Generate static documentation pages
import make_doc  # lint:ok

sys.path.append("scripts")

try:
    import make_VFS  # isort:skip
except ImportError:
    print("Cannot find make_VFS, so we won't make py_VFS.js")
    make_VFS = None
    sys.exit()

make_VFS.process(os.path.join(pdir, "www", "src", "py_VFS.js"))
# make distribution with core + libraries
with open(os.path.join(pdir, "www", "src", "brython_dist.js"), "w") as distrib_file:
    distrib_file.write(open(os.path.join(pdir, "www", "src", "brython.js")).read())
    distrib_file.write(open(os.path.join(pdir, "www", "src", "py_VFS.js")).read())

# make_VFS.process_unittest(os.path.join(pdir, 'www', 'src', 'py_unittest.js'))

# zip files
dest_dir = os.path.join(pdir, "dist")
if not os.path.exists(dest_dir):
    os.mkdir(dest_dir)

name = "Brython%s_site_mirror-%s" % (vname, now)
dest_path = os.path.join(dest_dir, name)
示例#3
0
文件: make_dist.py 项目: ivmx/brython
print('size : originals %s compact %s gain %.2f' %(src_size,len(res),100*(src_size-len(res))/src_size))

# version name
vname = '.'.join(str(x) for x in implementation[:3])
if implementation[3]=='rc':
    vname += 'rc%s' %implementation[4]

sys.path.append("scripts")

try:
  import make_VFS
except ImportError:
  print("Cannot find make_VFS, so we won't make py_VFS.js")
  sys.exit()

make_VFS.process(os.path.join(pdir,'src','py_VFS.js'))

# make distribution with core + libraries
out = open(os.path.join(pdir,'src','brython_dist.js'),'wb')
out.write(open(os.path.join(pdir,'src','brython.js')).read())
out.write(open(os.path.join(pdir,'src','py_VFS.js')).read())
out.close()


# zip files
import os
import tarfile
import zipfile

dest_dir = os.path.join(pdir,'dist')
if not os.path.exists(dest_dir):
示例#4
0
def run():
    # update package.json
    package_file = os.path.join(pdir, 'npm', 'package.json')
    with open(package_file, encoding="utf-8") as fobj:
        package_info = fobj.read()
        package_info = re.sub('"version": "(.*)"',
            '"version": "{}"'.format(vname),
            package_info)

    with open(package_file, "w", encoding="utf-8") as fobj:
        fobj.write(package_info)

    abs_path = lambda _pth: os.path.join(os.path.dirname(os.getcwd()), 'www',
        'src', _pth)
    now = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')

    # update version number
    with open(abs_path('version_info.js'), 'w') as vinfo_file_out:
        # implementation[2] = now
        vinfo_file_out.write('__BRYTHON__.implementation = %s\n'
            %implementation)
        vinfo_file_out.write('__BRYTHON__.__MAGIC__ = "%s"\n' %
            '.'.join(['%s' % _i for _i in implementation[:3]]))
        vinfo_file_out.write('__BRYTHON__.version_info = %s\n' % str(version))
        vinfo_file_out.write('__BRYTHON__.compiled_date = "%s"\n'
            %str(datetime.datetime.now()))
        vinfo_file_out.write('__BRYTHON__.timestamp = {}\n'.format(
            int(1000*time.time())))
        # builtin module names = list of scripts in src/libs
        vinfo_file_out.write('__BRYTHON__.builtin_module_names = [')
        _modules = ['"%s"' % fname.split('.')[0]
                   for fname in os.listdir(abs_path('libs'))
                   if fname.endswith('.js')]

        # Sort modules so that git diff's don't change between runs
        _modules.sort()
        vinfo_file_out.write(',\n    '.join(_modules))
        vinfo_file_out.write(']\n')

        #log.info("Finished Writing file: " + abs_path('version_info.js'))

    # generate html files that compare Brython and CPython distributions
    import make_stdlib_list

    import make_stdlib_static
    # build brython.js from base Javascript files
    sources = [
        'unicode.min',
        'brython_builtins', 'version_info', 'py2js',
        'py_object', 'py_type', 'py_utils', 'py_builtin_functions',
        'py_exceptions', 'py_range_slice', 'py_bytes', 'js_objects',
        'stdlib_paths', 'py_import', 'py_float', 'py_int', 'py_long_int',
        'py_complex', 'py_sort', 'py_list', 'py_string', 'py_dict', 'py_set',
        'py_dom', 'py_generator', 'builtin_modules', 'py_import_hooks',
        'async'
    ]

    res = """// brython.js brython.info
// version {}
// implementation {}
// version compiled from commented, indented source files at
// github.com/brython-dev/brython
""".format(version, implementation)
    src_size = 0

    for fname in sources:
        src = open(abs_path(fname)+'.js').read() + '\n'
        src_size += len(src)
        res += javascript_minifier.minify(src)

    res = re.sub(r'\bcontext\b', 'C', res)

    with open(abs_path('brython.js'), 'w') as out:
        out.write(res)

    print(('size : originals %s compact %s gain %.2f' %
          (src_size, len(res), 100 * (src_size - len(res)) / src_size)))

    sys.path.append("scripts")

    try:
        import make_VFS
    except ImportError:
        print("Cannot find make_VFS, so we won't make brython_stdlib.js.js")
        make_VFS = None
        sys.exit()

    make_VFS.process(os.path.join(pdir, 'www', 'src', 'brython_stdlib.js'))

    # Create make brython_stdlib.js : core + libraries
    src_dir = os.path.join(pdir, 'www', 'src')
    with open(os.path.join(src_dir, 'brython_dist.js'), 'w') as distrib:
        distrib.write(open(os.path.join(src_dir, 'brython.js')).read())
        distrib.write(open(os.path.join(src_dir, 'brython_stdlib.js')).read())

    # copy files in folder /setup
    sdir = os.path.join(pdir, 'setup', 'data')

    for f in ['brython.js', 'brython_stdlib.js', 'unicode.txt']:
        shutil.copyfile(os.path.join(src_dir, f), os.path.join(sdir, f))

    # copy demo.html
    with open(os.path.join(pdir, 'www', 'demo.html'), encoding="utf-8") as f:
        demo = f.read()
    start_tag = "<!-- start copy -->"
    end_tag = "<!-- end copy -->"
    start = demo.find(start_tag)
    if start == -1:
        raise Exception("No tag <!-- start copy --> in demo.html")
    end = demo.find(end_tag)
    if end == -1:
        raise Exception("No tag <!-- end copy --> in demo.html")
    body = demo[start + len(start_tag) : end].strip()

    with open(os.path.join(sdir, "demo.tmpl"), encoding="utf-8") as f:
        template = f.read()

    demo = template.replace("{{body}}", body)

    with open(os.path.join(sdir, "demo.html"), "w", encoding="utf-8") as out:
        out.write(demo)

    # copy files in folder /npm
    npmdir = os.path.join(pdir, 'npm')
    for f in ['brython.js', 'brython_stdlib.js', 'unicode.txt']:
        shutil.copyfile(os.path.join(src_dir, f), os.path.join(npmdir, f))

    # create zip files
    print('create zip files in /setup/data')
    name = 'Brython-{}'.format(vname)
    dest_path = os.path.join(sdir, name)
    dist1 = tarfile.open(dest_path + '.tar.gz', mode='w:gz')
    dist2 = tarfile.open(dest_path+'.tar.bz2', mode='w:bz2')
    dist3 = zipfile.ZipFile(dest_path + '.zip', mode='w',
                            compression=zipfile.ZIP_DEFLATED)

    paths = ['README.txt', 'demo.html', 'brython.js', 'brython_stdlib.js',
        'unicode.txt']

    for arc, wfunc in ((dist1, dist1.add), (dist2, dist2.add),
            (dist3, dist3.write)):
        for path in paths:
            wfunc(os.path.join(sdir, path),
                arcname=os.path.join(name, path))

        arc.close()

    # changelog file
    print('write changelog file')
    try:
        first = 'Changes in Brython version {}'.format(vname)
        with open(os.path.join(pdir, 'setup', 'changelog.txt')) as f:
            input_changelog_data_string = f.read()
        with open(os.path.join(pdir, 'setup', 'data',
                'changelog_{}.txt'.format(vname)), 'w') as out:
            out.write('%s\n' % first)
            out.write('%s\n\n' % ('=' * len(first)))
            out.write(input_changelog_data_string)
    except Exception as error:
        print(error)
        print("Warning - no changelog file")
示例#5
0
    #with open('test_ugl.js') as fobj:
    #    src = fobj.read()+'\n'
    #    src_size += len(src)
    #    res += src

res = res.replace('context', 'C')

with open(abs_path('brython.js'), 'w') as the_brythonjs_file_output:
    the_brythonjs_file_output.write(res)

print(('size : originals %s compact %s gain %.2f' %
       (src_size, len(res), 100 * (src_size - len(res)) / src_size)))

sys.path.append("scripts")

try:
    import make_VFS  # isort:skip
except ImportError:
    print("Cannot find make_VFS, so we won't make py_VFS.js")
    make_VFS = None
    sys.exit()

make_VFS.process(os.path.join(pdir, 'www', 'src', 'py_VFS.js'))
# make distribution with core + libraries
with open(os.path.join(pdir, 'www', 'src', 'brython_dist.js'),
          'w') as distrib_file:
    distrib_file.write(
        open(os.path.join(pdir, 'www', 'src', 'brython.js')).read())
    distrib_file.write(
        open(os.path.join(pdir, 'www', 'src', 'py_VFS.js')).read())
示例#6
0
def run():
    # update package.json
    package_file = os.path.join(pdir, 'npm', 'package.json')
    with open(package_file, encoding="utf-8") as fobj:
        package_info = fobj.read()
        package_info = re.sub('"version": "(.*)"',
                              '"version": "{}"'.format(vname), package_info)

    with open(package_file, "w", encoding="utf-8") as fobj:
        fobj.write(package_info)

    abs_path = lambda _pth: os.path.join(os.path.dirname(os.getcwd()), 'www',
                                         'src', _pth)
    now = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')

    # update version number
    with open(abs_path('version_info.js'), 'w') as vinfo_file_out:
        # implementation[2] = now
        vinfo_file_out.write('__BRYTHON__.implementation = %s\n' %
                             implementation)
        vinfo_file_out.write('__BRYTHON__.__MAGIC__ = "%s"\n' %
                             '.'.join(['%s' % _i
                                       for _i in implementation[:3]]))
        vinfo_file_out.write('__BRYTHON__.version_info = %s\n' % str(version))
        vinfo_file_out.write('__BRYTHON__.compiled_date = "%s"\n' %
                             str(datetime.datetime.now()))
        # builtin module names = list of scripts in src/libs
        vinfo_file_out.write('__BRYTHON__.builtin_module_names = ["posix",'
                             '"sys", "errno", "time",')
        _modules = [
            '"%s"' % fname.split('.')[0]
            for fname in os.listdir(abs_path('libs')) if fname.endswith('.js')
        ]

        # Sort modules so that git diff's don't change between runs
        _modules.sort()
        vinfo_file_out.write(',\n    '.join(_modules))

        # Add Python scripts in Lib that start with _ and aren't found in
        # CPython Lib.
        # Using sys.executable to find stdlib dir doesn't work under linux.
        stdlib_path = os.path.dirname(os.__file__)
        stdlib_mods = [f for f in os.listdir(stdlib_path) if f.startswith('_')]
        stdlib_mods.sort()
        brython_mods = [
            f for f in os.listdir(abs_path('Lib'))
            if f.startswith('_') and f != '__pycache__'
        ]
        brython_py_builtins = [
            os.path.splitext(x)[0] for x in brython_mods
            if x not in stdlib_mods
        ]
        brython_py_builtins.sort()
        vinfo_file_out.write(
            ',\n    ' +
            ',\n    '.join(['"%s"' % f for f in brython_py_builtins]))
        vinfo_file_out.write(']\n')

        #log.info("Finished Writing file: " + abs_path('version_info.js'))

    import make_stdlib_static
    # build brython.js from base Javascript files
    sources = [
        'unicode.min', 'brython_builtins', 'version_info', 'py2js',
        'py_object', 'py_type', 'py_utils', 'py_builtin_functions',
        'py_exceptions', 'py_range_slice', 'py_bytes', 'js_objects',
        'stdlib_paths', 'py_import', 'py_float', 'py_int', 'py_long_int',
        'py_complex', 'py_sort', 'py_list', 'py_string', 'py_dict', 'py_set',
        'py_dom', 'py_generator', 'builtin_modules', 'py_import_hooks'
    ]

    res = """// brython.js brython.info
// version {}
// implementation {}
// version compiled from commented, indented source files at
// github.com/brython-dev/brython
""".format(version, implementation)
    src_size = 0

    for fname in sources:
        src = open(abs_path(fname) + '.js').read() + '\n'
        src_size += len(src)
        res += javascript_minifier.minify(src)

    res = res.replace('context', 'C')

    with open(abs_path('brython.js'), 'w') as out:
        out.write(res)

    print(('size : originals %s compact %s gain %.2f' %
           (src_size, len(res), 100 * (src_size - len(res)) / src_size)))

    sys.path.append("scripts")

    try:
        import make_VFS
    except ImportError:
        print("Cannot find make_VFS, so we won't make brython_stdlib.js.js")
        make_VFS = None
        sys.exit()

    make_VFS.process(os.path.join(pdir, 'www', 'src', 'brython_stdlib.js'))

    # Create make brython_stdlib.js : core + libraries
    src_dir = os.path.join(pdir, 'www', 'src')
    with open(os.path.join(src_dir, 'brython_dist.js'), 'w') as distrib:
        distrib.write(open(os.path.join(src_dir, 'brython.js')).read())
        distrib.write(open(os.path.join(src_dir, 'brython_stdlib.js')).read())

    # copy files in folder /setup
    sdir = os.path.join(pdir, 'setup', 'data')
    for f in ['brython.js', 'brython_stdlib.js']:
        shutil.copyfile(os.path.join(src_dir, f), os.path.join(sdir, f))

    # copy files in folder /npm
    npmdir = os.path.join(pdir, 'npm')
    for f in ['brython.js', 'brython_stdlib.js']:
        shutil.copyfile(os.path.join(src_dir, f), os.path.join(npmdir, f))

    # create zip files
    print('create zip files in /setup/data')
    name = 'Brython-{}'.format(vname)
    dest_path = os.path.join(sdir, name)
    dist1 = tarfile.open(dest_path + '.tar.gz', mode='w:gz')
    dist2 = tarfile.open(dest_path + '.tar.bz2', mode='w:bz2')
    dist3 = zipfile.ZipFile(dest_path + '.zip',
                            mode='w',
                            compression=zipfile.ZIP_DEFLATED)

    paths = ['README.txt', 'demo.html', 'brython.js', 'brython_stdlib.js']

    for arc, wfunc in ((dist1, dist1.add), (dist2, dist2.add), (dist3,
                                                                dist3.write)):
        for path in paths:
            wfunc(os.path.join(sdir, path), arcname=os.path.join(name, path))

        arc.close()

    # changelog file
    print('write changelog file')
    try:
        first = 'Changes in Brython version {}'.format(vname)
        with open(os.path.join(pdir, 'setup',
                               'changelog.txt')) as file_to_read:
            input_changelog_data_string = file_to_read.read()
        with open(
                os.path.join(pdir, 'setup', 'data',
                             'changelog_{}.txt'.format(vname)), 'w') as out:
            out.write('%s\n' % first)
            out.write('%s\n\n' % ('=' * len(first)))
            out.write(input_changelog_data_string)
    except Exception as error:
        print(error)
        print("Warning - no changelog file")
示例#7
0
def run():
    # update package.json
    package_file = os.path.join(pdir, 'npm', 'package.json')
    with open(package_file, encoding="utf-8") as fobj:
        package_info = fobj.read()
        package_info = re.sub('"version": "(.*)"',
            '"version": "{}"'.format(vname),
            package_info)

    with open(package_file, "w", encoding="utf-8") as fobj:
        fobj.write(package_info)

    abs_path = lambda _pth: os.path.join(os.path.dirname(os.getcwd()), 'www',
        'src', _pth)
    now = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')

    # update version number
    with open(abs_path('version_info.js'), 'w') as vinfo_file_out:
        # implementation[2] = now
        vinfo_file_out.write('__BRYTHON__.implementation = %s\n'
            %implementation)
        vinfo_file_out.write('__BRYTHON__.__MAGIC__ = "%s"\n' %
            '.'.join(['%s' % _i for _i in implementation[:3]]))
        vinfo_file_out.write('__BRYTHON__.version_info = %s\n' % str(version))
        vinfo_file_out.write('__BRYTHON__.compiled_date = "%s"\n'
            %str(datetime.datetime.now()))
        vinfo_file_out.write('__BRYTHON__.timestamp = {}\n'.format(
            int(1000*time.time())))
        # builtin module names = list of scripts in src/libs
        vinfo_file_out.write('__BRYTHON__.builtin_module_names = [')
        _modules = ['"%s"' % fname.split('.')[0]
                   for fname in os.listdir(abs_path('libs'))
                   if fname.endswith('.js')]

        # Sort modules so that git diff's don't change between runs
        _modules.sort()
        vinfo_file_out.write(',\n    '.join(_modules))
        vinfo_file_out.write(']\n')

        #log.info("Finished Writing file: " + abs_path('version_info.js'))

    # generate html files that compare Brython and CPython distributions
    import make_stdlib_list

    import make_stdlib_static
    # build brython.js from base Javascript files
    sources = [
        'unicode.min',
        'brython_builtins', 'version_info', 'py2js', 'loaders',
        'py_object', 'py_type', 'py_utils', 'py_builtin_functions',
        'py_exceptions', 'py_range_slice', 'py_bytes', 'py_set', 'js_objects',
        'stdlib_paths', 'py_import', 'py_float', 'py_int', 'py_long_int',
        'py_complex', 'py_sort', 'py_list', 'py_string', 'py_dict',
        'py_dom', 'py_generator', 'builtin_modules', 'py_import_hooks',
        'async'
    ]

    res = """// brython.js brython.info
// version {}
// implementation {}
// version compiled from commented, indented source files at
// github.com/brython-dev/brython
""".format(version, implementation)
    src_size = 0

    for fname in sources:
        src = open(abs_path(fname)+'.js').read() + '\n'
        src_size += len(src)
        res += javascript_minifier.minify(src) + ";\n"

    res = re.sub(r'\bcontext\b', 'C', res)

    with open(abs_path('brython.js'), 'w', newline="\n") as out:
        out.write(res)

    print(('size : originals %s compact %s gain %.2f' %
          (src_size, len(res), 100 * (src_size - len(res)) / src_size)))

    sys.path.append("scripts")

    try:
        import make_VFS
    except ImportError:
        print("Cannot find make_VFS, so we won't make brython_stdlib.js.js")
        make_VFS = None
        sys.exit()

    make_VFS.process(os.path.join(pdir, 'www', 'src', 'brython_stdlib.js'))

    # Create brython_dist.js : core + libraries
    src_dir = os.path.join(pdir, 'www', 'src')
    with open(os.path.join(src_dir, 'brython_dist.js'), 'w') as distrib:
        distrib.write(open(os.path.join(src_dir, 'brython.js')).read())
        distrib.write(open(os.path.join(src_dir, 'brython_stdlib.js')).read())

    # update implementation in brython.py
    br_script = os.path.join(pdir, 'setup', 'brython.py')
    with open(br_script, encoding='utf-8') as f:
        br = f.read()
        mo = re.search('^implementation = "(.*)"$', br, flags=re.M)
        if not mo:
            raise Exception("missing implementation in brython.py")
        br_versioned = re.sub('^implementation = "(.*)"$',
                              'implementation = "{}"'.format(vname),
                              br,
                              flags=re.M)
    
    with open(br_script, "w", encoding="utf-8") as out:
        out.write(br_versioned)

    # copy files in folder /setup
    sdir = os.path.join(pdir, 'setup', 'data')

    for f in ['brython.js', 'brython_stdlib.js', 'unicode.txt']:
        shutil.copyfile(os.path.join(src_dir, f), os.path.join(sdir, f))

    # copy demo.html
    with open(os.path.join(pdir, 'www', 'demo.html'), encoding="utf-8") as f:
        demo = f.read()
    start_tag = "<!-- start copy -->"
    end_tag = "<!-- end copy -->"
    start = demo.find(start_tag)
    if start == -1:
        raise Exception("No tag <!-- start copy --> in demo.html")
    end = demo.find(end_tag)
    if end == -1:
        raise Exception("No tag <!-- end copy --> in demo.html")
    body = demo[start + len(start_tag) : end].strip()

    with open(os.path.join(sdir, "demo.tmpl"), encoding="utf-8") as f:
        template = f.read()

    demo = template.replace("{{body}}", body)

    with open(os.path.join(sdir, "demo.html"), "w", encoding="utf-8") as out:
        out.write(demo)

    # copy files in folder /npm
    npmdir = os.path.join(pdir, 'npm')
    for f in ['brython.js', 'brython_stdlib.js', 'unicode.txt']:
        shutil.copyfile(os.path.join(src_dir, f), os.path.join(npmdir, f))

    # create zip files
    print('create zip files in /setup/data')
    name = 'Brython-{}'.format(vname)
    dest_path = os.path.join(sdir, name)
    dist1 = tarfile.open(dest_path + '.tar.gz', mode='w:gz')
    dist2 = tarfile.open(dest_path+'.tar.bz2', mode='w:bz2')
    dist3 = zipfile.ZipFile(dest_path + '.zip', mode='w',
                            compression=zipfile.ZIP_DEFLATED)

    paths = ['README.txt', 'demo.html', 'brython.js', 'brython_stdlib.js',
        'unicode.txt']

    for arc, wfunc in ((dist1, dist1.add), (dist2, dist2.add),
            (dist3, dist3.write)):
        for path in paths:
            wfunc(os.path.join(sdir, path),
                arcname=os.path.join(name, path))

        arc.close()

    # changelog file
    print('write changelog file')
    try:
        first = 'Changes in Brython version {}'.format(vname)
        with open(os.path.join(pdir, 'setup', 'changelog.txt')) as f:
            input_changelog_data_string = f.read()
        with open(os.path.join(pdir, 'setup', 'data',
                'changelog_{}.txt'.format(vname)), 'w') as out:
            out.write('%s\n' % first)
            out.write('%s\n\n' % ('=' * len(first)))
            out.write(input_changelog_data_string)
    except Exception as error:
        print(error)
        print("Warning - no changelog file")
示例#8
0
def run():
    now = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')

    timestamp = int(1000 * time.time())

    # update version number
    with open(abs_path('version_info.js'), 'w') as vinfo_file_out:
        # implementation[2] = now
        vinfo_file_out.write('__BRYTHON__.implementation = %s\n' %
                             implementation)
        vinfo_file_out.write('__BRYTHON__.__MAGIC__ = "%s"\n' %
                             '.'.join(['%s' % _i
                                       for _i in implementation[:3]]))
        vinfo_file_out.write('__BRYTHON__.version_info = %s\n' % str(version))
        vinfo_file_out.write('__BRYTHON__.compiled_date = "%s"\n' %
                             str(datetime.datetime.now()))
        vinfo_file_out.write('__BRYTHON__.timestamp = {}\n'.format(timestamp))
        # builtin module names = list of scripts in src/libs
        vinfo_file_out.write('__BRYTHON__.builtin_module_names = [')
        _modules = [
            '"%s"' % fname.split('.')[0]
            for fname in os.listdir(abs_path('libs')) if fname.endswith('.js')
        ]

        # Sort modules so that git diff's don't change between runs
        _modules.sort()
        vinfo_file_out.write(',\n    '.join(_modules))
        vinfo_file_out.write(']\n')

    import make_stdlib_static
    # build brython.js from base Javascript files
    sources = [
        'brython_builtins', 'version_info', 'py2js', 'loaders', 'py_object',
        'py_type', 'py_utils', 'py_builtin_functions', 'py_exceptions',
        'py_range_slice', 'py_bytes', 'py_set', 'js_objects', 'stdlib_paths',
        'py_import', 'py_float', 'py_int', 'py_long_int', 'py_complex',
        'py_sort', 'py_list', 'unicode_data', 'py_string', 'py_dict', 'py_dom',
        'py_generator', 'builtin_modules', 'builtins_docstrings', 'async'
    ]

    res = """// brython.js brython.info
// version {}
// implementation {}
// version compiled from commented, indented source files at
// github.com/brython-dev/brython
""".format(version, implementation)

    res_no_static = res  # same but without static stdlib files
    src_size = 0

    for fname in sources:
        src = open(abs_path(fname) + '.js').read() + '\n'
        src_size += len(src)
        mini = javascript_minifier.minify(src) + ";\n"
        res += mini
        if fname == 'stdlib_paths':
            res_no_static += "__BRYTHON__.stdlib = {}\n"
        else:
            res_no_static += mini

    res = re.sub(r'\bcontext\b', 'C', res)
    res_no_static = re.sub(r'\bcontext\b', 'C', res_no_static)

    with open(abs_path('brython.js'), 'w', newline="\n") as out:
        out.write(res)

    with open(abs_path('brython_no_static.js'), 'w', newline="\n") as out:
        out.write(res_no_static)

    print(('size : originals %s compact %s gain %.2f' %
           (src_size, len(res), 100 * (src_size - len(res)) / src_size)))

    sys.path.append("scripts")

    try:
        import make_VFS
    except ImportError:
        print("Cannot find make_VFS, so we won't make brython_stdlib.js.js")
        make_VFS = None
        sys.exit()

    make_VFS.process(os.path.join(pdir, 'www', 'src', 'brython_stdlib.js'))