Navigation Menu

Skip to content

Commit

Permalink
Misc bugfixes in error reporting and build systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
pakal committed Nov 22, 2011
1 parent fb84284 commit 2612033
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -8,5 +8,5 @@ output
*.pyc
*.pyo
.*.sw?

_lokal_*
/stdlib
2 changes: 2 additions & 0 deletions CREDITS
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions copyright
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions 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:
Expand Down Expand Up @@ -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("..")

13 changes: 7 additions & 6 deletions examples/jsimport/examplejs.py
Expand Up @@ -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())
1 change: 1 addition & 0 deletions examples/libtest/I18N/__init__.py
Expand Up @@ -10,6 +10,7 @@ def another_example(self):
locale = 'en'
domains = []

import sys
import domain
domains.append('domain')
import domain.subdomain
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
4 changes: 4 additions & 0 deletions examples/showcase/__main__.py
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion library/__pyjamas__.py
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions pyjs/jsonrpc/__init__.py
Expand Up @@ -69,3 +69,4 @@ def remotify(func):
return remotify



8 changes: 5 additions & 3 deletions pyjs/src/pyjs/boilerplate/pyjampiler_wrapper.js.tmpl
Expand Up @@ -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");

11 changes: 8 additions & 3 deletions pyjs/src/pyjs/linker.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pyjs/src/pyjs/options.py
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
30 changes: 16 additions & 14 deletions pyjs/src/pyjs/pyjampiler.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand Down
25 changes: 18 additions & 7 deletions pyv8/jsglobal.py
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions pyv8/linker.py
Expand Up @@ -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);
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion test.py
Expand Up @@ -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))
Expand Down Expand Up @@ -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')))
Expand Down

0 comments on commit 2612033

Please sign in to comment.