From 8493599c0593441711f90bab3f98deb0c9761106 Mon Sep 17 00:00:00 2001 From: Paul Schweizer Date: Fri, 24 Nov 2023 14:44:19 +0100 Subject: [PATCH] Version2 (#17) * Remove Python2 dependecies, setup with poetry * Update to pyproject. toml * Cleanup readme * Cleanup * Fix pylint * Fix more pylint issues * Fix pylint again --- .github/workflows/publish.yml | 29 ++++++++++++++++++++++ .github/workflows/pylint.yml | 23 ++++++++++++++++++ .github/workflows/pytest.yml | 29 ++++++++++++++++++++++ .travis.yml | 45 ----------------------------------- ascii_canvas/__init__.py | 10 -------- ascii_canvas/canvas.py | 2 +- ascii_canvas/item.py | 13 ++-------- noxfile.py | 16 ------------- pyproject.toml | 8 +++++++ 9 files changed, 92 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/pylint.yml create mode 100644 .github/workflows/pytest.yml delete mode 100644 .travis.yml delete mode 100644 noxfile.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..76bc2d3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,29 @@ +name: Publish + +on: + release: + types: + - created + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Install Poetry + run: | + python -m pip install --upgrade poetry wheel + - name: Install dependencies + run: | + poetry install + - name: Publish + env: + POETRY_PYPI_TOKEN_PYPI: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }} + run: | + poetry config pypi-token.pypi $POETRY_PYPI_TOKEN_PYPI + poetry build + poetry publish diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..59c26b5 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + pylint: + name: Pylint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Install Poetry + run: | + python -m pip install --upgrade poetry wheel + - name: Install dependencies + run: | + poetry install + - name: Analysing the code with pylint + run: | + poetry run pylint ./ascii_canvas diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..611993e --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,29 @@ +# .github/workflows/app.yaml +name: Pytest + +on: [push] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.10", "3.x"] + steps: + - name: Check out repository code + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install Poetry + run: | + python -m pip install --upgrade poetry wheel + - name: Install dependencies + run: | + poetry install + - name: Run tests without coverage + if: ${{ matrix.python-version == 2.7 }} + run: | + poetry run pytest tests diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b6deca0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ -language: python -python: - - '2.7' - - '3.4' - - '3.5' - - '3.6' - -install: - - pip install -r requirements.txt - - pip install -r test-requirements.txt - - python setup.py install - - if [[ "$TRAVIS_PYTHON_VERSION" == "3.6" ]]; then - pip install mypy; - fi; - -jobs: - include: - - stage: test - name: satic_type - script: nox -s static_type - if: env(TRAVIS_PYTHON_VERSION) = "3.6" - -script: - - coverage run --source ascii_canvas -m pytest ./tests --cov=ascii_canvas --cov-report=xml --cov-report=term - -after_success: - - if [[ "$TRAVIS_PYTHON_VERSION" == "3.6" ]]; then - python-codacy-coverage -r coverage.xml; - fi; - -before_deploy: - - python strip-type-hints.py; - -deploy: - provider: pypi - skip_existing: true - distributions: sdist bdist_wheel - user: Anton-4 - password: - secure: ZIeVakvSeDwoQhiGyMPx1CJGhk/RoOrAkopysX3v3bDTnsDmEynsmXkkfd4GpJif+w0jZNWIqwwCE5ycioeReNtNhe18Ii9vzpxAIOeTNnfXqld16Zi9QH6nydWISb+LjAV23xafi35Rp6ahteSE7LqYu9b6yEaxdjZOsUTukVMni/Kpy4SDGyk7vL/jnIxzLVJfBW6DVJCGeGEno1ioqgkvBzoCl1W+xNKgE8g1Bqnmup/8Q0MyqG5rr+Gs1UkPVt9G+1xiTbp3KKUiz1XtIIeJKiXwBvutqWBP0qESeIFfrEE5Xx08oW+QW6wpEDKiuLrZpUClwrzCQa2Ru6RcZB1Sua+6t+DIjl40E2MZTC/USBd29iN3akp4vC1GSjne/leHCcwwitev2O4tvmhNfh0gMXjHWSR8b0A/AD3ySz95XsoMz6YY3c/zPWM5wclJexw0GU8LmUg5MOr+oD93rDyEL/htNVq0xUlrQELAexj4Y6vI8p/yFOej9gSJHMlfkXoOfpY/dzmH7uyWC5qfE1D2K0fc5qpx6zyzw6avDM9m1gdNihWXqxjYxeOmmuD1wQXRg6cNAPeSHLLriiurIpZ3mclRvW/FqDZOGFQCrMidOwJB0Atg1GfnP3qTOs33jYnxtzTVqaJmsukV6FqJa6WDiNGi5OJ9D4Xt5+M4ou0= - on: - tags: true - repo: PaulSchweizer/ascii-canvas - branch: master - python: '3.6' diff --git a/ascii_canvas/__init__.py b/ascii_canvas/__init__.py index f77dfed..e69de29 100644 --- a/ascii_canvas/__init__.py +++ b/ascii_canvas/__init__.py @@ -1,10 +0,0 @@ -"""Stripping the python 3.6 type hints for backwards compatibility.""" -import os -import sys - - -if sys.version_info.major < 3 or (sys.version_info.major == 3 and sys.version_info.minor < 6): - from strip_hints import strip_on_import - strip_on_import(__file__, to_empty=False, no_ast=False, no_colon_move=False, - only_assigns_and_defs=False, py3_also=True) - diff --git a/ascii_canvas/canvas.py b/ascii_canvas/canvas.py index 3c24433..05ad706 100644 --- a/ascii_canvas/canvas.py +++ b/ascii_canvas/canvas.py @@ -6,7 +6,7 @@ from ascii_canvas import item as item_ -class Canvas(object): +class Canvas: """Aggregate string objects onto a 2D string canvas.""" BLANK = " " diff --git a/ascii_canvas/item.py b/ascii_canvas/item.py index 75ecfd0..1b366cf 100644 --- a/ascii_canvas/item.py +++ b/ascii_canvas/item.py @@ -4,7 +4,7 @@ from typing import List, Union -class Item(object): +class Item: """Defined by an arbitrary text and a position on the Canvas.""" def __init__( @@ -31,14 +31,6 @@ def bbox(self) -> List[int]: return [0, 0, max(len(line) for line in lines), len(lines)] -# class Item(Item): -# def __init__(self, text: str, position: Union[List[int], None] = None): -# """Hold a text and a position.""" -# super().__init__() -# self._text = text -# self._position = position or [0, 0] - - class Line(Item): """A line between two points. @@ -105,8 +97,7 @@ def position(self) -> List[int]: """Offset the position if the start is left of the end.""" if self.start[1] <= self.end[1]: return self.start - else: - return [self.start[0], self.start[1] - self.bbox[3]] + return [self.start[0], self.start[1] - self.bbox[3]] class Rectangle(Item): diff --git a/noxfile.py b/noxfile.py deleted file mode 100644 index 3099380..0000000 --- a/noxfile.py +++ /dev/null @@ -1,16 +0,0 @@ -import nox -import os - - -@nox.session(python=["3.6"]) -def static_type(session): - session.install("mypy") - - session.run("mypy", "--ignore-missing-imports", "ascii_canvas") - - -@nox.session(python=["2.7", "3.4", "3.5", "3.6"]) -def pytests_no_hints(session): - session.install("-r", "test-requirements.txt") - - session.run("python", "-m", "pytest", "--spec", "-s", os.path.join("tests")) diff --git a/pyproject.toml b/pyproject.toml index 7f1f892..05d7731 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,3 +25,11 @@ build-backend = "poetry.core.masonry.api" [tool.black] line-length = 79 + +[tool.pylint."MESSAGES CONTROL"] +disable = [ + "duplicate-code", + "no-else-raise", + "too-many-arguments", + "too-many-branches", +]