Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings #213

Merged
merged 4 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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