From ee7a1baa9279d201cf89fa1e41b88338b2ec5996 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Tue, 27 Jun 2023 08:39:38 -0400 Subject: [PATCH 1/3] Slightly expand doc. of evaluating a string of Hy --- docs/interop.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/interop.rst b/docs/interop.rst index 99f7e38c2..cf0d8a4a4 100644 --- a/docs/interop.rst +++ b/docs/interop.rst @@ -42,10 +42,16 @@ You can use :ref:`hy2py` to convert a Hy program to Python. The output will still import ``hy``, and thus require Hy to be installed in order to run; see :ref:`implicit-names` for details and workarounds. -To execute Hy code from a string, use :func:`hy.read` to convert it to -:ref:`models ` and then :func:`hy.eval` to evaluate it. There is no Hy -equivalent of :func:`exec` because :func:`hy.eval` works even when the input -isn't equivalent to a single Python expression. +To execute Hy code from a string, use :hy:func:`hy.read-many` to convert it to +:ref:`models ` and then :hy:func:`hy.eval` to evaluate it: + +.. code-block:: python + + >>> hy.eval(hy.read_many("(setv x 1) (+ x 1)")) + 2 + +There is no Hy equivalent of :func:`exec` because :hy:func:`hy.eval` works +even when the input isn't equivalent to a single Python expression. You can use :meth:`hy.REPL.run` to launch the Hy REPL from Python, as in ``hy.REPL(locals = locals()).run()``. From 2f3beb97f059b258583d05e2ed1d684a2a415a26 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Tue, 27 Jun 2023 08:40:25 -0400 Subject: [PATCH 2/3] Test PyPy for Python 3.10 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4e6045594..e60b3774f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: matrix: name-prefix: [''] os: [ubuntu-latest] - python: [3.8, 3.9, '3.10', 3.11, 3.12-dev, pypy-3.9, pyodide] + python: [3.8, 3.9, '3.10', 3.11, 3.12-dev, pypy-3.10, pyodide] include: # To keep the overall number of runs low, we test Windows and MacOS # only on the latest CPython. From 15abf28d52a736dceca4801990e730d481fb990f Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Tue, 27 Jun 2023 08:42:30 -0400 Subject: [PATCH 3/3] Remove workarounds for fixed PyPy `__file__` bug --- hy/cmdline.py | 4 ++-- tests/test_bin.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hy/cmdline.py b/hy/cmdline.py index 73e02eac7..c48fc1d9e 100644 --- a/hy/cmdline.py +++ b/hy/cmdline.py @@ -12,7 +12,7 @@ from pathlib import Path import hy -from hy._compat import PY3_9, PYPY +from hy._compat import PY3_9 from hy.compiler import hy_compile, hy_eval from hy.errors import HyLanguageError, filtered_hy_exceptions, hy_exc_handler from hy.importer import runhy @@ -270,7 +270,7 @@ def proc_opt(opt, arg=None, item=None, i=None): set_path(filename) # Ensure __file__ is set correctly in the code we're about # to run. - if PY3_9 and not PYPY: + if PY3_9: if not filename.is_absolute(): filename = Path.cwd() / filename if platform.system() == "Windows": diff --git a/tests/test_bin.py b/tests/test_bin.py index b31682434..4f7e4805a 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -11,7 +11,7 @@ import pytest -from hy._compat import PY3_9, PYODIDE, PYPY +from hy._compat import PY3_9, PYODIDE if PYODIDE: pytest.skip( @@ -681,7 +681,6 @@ def test_output_buffering(tmp_path): assert tf.read_text().splitlines() == ["line 1", "line 2"] -@pytest.mark.skipif(PYPY, reason = 'https://foss.heptapod.net/pypy/pypy/-/issues/3881') def test_uufileuu(tmp_path, monkeypatch): # `__file__` should be set the same way as in Python. # https://github.com/hylang/hy/issues/2318 @@ -691,7 +690,7 @@ def test_uufileuu(tmp_path, monkeypatch): (tmp_path / "realdir" / "pyex.py").write_text('print(__file__)') def file_is(arg, expected_py3_9): - expected = expected_py3_9 if PY3_9 and not PYPY else Path(arg) + expected = expected_py3_9 if PY3_9 else Path(arg) output, _ = run_cmd(["python3", arg + "pyex.py"]) assert output.rstrip() == str(expected / "pyex.py") output, _ = run_cmd(["hy", arg + "hyex.hy"])