Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Misc bugfixes in error reporting and build systems.

  • Loading branch information...
commit 2612033d1b9ad07f42f352720bc57e67db37a4f9 1 parent fb84284
@pakal pakal authored
View
2  .gitignore
@@ -8,5 +8,5 @@ output
*.pyc
*.pyo
.*.sw?
-
+_lokal_*
/stdlib
View
2  CREDITS
@@ -16,6 +16,8 @@ Daniel Carvalho - <idnael@gmail.com>
Tobias Weber - <tobi-weber@gmx.de>
Daniel Popowich - <danielpopowich@gmail.com>
Lex Berezhny - <eukreign@gmail.com>
+Pascal Chambon - <pythoniks@gmail.com>
+
Other Contributors
View
1  copyright
@@ -82,6 +82,7 @@ Copyright: 2011 Janjaap Bos <janjaapbos@gmail.com>
Copyright: 2011 Greg Warner <gdwarner@gmail.com>
Copyright: 2011 Daniel Hopkins <drhops@gmail.com>
Copyright: 2011 Lex Berezhny <eukreign@gmail.com>
+Copyright: 2011 Pascal Chambon <pythoniks@gmail.com>
Files: pyjs/src/pyjs/lib/socket.py
Copyright: 2008-2010, David P. D. Moss.
View
14 examples/buildall.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-import os, sys, glob
+import os, sys, glob, shutil
options = " ".join(sys.argv[1:])
if not options:
@@ -28,12 +28,18 @@ def guessMainScriptName(d):
if os.path.isdir(d):
os.chdir(d)
try:
- if os.path.isdir('output'): continue
name = guessMainScriptName(d)
- if not name: continue
+ if not name:
+ print "Skipping directory %s because no main script found" % d
+ continue
f = name + '.py'
print("********** Building %s **********" % name.upper())
- os.system("python ../%s %s %s" % (pyjsbuild, options, f))
+ if os.path.isdir('output'):
+ shutil.rmtree(os.path.join(".", "output")) # Why should we skip compilation here ? Just clean first.
+ res = os.system("python ../%s %s %s" % (pyjsbuild, options, f))
+ except Exception, e:
+ print "Error encountered for %s - %r" % (d, e)
finally:
#raw_input('Press any key')
os.chdir("..")
+
View
13 examples/jsimport/examplejs.py
@@ -21,13 +21,14 @@
jsimport("example.js")
def main():
- global examplevar
- # Note that the javascript example var is globally
- # defined, but not accessible from the global
- # scope. You'll have to swich to a local scope
- # and define the javascript names global
+ global examplevar
+ #examplevar is actually "out of modules", in a super scope
+
log.writebr(examplevar)
examplevar = 'Altered'
- log.writebr( get_examplevar() )
+ log.writebr(get_examplevar())
main()
+
+examplevar = "Realtered"
+log.writebr(get_examplevar())
View
1  examples/libtest/I18N/__init__.py
@@ -10,6 +10,7 @@ def another_example(self):
locale = 'en'
domains = []
+import sys
import domain
domains.append('domain')
import domain.subdomain
View
2  examples/libtest/build.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-../../bin/pyjsbuild --no-compile-inplace --strict --dynamic '^I18N[.].*.._..' $@ LibTest `find I18N -name ??_??.py`
+python ../../bin/pyjsbuild --no-compile-inplace --strict --dynamic '^I18N[.].*.._..' $@ LibTest `find I18N -name ??_??.py`
# For --translator=dict
# - disable the generator test for now (will hang forever)
# - comment second line
View
4 examples/showcase/__main__.py
@@ -2,6 +2,10 @@
# -*- coding: utf-8 -*-
import sys
+try:
+ sys.argv.remove("--download") # quick and dirty fix for the globally distributed --download argument
+except ValueError:
+ pass
import os
head = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(head))
View
2  library/__pyjamas__.py
@@ -15,10 +15,10 @@ def noSourceTracking(*args):
pass
def unescape(str):
- s = s.replace("&amp;", "&")
s = s.replace("&lt;", "<")
s = s.replace("&gt;", ">")
s = s.replace("&quot;", '"')
+ s = s.replace("&amp;", "&") # must be LAST
return s
def set_gtk_module(m):
View
1  pyjs/jsonrpc/__init__.py
@@ -69,3 +69,4 @@ def remotify(func):
return remotify
+
View
8 pyjs/src/pyjs/boilerplate/pyjampiler_wrapper.js.tmpl
@@ -29,9 +29,11 @@ $pyjs.in_try_except = 0;
%(modules_source)s
-/* initialize library */
-pyjslib("pyjslib");
+// initialize library
+// $p = $pyjs.loaded_modules["pyjslib"]
+// $p("pyjslib");
+
/* initialize application */
-%(entry_module)s("%(entry_module)s");
+$pyjs.loaded_modules["%(entry_module)s"]("%(entry_module)s");
View
11 pyjs/src/pyjs/linker.py
@@ -45,6 +45,8 @@
'list_imports',
'translator',
]
+non_boolean_opts = ['translator']
+assert set(non_boolean_opts) < set(translator_opts)
def is_modified(in_file,out_file):
modified = False
@@ -62,7 +64,9 @@ def get_translator_opts(args):
for k in translator_opts:
if args.has_key(k):
nk = k.replace("_", "-")
- if args[k]:
+ if k in non_boolean_opts:
+ opts.append("--%s=%s" % (nk, args[k]))
+ elif args[k]:
opts.append("--%s" % nk)
elif k != 'list_imports':
opts.append("--no-%s" % nk)
@@ -128,10 +132,11 @@ def out_translate(platform, file_names, out_file, module_name,
file_names = map(lambda x: x.replace(" ", r"\ "), file_names)
opts.append(out_file.replace(" ", r"\ "))
shell=True
- opts += get_translator_opts(translator_args) + file_names
+ translator_opts = get_translator_opts(translator_args)
+ opts += translator_opts + file_names
opts = [pyjs.PYTHON] + [os.path.join(pydir, translate_cmd)] + translate_cmd_opts + opts
pyjscompile_cmd = '"%s"' % '" "'.join(opts)
- #print pyjscompile_cmd - use this to create Makefile code-fragment
+
proc = subprocess.Popen(pyjscompile_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
View
8 pyjs/src/pyjs/options.py
@@ -33,8 +33,8 @@ def add_compile_options(parser):
parser.add_option("--no-internal-ast",
dest="internal_ast",
action="store_false",
- help="Use internal AST parser instead of standard python one"
- )
+ help="Use standard python parser instead of internal AST one"
+ )
parser.add_option("--debug-wrap",
dest="debug",
@@ -202,7 +202,7 @@ def add_compile_options(parser):
)
speed_options['number_classes'] = False
pythonic_options['number_classes'] = True
-
+
parser.add_option("--create-locals",
dest = "create_locals",
action="store_true",
@@ -249,7 +249,7 @@ def set_multiple(option, opt_str, value, parser, **kwargs):
help="Set all options that mimic standard python behavior",
)
parser.set_defaults(**all_compile_options)
-
+
def get_compile_options(opts):
d = {}
for opt in all_compile_options:
View
30 pyjs/src/pyjs/pyjampiler.py
@@ -28,7 +28,7 @@
#print "PYJAMPILER_BASE", PYJAMPILER_BASE
-SYSTEM_MODULES_DIR = "system_modules"
+SYSTEM_MODULES_DIR = os.path.join(BASE, "lib")
TMP_DIR = "pyjampiler_tmp"
class Builder(object):
@@ -65,7 +65,7 @@ def __read_file(self, filename):
f.close()
return buf
- def compile(self, src, module_name, base_dir=None):
+ def compile(self, src, module_name):
dst = os.path.join(self.options.working_dir, TMP_DIR, module_name + ".js")
internal_ast = False
compiler = pyjs.translator.import_compiler(internal_ast)
@@ -81,15 +81,17 @@ def compile(self, src, module_name, base_dir=None):
fr.close()
def compile_system_modules(self):
- # check if the system modules are present in the current direcoty
- if os.path.isdir(SYSTEM_MODULES_DIR):
- modules_dir = os.path.abspath(SYSTEM_MODULES_DIR)
- else:
- modules_dir = os.path.join(PYJAMPILER_BASE, SYSTEM_MODULES_DIR)
+ # check if the system modules are present in the current directory
- for module_filename in glob.glob(os.path.join(modules_dir, "*.py")):
+ '''
+ lib_file = os.path.join(BUILTIN_PATH, "pyjslib.py")
+ self.compile(lib_file, "pyjslib")
+
+ # FIXME - add packages like 'os' too!!
+ for module_filename in glob.glob(os.path.join(SYSTEM_MODULES_DIR, "*.py")):
module_name = os.path.basename(module_filename)[:-3]
- self.compile(module_filename, module_name, modules_dir)
+ self.compile(os.path.join(SYSTEM_MODULES_DIR, module_filename), module_name)
+ '''
def compile_application(self):
# compile application
@@ -101,7 +103,7 @@ def compile_application(self):
for filename in files:
filename = os.path.join(dirname, filename)
- based_filename = filename[len(self.options.working_dir)+1:]
+ based_filename = filename[len(self.options.working_dir) + 1:]
if not filename.endswith(".py"):
continue
@@ -115,8 +117,8 @@ def compile_application(self):
module_name = based_filename[:-3] # cut ".py"
module_name = module_name.replace(os.sep, ".")
- print "%s (%s)" % (module_name, based_filename)
- self.compile(based_filename, module_name, self.options.working_dir)
+ print "Compiling %s (%s)" % (module_name, based_filename)
+ self.compile(os.path.join(self.options.working_dir, based_filename), module_name)
def clear_tmp(self):
tmp_dir = os.path.join(self.options.working_dir, TMP_DIR)
@@ -131,11 +133,11 @@ def run(self):
self.compile_application()
# application template
- tmpl = self.__read_file(os.path.join(PYJAMPILER_BASE,
+ tmpl = self.__read_file(os.path.join(PYJAMPILER_BASE,
"pyjampiler_wrapper.js.tmpl"))
available_modules = repr(self.modules)
- _pyjs = self.__read_file(os.path.join(BUILTIN_PATH,
+ _pyjs = self.__read_file(os.path.join(BUILTIN_PATH,
"public/_pyjs.js")) # core pyjs functions
modules_source = "\n\n".join(self.modules_source)
View
25 pyv8/jsglobal.py
@@ -32,15 +32,26 @@ def pyv8_import_module(self, parent_name, module_name):
#print "pyv8_import_module", parent_name, module_name
exec "import " + module_name
return locals()[module_name]
-
+
def pyv8_load(self, modules):
for i in range(len(modules)):
fname = modules[i]
try:
- fp = open(fname, 'r')
- # XXX: Very bad hack! Do something about encoding of Translator
- txt = fp.read().decode('latin1')
- fp.close()
- x = self.__context__.eval(txt)
+ fp = open(fname, 'rb')
+ txt = fp.read()# historically js files were ascii or latin1 only, we only generate ascii to be safer
+ fp.close()
+ """ # Use this if encoding problems in generated javascript files
+ for index, line in enumerate(txt.split("\n")):
+ assert isinstance(txt, str)
+ try:
+ line.decode("ascii")
+ except UnicodeError:
+ import sys
+ print >> sys.stderr, "BUGGY LINE", index + 1, "-", repr(line)
+ """
+ x = self.__context__.eval(txt, fname)
except Exception, e:
- raise ImportError("Failed to load %s: '%s'" % (fname, e))
+ import traceback
+ import sys
+ traceback.print_exc(file=sys.stderr)
+ raise ImportError("Failed to load %s: '%s'" % (fname, e))
View
4 pyv8/linker.py
@@ -38,7 +38,7 @@
* prepare app system vars
*/
$pyjs.platform = 'pyv8';
-$pyjs.appname = '%(app_name)s';
+$pyjs.appname = %(app_name)r;
$pyjs.loadpath = './';
pyv8_load(%(module_files)s);
@@ -68,7 +68,7 @@
"""
def tostrlist(l):
- l = map(lambda x: "'%s'" % x, l)
+ l = map(lambda x: repr(x), l)
return "[%s]" % ', '.join(l)
class PyV8Linker(linker.BaseLinker):
View
3  test.py
@@ -219,7 +219,7 @@ def test_libtest_pyv8(self, output):
def test_examples(self, output):
return self.check_stderr(*self.run_cmd(
opts=["__main__.py",
- # "--download", should it be there or not ???
+ "--download", # should it be there or not ???
"--",
"-o %s" % output,],
cwd=self.options.examples_path))
@@ -257,6 +257,7 @@ def test_pyjampiler(self, output):
cmd,
opts=["-r LibTest",
"-o %s/libtest.js" % output,
+ "-e \"_[^_].*\"" # skip weird modules used to test syntax errors
],
cwd=path.join(self.options.examples_path, 'libtest')) +
('libtest', 'compile')))
Please sign in to comment.
Something went wrong with that request. Please try again.