From 265578692d94257d1ac0d5cb4908cf1e636cc8a8 Mon Sep 17 00:00:00 2001 From: Eric Wolf Date: Wed, 7 Feb 2024 19:49:23 +0100 Subject: [PATCH 1/3] change build system to hatch --- .github/workflows/Tests.yaml | 39 +++++++-------- .gitignore | 1 + pyproject.toml | 50 ++++++++++++++++--- {lambda_repl => src/lambda_repl}/__init__.py | 0 {lambda_repl => src/lambda_repl}/__main__.py | 0 {lambda_repl => src/lambda_repl}/aliases.py | 0 {lambda_repl => src/lambda_repl}/grammar.lark | 0 {lambda_repl => src/lambda_repl}/main.py | 0 {lambda_repl => src/lambda_repl}/parsing.py | 0 {lambda_repl => src/lambda_repl}/py.typed | 0 10 files changed, 63 insertions(+), 27 deletions(-) rename {lambda_repl => src/lambda_repl}/__init__.py (100%) rename {lambda_repl => src/lambda_repl}/__main__.py (100%) rename {lambda_repl => src/lambda_repl}/aliases.py (100%) rename {lambda_repl => src/lambda_repl}/grammar.lark (100%) rename {lambda_repl => src/lambda_repl}/main.py (100%) rename {lambda_repl => src/lambda_repl}/parsing.py (100%) rename {lambda_repl => src/lambda_repl}/py.typed (100%) diff --git a/.github/workflows/Tests.yaml b/.github/workflows/Tests.yaml index b639e71..336594f 100644 --- a/.github/workflows/Tests.yaml +++ b/.github/workflows/Tests.yaml @@ -4,36 +4,31 @@ on: [push, workflow_dispatch] jobs: Test: - strategy: - matrix: - python-version: ["3.10", "3.11", "3.12"] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} - - - name: Install test dependencies - run: python -m pip install mypy coverage build - - - name: Build wheel - run: python -m build + python-version: | + 3.10 + 3.11 + 3.12 - - name: Install wheel - run: python -m pip install --no-cache-dir dist/lambda_repl-*.whl + - name: Install Hatch + run: python -m pip install hatch + + - name: Perform release check + run: hatch run lint:release - - name: Run MyPy - run: python -m mypy -p lambda_repl + - name: Run tests + run: hatch run test:cov --verbose - - name: Run tests and generate report - run: coverage run -m unittest discover --verbose + - name: Generate report + run: hatch env run -e test.py3.12 coverage xml - name: Upload coverage uses: codecov/codecov-action@v4 @@ -43,6 +38,10 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Build wheel + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + run: hatch build + - name: Publish package if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore index 09e0029..a079f87 100644 --- a/.gitignore +++ b/.gitignore @@ -122,6 +122,7 @@ celerybeat.pid # Environments .env .venv +.direnv env/ venv/ ENV/ diff --git a/pyproject.toml b/pyproject.toml index ca9ee99..baa666e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,15 +34,46 @@ Bugtracker = "https://github.com/Deric-W/lambda_repl/issues" lambda-repl = "lambda_repl.main:main_cli" [build-system] -requires = ["setuptools >= 61.0.0"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" -[tool.setuptools.package-data] -lambda_repl = [ - "py.typed", - "grammar.lark" +[tool.hatch.envs.test] +dependencies = [ + "coverage[toml] == 7.*" +] + +[tool.hatch.envs.test.scripts] +test = "python -m unittest discover {args}" +cov-run = "coverage run -m unittest discover {args}" +cov-report = [ + "- coverage combine", + "coverage report" +] +cov = [ + "cov-run", + "cov-report" +] + +[[tool.hatch.envs.test.matrix]] +python = ["3.10", "3.11", "3.12"] + +[tool.hatch.envs.lint] +dependencies = [ + "mypy >= 1.0.0", + "pylint >= 2.12.2", + "flake8 >= 5.0.0", + "isort >= 5.10.1" +] + +[tool.hatch.envs.lint.scripts] +typecheck = "mypy -p lambda_repl" +release = [ + "typecheck" ] +[tool.hatch.build.targets.sdist] +exclude = ["/.github"] + [tool.mypy] disallow_any_unimported = true disallow_any_generics = true @@ -52,4 +83,9 @@ strict_optional = true warn_redundant_casts = true warn_unused_ignores = true warn_return_any = true -warn_unreachable = true \ No newline at end of file +warn_unreachable = true + +[tool.coverage.run] +source_pkgs = ["lambda_repl"] +branch = true +parallel = true diff --git a/lambda_repl/__init__.py b/src/lambda_repl/__init__.py similarity index 100% rename from lambda_repl/__init__.py rename to src/lambda_repl/__init__.py diff --git a/lambda_repl/__main__.py b/src/lambda_repl/__main__.py similarity index 100% rename from lambda_repl/__main__.py rename to src/lambda_repl/__main__.py diff --git a/lambda_repl/aliases.py b/src/lambda_repl/aliases.py similarity index 100% rename from lambda_repl/aliases.py rename to src/lambda_repl/aliases.py diff --git a/lambda_repl/grammar.lark b/src/lambda_repl/grammar.lark similarity index 100% rename from lambda_repl/grammar.lark rename to src/lambda_repl/grammar.lark diff --git a/lambda_repl/main.py b/src/lambda_repl/main.py similarity index 100% rename from lambda_repl/main.py rename to src/lambda_repl/main.py diff --git a/lambda_repl/parsing.py b/src/lambda_repl/parsing.py similarity index 100% rename from lambda_repl/parsing.py rename to src/lambda_repl/parsing.py diff --git a/lambda_repl/py.typed b/src/lambda_repl/py.typed similarity index 100% rename from lambda_repl/py.typed rename to src/lambda_repl/py.typed From 66f5a81c5bef461ceedba4926b7cf66836ddf31e Mon Sep 17 00:00:00 2001 From: Eric Wolf Date: Wed, 7 Feb 2024 19:50:43 +0100 Subject: [PATCH 2/3] add hatch badge to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 10cf008..50fc4cb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # lambda_repl +[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) ![Tests](https://github.com/Deric-W/lambda_repl/actions/workflows/Tests.yaml/badge.svg) [![codecov](https://codecov.io/gh/Deric-W/lambda_repl/branch/main/graph/badge.svg?token=SU3982mC17)](https://codecov.io/gh/Deric-W/lambda_repl) From d877ea9bfe872a12e648b1c6c8ab87dbf2086022 Mon Sep 17 00:00:00 2001 From: Eric Wolf Date: Wed, 7 Feb 2024 19:58:21 +0100 Subject: [PATCH 3/3] add lint config --- .flake8 | 3 +++ pyproject.toml | 7 +++++++ src/lambda_repl/__init__.py | 2 +- src/lambda_repl/parsing.py | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..e30e003 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 100 +extend-ignore = E221,E501 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index baa666e..787838f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,6 +66,10 @@ dependencies = [ ] [tool.hatch.envs.lint.scripts] +lint = [ + "- flake8 src/lambda_repl", + "- pylint src/lambda_repl" +] typecheck = "mypy -p lambda_repl" release = [ "typecheck" @@ -85,6 +89,9 @@ warn_unused_ignores = true warn_return_any = true warn_unreachable = true +[tool.pylint] +max-line-length = 100 + [tool.coverage.run] source_pkgs = ["lambda_repl"] branch = true diff --git a/src/lambda_repl/__init__.py b/src/lambda_repl/__init__.py index de6e4ad..8719a70 100644 --- a/src/lambda_repl/__init__.py +++ b/src/lambda_repl/__init__.py @@ -57,7 +57,7 @@ def import_term(self, location: str) -> Term[str] | None: module, _, name = location.strip().rpartition(".") try: term = getattr(import_module(module), name) - except Exception as error: + except Exception as error: # pylint: disable=W0718 self.stdout.write(f"Error while importing: {error}\n") return None if not isinstance(term, Term): diff --git a/src/lambda_repl/parsing.py b/src/lambda_repl/parsing.py index 0b521da..4f8ab12 100644 --- a/src/lambda_repl/parsing.py +++ b/src/lambda_repl/parsing.py @@ -55,7 +55,7 @@ def transform_string(self, string: str) -> Term[str]: case Token(type="VARIABLE") as name: # type: ignore return self.VARIABLE(name) # type: ignore case Token() as token: # type: ignore - raise UnexpectedToken(token, {"VARIABLE",}) + raise UnexpectedToken(token, {"VARIABLE", }) case tree: return self.transform(tree)