Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyjs/builtin/pyjslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def __setattr__(self, name, value):
return s + "<unknown>";
}""")

#HACK
object.__reduce__ = object.__str__


class basestring(object):
pass
Expand Down
1 change: 1 addition & 0 deletions pyjs/lib/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

timezone = JS("60 * (new Date(new Date()['getFullYear'](), 0, 1))['getTimezoneOffset']()")
altzone = JS("60 * (new Date(new Date()['getFullYear'](), 6, 1))['getTimezoneOffset']()")
daylight = altzone != timezone
if altzone > timezone:
# Probably on southern parth of the earth...
d = timezone
Expand Down
32 changes: 27 additions & 5 deletions pyjs/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
assert set(non_boolean_opts) < set(translator_opts)

def is_modified(in_file,out_file):
if not exits_casesensitive(outfile):
# due to case insensitivee filesystems, os.path.getmtime
# can return time for the wrong file
return True

modified = False
in_mtime = os.path.getmtime(in_file)
try:
Expand Down Expand Up @@ -111,7 +116,8 @@ def out_translate(platform, file_names, out_file, module_name,
if not incremental or do_translate:
pydir = os.path.abspath(os.path.dirname(__file__))
if not 'PYJS_SYSPATH' in os.environ:
os.environ['PYJS_SYSPATH'] = sys.path[0]
#HACK: below assumes all we need is pyjs. how to get six and others?
os.environ['PYJS_SYSPATH'] = ':'.join(sys.path)
opts = ["--module-name", module_name, "-o"]
if sys.platform == 'win32':
opts.append(out_file)
Expand Down Expand Up @@ -148,6 +154,22 @@ def out_translate(platform, file_names, out_file, module_name,

return deps, js_libs

def isfile_casesensitive(path):
if not os.path.isfile(path): return False # exit early
return exits_casesensitive(path)

exists_cache = {}
def exits_casesensitive(path):
if not os.path.exists(path): return False # exit early
if exists_cache.get(path): return True
directory, filename = os.path.split(path)
if not directory or not filename:
return True
if not filename in os.listdir(directory): return False
exists_cache[path] = exits_casesensitive(directory)
return exists_cache[path]


_path_cache= {}
def module_path(name, path, platform=None):
if name == '__pyjamas__' or name == '__javascript__':
Expand Down Expand Up @@ -177,7 +199,7 @@ def module_path(name, path, platform=None):
else:
cache = {}
_path_cache[name] = cache
if os.path.exists(cp + '.py'):
if exits_casesensitive(cp + '.py'):
cache[p] = cp + '.py'
else:
tail = []
Expand All @@ -193,12 +215,12 @@ def module_path(name, path, platform=None):
if p in cache:
if cache[p] is None:
break
elif os.path.isdir(cp) and os.path.exists(
elif os.path.isdir(cp) and exits_casesensitive(
os.path.join(cp, '__init__.py')):
cache[p] = os.path.join(cp, '__init__.py')
elif os.path.exists(cp + '.py'):
elif exits_casesensitive(cp + '.py'):
cache[p] = cp + '.py'
elif pn.endswith('.js') and os.path.exists(cp):
elif pn.endswith('.js') and exits_casesensitive(cp):
cache[p] = cp
else:
cache[p] = None
Expand Down
2 changes: 1 addition & 1 deletion pyjs/translator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os
if 'PYJS_SYSPATH' in os.environ:
sys.path[0:0] = [os.environ['PYJS_SYSPATH']]
sys.path[0:0] = os.environ['PYJS_SYSPATH'].split(':')
import pyjs
LIBRARY_PATH = os.path.abspath(os.path.dirname(__file__))

Expand Down
2 changes: 1 addition & 1 deletion pyjs/translator_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3126,7 +3126,7 @@ def leaf_return(self, leaf):
pythonic_options)

if os.environ.has_key('PYJS_SYSPATH'):
sys.path[0:0] = [os.environ['PYJS_SYSPATH']]
sys.path[0:0] = os.environ['PYJS_SYSPATH'].split(':')

import pyjs

Expand Down
55 changes: 47 additions & 8 deletions pyjs/translator_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import types
import os
import copy
import six
from six.moves import cStringIO as StringIO
import re
try:
Expand All @@ -28,11 +29,10 @@
from pyjs.options import (all_compile_options, add_compile_options,
get_compile_options, debug_options, speed_options,
pythonic_options)

if 'PYJS_SYSPATH' in os.environ:
sys.path[0:0] = [os.environ['PYJS_SYSPATH']]
sys.path[0:0] = os.environ['PYJS_SYSPATH'].split(':')

sys.path[1:1] = [os.path.join(os.path.dirname(__file__), "lib_trans")]
sys.path += [os.path.join(os.path.dirname(__file__), "lib_trans")]

import pycompiler as compiler
from pycompiler.visitor import ASTVisitor
Expand Down Expand Up @@ -4449,16 +4449,43 @@ def translate(sources, output_file, module_name=None, **kw):
compiler.walk(tree, v)
return v.imported_modules, v.imported_js

deps = []
if hasattr(output_file, 'write'):
output = output_file
elif output_file == '-':
output = sys.stdout
else:
output = file(output_file, 'w')
# due to case insenstive filesystems two different modules might have to be in one file.
# open file and remove this modules code
# read in dep and remove
# open file in append mode and write
# combine dep and write them
matches = None
if os.path.exists(output_file):
with open(output_file, "r") as output:
compiled = output.read()
modules = re.findall("^/\* start module: (.*) \*/$", compiled, flags=re.MULTILINE)
if module_name in modules and len(modules) > 1:
r="(?ms)(.*)^/\* start module: %s \*/$(.*)^/\* end module: %s \*/$(.*)(/\*.*^PYJS_DEPS: (.*)$.*\*/).*"
matches = re.match(r % (module_name, module_name), compiled)
compiled = '\n'.join([matches.group(1), matches.group(3)])
deps = eval(matches.group(5))
elif module_name not in modules:
matches = re.match("(?ms)(.*)(/\*.*^PYJS_DEPS: (.*)$.*\*/).*", compiled)
compiled = '\n'.join([matches.group(1)])
deps = eval(matches.group(3))
#TODO: combine PYJS_DEPS

if matches:
with open(output_file, "w") as output:
output.write(compiled)
output = file(output_file, "a")
else:
output = file(output_file, 'w')

t = Translator(compiler,
module_name, sources[0], src, tree, output, **kw)
return t.imported_modules, t.imported_js
return t.imported_modules+deps, t.imported_js

def merge(ast, module_name, tree1, tree2, flags):
if 'FULL_OVERRIDE' in flags:
Expand Down Expand Up @@ -4661,6 +4688,18 @@ def dotreplace(fname):
path, ext = os.path.splitext(fname)
return path.replace(".", "/") + ext

def isfile_casesensitive(path):
if not os.path.isfile(path): return False # exit early
return exits_casesensitive(path)

def exits_casesensitive(path):
if not os.path.exists(path): return False # exit early
directory, filename = os.path.split(path)
if not directory or not filename:
return True
if not filename in os.listdir(directory): return False
return exits_casesensitive(directory)

class ImportVisitor(object):

def __init__(self, module_name):
Expand Down Expand Up @@ -4768,22 +4807,22 @@ def __init__(self, compiler,
self.parser.dynamic = dynamic

def findFile(self, file_name):
if os.path.isfile(file_name):
if isfile_casesensitive(file_name):
return file_name

for library_dir in self.library_dirs:
file_name = dotreplace(file_name)
full_file_name = os.path.join(
LIBRARY_PATH, library_dir, file_name)
if os.path.isfile(full_file_name):
if isfile_casesensitive(full_file_name):
return full_file_name

fnameinit, ext = os.path.splitext(file_name)
fnameinit = fnameinit + "/__init__.py"

full_file_name = os.path.join(
LIBRARY_PATH, library_dir, fnameinit)
if os.path.isfile(full_file_name):
if isfile_casesensitive(full_file_name):
return full_file_name

raise Exception("file not found: " + file_name)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read(fname):
package_data=package_data,
zip_safe = False,
entry_points = entry_points,
install_requires=['six'],
install_requires=['six>=1.9.0'],

license="Apache",
keywords=["js", "javascript"],
Expand Down