Skip to content

Commit baf2eb1

Browse files
author
hartsantler
committed
deprecated the old header hack used in python_to_pythonjs.py, replaced with a command line option: --module name for when sending input using stdin,
otherwise the module name is the first python file given on the command line.
1 parent c508649 commit baf2eb1

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

pythonjs/python_to_pythonjs.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def visit_ImportFrom(self, node):
313313
## the helper script (nodejs.py) checks for these import statements, and loads the binding,
314314
pass
315315
else:
316-
raise SyntaxError( 'invalid import' )
316+
raise SyntaxError( 'invalid import - could not find cached module: %s' %node.module )
317317

318318
def visit_Assert(self, node):
319319
## hijacking "assert isinstance(a,A)" as a type system ##
@@ -1533,12 +1533,18 @@ def main(script):
15331533

15341534

15351535
def command():
1536-
module = module_path = None
1536+
module = None
1537+
module_path = '/tmp'
15371538
scripts = []
15381539
if len(sys.argv) > 1:
1539-
for arg in sys.argv[1:]:
1540+
argv = sys.argv[1:]
1541+
for i,arg in enumerate(argv):
15401542
if arg.endswith('.py'):
15411543
scripts.append( arg )
1544+
module = arg.split('.')[0]
1545+
elif module is None and i > 0:
1546+
if argv[i-1] == '--module':
1547+
module = arg
15421548

15431549
if len(scripts):
15441550
a = []
@@ -1548,13 +1554,13 @@ def command():
15481554
else:
15491555
data = sys.stdin.read()
15501556

1551-
if data.startswith('#!'):
1552-
header = data[ 2 : data.index('\n') ]
1553-
data = data[ data.index('\n')+1 : ]
1554-
if ';' in header:
1555-
module_path, module = header.split(';')
1556-
else:
1557-
module_path = header
1557+
#if data.startswith('#!'):
1558+
# header = data[ 2 : data.index('\n') ]
1559+
# data = data[ data.index('\n')+1 : ]
1560+
# if ';' in header:
1561+
# module_path, module = header.split(';')
1562+
# else:
1563+
# module_path = header
15581564

15591565
compiler = PythonToPythonJS( module=module, module_path=module_path )
15601566

tests/server.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,24 @@
3131

3232

3333
def python_to_pythonjs( src, module=None, global_variable_scope=False ):
34-
cmdheader = '#!%s' %PATHS['module_cache']
35-
if module:
36-
assert '.' not in module
37-
cmdheader += ';' + module
38-
cmdheader += '\n'
34+
#cmdheader = '#!%s' %PATHS['module_cache']
35+
#if module:
36+
# assert '.' not in module
37+
# cmdheader += ';' + module
38+
#cmdheader += '\n'
3939

4040
cmd = ['python2', os.path.join( PATHS['pythonscript'], 'python_to_pythonjs.py')]
4141
if global_variable_scope: cmd.append('--global-variable-scope')
42+
if module:
43+
cmd.append( '--module' )
44+
cmd.append( module )
45+
4246
p = subprocess.Popen(
4347
cmd,
4448
stdin = subprocess.PIPE,
4549
stdout = subprocess.PIPE
4650
)
47-
stdout, stderr = p.communicate( (cmdheader + src).encode('utf-8') )
51+
stdout, stderr = p.communicate( src.encode('utf-8') )
4852
return stdout.decode('utf-8')
4953

5054
def pythonjs_to_javascript( src, closure_compiler=False ):

0 commit comments

Comments
 (0)