Permalink
Browse files

Make opy and opyc commands, analogous to osh and oshc.

Test the usage with test/opy.sh.
  • Loading branch information...
Andy Chu
Andy Chu committed Mar 4, 2018
1 parent b74c1e5 commit 71deba81add7137fef13d7f388c8da28c58bf3dd
Showing with 102 additions and 11 deletions.
  1. +4 −4 bin/oil.py
  2. +43 −4 bin/opy_.py
  3. +1 −0 build/common.sh
  4. +3 −3 opy/opy_main.py
  5. +5 −0 scripts/run.sh
  6. +46 −0 test/opy.sh
View
@@ -575,7 +575,7 @@ def AppBundleMain(argv):
b = os.path.basename(argv[0])
main_name, ext = os.path.splitext(b)
if main_name.startswith("-"):
if main_name.startswith('-'):
login_shell = True
main_name = main_name[1:]
@@ -594,7 +594,7 @@ def AppBundleMain(argv):
sys.exit(0)
main_name = first_arg
if main_name.startswith("-"):
if main_name.startswith('-'): # TODO: Remove duplication above
login_shell = True
main_name = main_name[1:]
argv0 = argv[1]
@@ -633,10 +633,10 @@ def main(argv):
raise
except args.UsageError as e:
#builtin.Help(['oil-usage'], util.GetResourceLoader())
print('oil: %s' % e, file=sys.stderr)
log('oil: %s', e)
sys.exit(2)
except RuntimeError as e:
print('FATAL: %s' % e, file=sys.stderr)
log('FATAL: %s', e)
sys.exit(1)
finally:
_tlog('Exiting main()')
View
@@ -20,14 +20,53 @@
_OPY_USAGE = 'Usage: opy_ MAIN [OPTION]... [ARG]...'
# TODO: Make this more consistent with bin/oil.py.
# Run the bytecode too. Should this have an option to use byterun?
def OpyMain(argv0, main_argv):
raise NotImplementedError('opy not implemented')
def AppBundleMain(argv):
b = os.path.basename(argv[0])
main_name, ext = os.path.splitext(b)
if main_name in ('opy_', 'opy') and ext: # opy_.py or opy.ovm
try:
first_arg = argv[1]
except IndexError:
raise args.UsageError('Missing required applet name.')
# TODO: We don't have this
if first_arg in ('-h', '--help'):
builtin.Help(['bundle-usage'], util.GetResourceLoader())
sys.exit(0)
if first_arg in ('-V', '--version'):
_ShowVersion()
sys.exit(0)
main_name = first_arg
argv0 = argv[1]
main_argv = argv[2:]
else:
argv0 = argv[0]
main_argv = argv[1:]
if main_name == 'opy':
status = OpyMain(argv0, main_argv)
return status
elif main_name == 'opyc':
return opy_main.OpyCommandMain(main_argv)
else:
raise args.UsageError('Invalid applet name %r.' % main_name)
def main(argv):
try:
opy_main.OpyMain(argv[1:])
sys.exit(AppBundleMain(argv))
except args.UsageError as e:
print(_OPY_USAGE, file=sys.stderr)
print(str(e), file=sys.stderr)
#print(_OPY_USAGE, file=sys.stderr)
log('opy: %s', e)
sys.exit(2)
except RuntimeError as e:
log('FATAL: %s', e)
View
@@ -20,6 +20,7 @@ readonly PREPARE_DIR=_devbuild/cpython-full
# Used by scripts/run.sh and opy/build.sh
readonly OIL_SYMLINKS=(oil osh oshc sh wok boil true false)
readonly OPY_SYMLINKS=(opy opyc)
log() {
View
@@ -145,7 +145,7 @@ def Options():
return p
def OpyMain(argv):
def OpyCommandMain(argv):
"""Dispatch to the right action."""
opts, argv = Options().parse_args(argv)
@@ -317,10 +317,10 @@ def py2st(gr, raw_node):
execfile.run_code_object(co, opy_argv)
else:
raise RuntimeError('Invalid path %r' % py_path)
raise args.UsageError('Invalid path %r' % py_path)
else:
raise RuntimeError('Invalid action %r' % action)
raise args.UsageError('Invalid action %r' % action)
# Examples of nodes Leaf(type, value):
# Leaf(1, 'def')
View
@@ -30,6 +30,11 @@ make-bin-links() {
for link in "${OIL_SYMLINKS[@]}"; do
ln -s -f --verbose oil.ovm _bin/$link
done
for link in "${OPY_SYMLINKS[@]}"; do
ln -s -f --verbose opy_.py bin/$link
ln -s -f --verbose opy.ovm _bin/$link
done
}
# Hm all of the solutions involve grep --perl or perl itself?
View
@@ -0,0 +1,46 @@
#!/bin/bash
#
# Usage:
# ./opy.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
source test/common.sh
usage() {
set +o errexit
bin/opy_.py
test $? -eq 2 || fail
#bin/opy
#test $? -eq 2 || fail
bin/opyc
test $? -eq 2 || fail
bin/opyc invalid
test $? -eq 2 || fail
}
readonly -a PASSING=(
usage
)
# TODO: Consolidate this
all-passing() {
for t in "${PASSING[@]}"; do
# fail calls 'exit 1'
$t
echo "OK $t"
done
echo
echo "All $0 tests passed."
}
"$@"

0 comments on commit 71deba8

Please sign in to comment.