Skip to content

Commit

Permalink
Merge pull request #213 from gilch/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
gilch committed May 26, 2023
2 parents 6be47da + f55da8d commit b733a43
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Test install with pytest (including doctests)
env:
PYTHONWARNINGS: error
run: |
python -c "import tests" # Compiles hissp.basic on package import.
pytest -v --cov=hissp --cov-report=xml --doctest-modules --doctest-glob *.md src/hissp/*.lissp tests/ docs/ $(python -c "import hissp; print(hissp.__path__[0])")
pytest -p no:cacheprovider -v --cov=hissp --cov-report=xml --doctest-modules --doctest-glob *.md src/hissp/*.lissp tests/ docs/ $(python -c "import hissp; print(hissp.__path__[0])")
- name: Codecov
uses: codecov/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion src/hissp/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, token):
self.token = token

def contents(self):
return re.sub(r"\n$|(?m)^ *;+ ?", "", self.token)
return re.sub(r"(?m)\n$|^ *;+ ?", "", self.token)

def __repr__(self):
return f"Comment({self.token!r})"
Expand Down
13 changes: 3 additions & 10 deletions src/hissp/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,22 @@ def interact(locals=None):

def force_main():
""":meta private:"""
# Creates a new ``__main__`` to take the place of the current
# ``__main__`` module.
__main__ = ModuleType("__main__")
sys.modules["__main__"] = __main__
sys.path.insert(0, "")
return __main__


def main(__main__=None):
def main(__main__):
"""REPL command-line entry point.
If ``__main__`` is not provided, it creates a new one to take the
place of the current ``__main__`` module.
`hissp.macros._macro_` is imported into the module namespace,
making the bundled macros immediately available unqualified.
"""
if not __main__:
__main__ = force_main()
repl = LisspREPL(locals=__main__.__dict__)
import hissp.macros # Here so repl can import before compilation.

repl.locals["_macro_"] = SimpleNamespace(**vars(hissp.macros._macro_))
repl.interact()


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_i_file_args():


def test_repl_read_exception():
out, err = cmd("python -m hissp.repl", ".#(operator..truediv 1 0)\n")
out, err = cmd("python -m hissp", ".#(operator..truediv 1 0)\n")
assert ">>> # Compilation failed!\nTraceback (most recent call last):\n F" in err
assert "\nZeroDivisionError: division by zero" in err
assert out.count("#> ") == 2
Expand Down

0 comments on commit b733a43

Please sign in to comment.