Пример #1
0
 def _compile(self, name, source, dev_mode=False):
     if self.debug is None:
         debug = dev_mode
     else:
         debug = self.debug
     compiler = import_compiler(False)
     tree = compiler.parse(source)
     output = StringIO()
     translator = Translator(
         compiler,
         name,
         name,
         source,
         tree,
         output,
         # Debug options
         debug=debug,
         source_tracking=debug,
         line_tracking=debug,
         store_source=debug,
         # Speed and size optimizations
         function_argument_checking=debug,
         attribute_checking=False,
         inline_code=False,
         number_classes=False,
         # Sufficient Python conformance
         operator_funcs=True,
         bound_methods=True,
         descriptors=True,
     )
     return output.getvalue(
     ), translator.imported_modules, translator.imported_js
Пример #2
0
 def _compile(self, name, source, dev_mode=False):
     if self.debug is None:
         debug = dev_mode
     else:
         debug = self.debug
     compiler = import_compiler(False)
     tree = compiler.parse(source)
     output = StringIO()
     translator = Translator(compiler, name, name, source, tree, output,
         # Debug options
         debug=debug, source_tracking=debug, line_tracking=debug,
         store_source=debug,
         # Speed and size optimizations
         function_argument_checking=debug, attribute_checking=False,
         inline_code=False, number_classes=False,
         # Sufficient Python conformance
         operator_funcs=True, bound_methods=True, descriptors=True,
     )
     return output.getvalue(), translator.imported_modules, translator.imported_js
Пример #3
0
def build_script():
    usage = """
    usage: %prog [options] <application module name>

    This is the command line builder for the pyjamas project, which can
    be used to build Ajax applications from Python.
    For more information, see the website at http://pyjs.org/
    """
    global app_platforms
    parser = OptionParser(usage = usage)
    # TODO: compile options
    translator.add_compile_options(parser)
    linker.add_linker_options(parser)
    parser.add_option("-P", "--platforms", dest="platforms",
        help="platforms to build for, comma-separated")
    parser.add_option("-l", "--log-level", dest="log_level",
                      default=None,
                      type="int",
                      help="The python log level as an int")
    parser.add_option(
        "-m", "--multi-file", dest="multi_file",
        default=False,
        action="store_true",
        help="Include each module via a script-tag instead of writing"
              " the whole code into the main cache.html file")

    parser.add_option(
        "-c", "--cache-buster", action="store_true",
        dest="cache_buster",
        default=False,
        help="Enable browser cache-busting (MD5 hash added to output filenames)",
        )

    parser.add_option(
        "--bootstrap-file", 
        dest="bootstrap_file",
        help="Specify the bootstrap code. (Used when application html file is generated)."
        )

    parser.add_option(
        "--public-folder",
        dest="public_folder",
        help="Specifiy the public folder. (Contents copied into the output dir, see -o)."
        )

    parser.add_option(
        "--dynamic",
        dest="unlinked_modules",
        action="append",
        help="regular expression for modules that will not be linked and thus loaded dynamically"
        )

    parser.add_option(
        "--keep-lib-files", dest="keep_lib_files",
        default=False,
        action="store_true",
        help="Keep the files generated in the lib directory"
        )

    parser.set_defaults(output="output",
                        js_includes=[],
                        js_static_includes=[],
                        library_dirs=[],
                        platforms=(','.join(AVAILABLE_PLATFORMS)),
                        bootstrap_file="bootstrap.js",
                        public_folder="public",
                        unlinked_modules=[],
                        )
    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    compiler = translator.import_compiler(options.internal_ast)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
       app_platforms = options.platforms.lower().split(',')
    print "Building:", top_module
    print "PYJSPATH:", pyjs.path

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(("arg_is_instance", options.function_argument_checking))
    runtime_options.append(("arg_instance_type", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(("dynamic_loading", (len(options.unlinked_modules)>0)))

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        bound_methods=options.bound_methods,
        descriptors=options.descriptors,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source,
        inline_code = options.inline_code,
        operator_funcs = options.operator_funcs,
        number_classes = options.number_classes,
    )

    l = BrowserLinker(args,
                      compiler=compiler,
                      output=options.output,
                      platforms=app_platforms,
                      path=pyjs.path,
                      js_libs=options.js_includes,
                      unlinked_modules=options.unlinked_modules,
                      keep_lib_files=options.keep_lib_files,
                      translator_arguments=translator_arguments,
                      multi_file=options.multi_file,
                      cache_buster=options.cache_buster,
                      bootstrap_file=options.bootstrap_file,
                      public_folder=options.public_folder,
                      runtime_options=runtime_options,
                     )
    l()
    print "Built to :", os.path.abspath(options.output)
Пример #4
0
def build_script():
    usage = """
    usage: %prog [options] <application module name>

    This is the command line builder for the pyjamas project, which can
    be used to build Ajax applications from Python.
    For more information, see the website at http://pyjs.org/
    """
    global app_platforms
    parser = OptionParser(usage = usage)
    # TODO: compile options
    translator.add_compile_options(parser)
    linker.add_linker_options(parser)
    parser.add_option("-P", "--platforms", dest="platforms",
        help="platforms to build for, comma-separated")
    parser.add_option("-l", "--log-level", dest="log_level",
                      default=None,
                      type="int",
                      help="The python log level as an int")
    parser.add_option(
        "-m", "--multi-file", dest="multi_file",
        default=False,
        action="store_true",
        help="Include each module via a script-tag instead of writing"
              " the whole code into the main cache.html file")

    parser.add_option(
        "-c", "--cache-buster", action="store_true",
        dest="cache_buster",
        default=False,
        help="Enable browser cache-busting (MD5 hash added to output filenames)",
        )

    parser.add_option(
        "--bootstrap-file", 
        dest="bootstrap_file",
        help="Specify the bootstrap code. (Used when application html file is generated)."
        )

    parser.add_option(
        "--public-folder",
        dest="public_folder",
        help="Specifiy the public folder. (Contents copied into the output dir, see -o)."
        )

    parser.add_option(
        "--dynamic",
        dest="unlinked_modules",
        action="append",
        help="regular expression for modules that will not be linked and thus loaded dynamically"
        )

    parser.add_option(
        "--keep-lib-files", dest="keep_lib_files",
        default=False,
        action="store_true",
        help="Keep the files generated in the lib directory"
        )

    parser.set_defaults(output="output",
                        js_includes=[],
                        js_static_includes=[],
                        library_dirs=[],
                        platforms=(','.join(AVAILABLE_PLATFORMS)),
                        bootstrap_file="bootstrap.js",
                        public_folder="public",
                        unlinked_modules=[],
                        )
    options, _args = parser.parse_args()
    args = []
    for a in _args:
        if a.lower().endswith('.py'):
            args.append(a[:-3])
        else:
            args.append(a)

    compiler = translator.import_compiler(options.internal_ast)

    if options.log_level is not None:
        import logging
        logging.basicConfig(level=options.log_level)
    if len(args) < 1:
        parser.error("incorrect number of arguments")

    top_module = args[0]
    for d in options.library_dirs:
        pyjs.path.append(os.path.abspath(d))

    if options.platforms:
       app_platforms = options.platforms.lower().split(',')
    print "Building:", top_module
    print "PYJSPATH:", pyjs.path

    runtime_options = []
    runtime_options.append(("arg_ignore", options.function_argument_checking))
    runtime_options.append(("arg_count", options.function_argument_checking))
    runtime_options.append(("arg_is_instance", options.function_argument_checking))
    runtime_options.append(("arg_instance_type", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_dup", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_unexpected_keyword", options.function_argument_checking))
    runtime_options.append(("arg_kwarg_multiple_values", options.function_argument_checking))
    runtime_options.append(("dynamic_loading", (len(options.unlinked_modules)>0)))

    translator_arguments=dict(
        debug=options.debug,
        print_statements = options.print_statements,
        function_argument_checking=options.function_argument_checking,
        attribute_checking=options.attribute_checking,
        bound_methods=options.bound_methods,
        descriptors=options.descriptors,
        source_tracking=options.source_tracking,
        line_tracking=options.line_tracking,
        store_source=options.store_source,
        inline_code = options.inline_code,
        operator_funcs = options.operator_funcs,
        number_classes = options.number_classes,
    )

    l = BrowserLinker(args,
                      compiler=compiler,
                      output=options.output,
                      platforms=app_platforms,
                      path=pyjs.path,
                      js_libs=options.js_includes,
                      unlinked_modules=options.unlinked_modules,
                      keep_lib_files=options.keep_lib_files,
                      translator_arguments=translator_arguments,
                      multi_file=options.multi_file,
                      cache_buster=options.cache_buster,
                      bootstrap_file=options.bootstrap_file,
                      public_folder=options.public_folder,
                      runtime_options=runtime_options,
                     )
    l()
    print "Built to :", os.path.abspath(options.output)