mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
...
This commit is contained in:
parent
b01d47d6a8
commit
cb34ffd380
@ -66,7 +66,7 @@ def compiler():
|
|||||||
if c is None:
|
if c is None:
|
||||||
from duktape import Context
|
from duktape import Context
|
||||||
c = tls.compiler = Context(base_dirs=(P('rapydscript', allow_user_override=False),))
|
c = tls.compiler = Context(base_dirs=(P('rapydscript', allow_user_override=False),))
|
||||||
c.eval(P(COMPILER_PATH, data=True, allow_user_override=False).decode('utf-8'))
|
c.eval(P(COMPILER_PATH, data=True, allow_user_override=False).decode('utf-8'), fname='rapydscript-compiler.js')
|
||||||
return c
|
return c
|
||||||
|
|
||||||
class PYJError(Exception):
|
class PYJError(Exception):
|
||||||
@ -254,14 +254,15 @@ def main(args=sys.argv):
|
|||||||
parser.add_argument('--show-js', action='store_true', help='Have the REPL output compiled javascript before executing it')
|
parser.add_argument('--show-js', action='store_true', help='Have the REPL output compiled javascript before executing it')
|
||||||
parser.add_argument('--libdir', help='Where to look for imported modules')
|
parser.add_argument('--libdir', help='Where to look for imported modules')
|
||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
|
libdir = os.path.expanduser(args.libdir) if args.libdir else None
|
||||||
|
|
||||||
if sys.stdin.isatty():
|
if sys.stdin.isatty():
|
||||||
Repl(show_js=args.show_js, libdir=args.libdir)()
|
Repl(show_js=args.show_js, libdir=libdir)()
|
||||||
else:
|
else:
|
||||||
from duktape import JSError
|
from duktape import JSError
|
||||||
try:
|
try:
|
||||||
enc = getattr(sys.stdin, 'encoding', 'utf-8') or 'utf-8'
|
enc = getattr(sys.stdin, 'encoding', 'utf-8') or 'utf-8'
|
||||||
sys.stdout.write(compile_pyj(sys.stdin.read().decode(enc), libdir=args.libdir))
|
sys.stdout.write(compile_pyj(sys.stdin.read().decode(enc), libdir=libdir))
|
||||||
except PYJError as e:
|
except PYJError as e:
|
||||||
for e in e.errors:
|
for e in e.errors:
|
||||||
print(format_error(e), file=sys.stderr)
|
print(format_error(e), file=sys.stderr)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user