Merge pull request #1557 from waigx/feat/E-arg
Add -E support for Hy REPL
This commit is contained in:
commit
6c25fc23df
1
NEWS.rst
1
NEWS.rst
@ -22,6 +22,7 @@ New Features
|
|||||||
* Added `mangle` and `unmangle` as core functions
|
* Added `mangle` and `unmangle` as core functions
|
||||||
* `defclass` in Python 3 now supports specifying metaclasses and other
|
* `defclass` in Python 3 now supports specifying metaclasses and other
|
||||||
keyword arguments
|
keyword arguments
|
||||||
|
* Added a command-line option `-E` per CPython
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
------------------------------
|
------------------------------
|
||||||
|
@ -271,6 +271,8 @@ def cmdline_handler(scriptname, argv):
|
|||||||
help="program passed in as a string")
|
help="program passed in as a string")
|
||||||
parser.add_argument("-m", dest="mod",
|
parser.add_argument("-m", dest="mod",
|
||||||
help="module to run, passed in as a string")
|
help="module to run, passed in as a string")
|
||||||
|
parser.add_argument("-E", action='store_true',
|
||||||
|
help="ignore PYTHON* environment variables")
|
||||||
parser.add_argument("-i", dest="icommand",
|
parser.add_argument("-i", dest="icommand",
|
||||||
help="program passed in as a string, then stay in REPL")
|
help="program passed in as a string, then stay in REPL")
|
||||||
parser.add_argument("--spy", action="store_true",
|
parser.add_argument("--spy", action="store_true",
|
||||||
@ -310,6 +312,10 @@ def cmdline_handler(scriptname, argv):
|
|||||||
# reset sys.argv like Python
|
# reset sys.argv like Python
|
||||||
sys.argv = options.args + module_args or [""]
|
sys.argv = options.args + module_args or [""]
|
||||||
|
|
||||||
|
if options.E:
|
||||||
|
# User did "hy -E ..."
|
||||||
|
_remove_python_envs()
|
||||||
|
|
||||||
if options.command:
|
if options.command:
|
||||||
# User did "hy -c ..."
|
# User did "hy -c ..."
|
||||||
return run_command(options.command)
|
return run_command(options.command)
|
||||||
@ -436,3 +442,10 @@ def _print_for_windows(src):
|
|||||||
print(line)
|
print(line)
|
||||||
except:
|
except:
|
||||||
print(line.encode('utf-8'))
|
print(line.encode('utf-8'))
|
||||||
|
|
||||||
|
# remove PYTHON* environment variables,
|
||||||
|
# such as "PYTHONPATH"
|
||||||
|
def _remove_python_envs():
|
||||||
|
for key in list(os.environ.keys()):
|
||||||
|
if key.startswith("PYTHON"):
|
||||||
|
os.environ.pop(key)
|
||||||
|
3
tests/resources/bin/printenv.hy
Normal file
3
tests/resources/bin/printenv.hy
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(import os)
|
||||||
|
|
||||||
|
(print (. os environ))
|
@ -168,6 +168,23 @@ def test_bin_hy_stdin_hy_repr():
|
|||||||
output, _ = run_cmd(hr("--spy"), '(+ [1] [2] (foof))')
|
output, _ = run_cmd(hr("--spy"), '(+ [1] [2] (foof))')
|
||||||
assert "[1]+[2]" in output.replace('L', '').replace(' ', '')
|
assert "[1]+[2]" in output.replace('L', '').replace(' ', '')
|
||||||
|
|
||||||
|
def test_bin_hy_ignore_python_env():
|
||||||
|
os.environ.update({"PYTHONTEST": '0'})
|
||||||
|
output, _ = run_cmd("hy -c '(print (do (import os) (. os environ)))'")
|
||||||
|
assert "PYTHONTEST" in output
|
||||||
|
output, _ = run_cmd("hy -m tests.resources.bin.printenv")
|
||||||
|
assert "PYTHONTEST" in output
|
||||||
|
output, _ = run_cmd("hy tests/resources/bin/printenv.hy")
|
||||||
|
assert "PYTHONTEST" in output
|
||||||
|
|
||||||
|
output, _ = run_cmd("hy -E -c '(print (do (import os) (. os environ)))'")
|
||||||
|
assert "PYTHONTEST" not in output
|
||||||
|
os.environ.update({"PYTHONTEST": '0'})
|
||||||
|
output, _ = run_cmd("hy -E -m tests.resources.bin.printenv")
|
||||||
|
assert "PYTHONTEST" not in output
|
||||||
|
os.environ.update({"PYTHONTEST": '0'})
|
||||||
|
output, _ = run_cmd("hy -E tests/resources/bin/printenv.hy")
|
||||||
|
assert "PYTHONTEST" not in output
|
||||||
|
|
||||||
def test_bin_hy_cmd():
|
def test_bin_hy_cmd():
|
||||||
output, _ = run_cmd("hy -c \"(koan)\"")
|
output, _ = run_cmd("hy -c \"(koan)\"")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user