From 73fe503d499aeecd4aa8ebef986847e07770760a Mon Sep 17 00:00:00 2001 From: Walter Scheper Date: Tue, 26 Jan 2021 12:58:53 -0500 Subject: [PATCH] Add workflow to lint and test pymaven Fixes some linting errors and drops old, unsupported versions of python. Closes #7 Change-Id: I8684668fa8d259f751b211d053734023135ea53d --- .github/workflows/python-package.yml | 34 +++++++++++++++++++ .travis.yml | 49 ---------------------------- pymaven/constants.py | 1 + pymaven/versioning.py | 40 +++++++++++------------ setup.cfg | 1 - tests/test_client.py | 12 ++++--- tests/test_pom.py | 2 +- tox.ini | 21 +++--------- 8 files changed, 69 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/python-package.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..496e1f9 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,34 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python package + +on: + push: + branches: [master, release-*] + pull_request: + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] + os: [ubuntu-latest, macOS-latest, windows-latest] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox + - name: Lint code + run: | + tox -e check + - name: Test code + run: | + tox -e py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9157ce5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: python -sudo: false -cache: pip -env: - global: - - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so - - SEGFAULT_SIGNALS=all - matrix: - - TOXENV=check - - TOXENV=docs -matrix: - include: - - python: '2.7' - env: - - TOXENV=py27,report - - python: '3.3' - env: - - TOXENV=py33,report - - python: '3.4' - env: - - TOXENV=py34,report - - python: '3.5' - env: - - TOXENV=py35,report - - python: '3.6' - env: - - TOXENV=py36,report - - python: 'pypy-5.4' - env: - - TOXENV=pypy,report -before_install: -- python --version -- uname -a -- lsb_release -a -install: -- pip install tox -- virtualenv --version -- easy_install --version -- pip --version -- tox --version -script: -- tox -v -after_failure: -- more .tox/log/* | cat -- more .tox/*/log/* | cat -notifications: - email: - on_success: never - on_failure: always diff --git a/pymaven/constants.py b/pymaven/constants.py index ed06109..ea69dda 100644 --- a/pymaven/constants.py +++ b/pymaven/constants.py @@ -17,5 +17,6 @@ VERSION = (0, 2, 0) + def get_version(): return '.'.join(str(v) for v in VERSION) diff --git a/pymaven/versioning.py b/pymaven/versioning.py index e89de6c..84a3cb3 100644 --- a/pymaven/versioning.py +++ b/pymaven/versioning.py @@ -47,8 +47,8 @@ } -def list2tuple(l): - return tuple(list2tuple(x) if isinstance(x, list) else x for x in l) +def list2tuple(li): + return tuple(list2tuple(x) if isinstance(x, list) else x for x in li) @functools.total_ordering @@ -460,17 +460,17 @@ def _int_compare(self, this, other): else: raise RuntimeError("other is of invalid type: %s" % type(other)) - def _list_compare(self, l, other): + def _list_compare(self, this, other): if other is None: - if len(l) == 0: + if len(this) == 0: return 0 - return self._compare(l[0], other) + return self._compare(this[0], other) if isinstance(other, int): return -1 elif isinstance(other, six.string_types): return 1 elif isinstance(other, (list, tuple)): - for left, right in zip_longest(l, other): + for left, right in zip_longest(this, other): if left is None: if right is None: result = 0 @@ -485,41 +485,41 @@ def _list_compare(self, l, other): else: raise RuntimeError("other is of invalid type: %s" % type(other)) - def _new_list(self, l): - """Create a new sublist, append it to the current list and return the + def _new_list(self, old): + """Create a new sublist, append it to the old list and return the sublist - :param list l: list to add a sublist to + :param list old: list to add a sublist to :return: the sublist :rtype: list """ - l = self._normalize(l) + old = self._normalize(old) sublist = [] - l.append(sublist) + old.append(sublist) return sublist - def _normalize(self, l): - for item in l[::-1]: + def _normalize(self, li): + for item in li[::-1]: if not item: - l.pop() + li.pop() elif not isinstance(item, list): break - return l + return li - def _string_compare(self, s, other): - """Compare string item `s` to `other` + def _string_compare(self, this, other): + """Compare string item `this` to `other` - :param str s: string item to compare + :param str this: string item to compare :param other: other item to compare :type other: int, str, list or None """ if other is None: - return self._string_compare(s, "") + return self._string_compare(this, "") if isinstance(other, (int, list, tuple)): return -1 elif isinstance(other, six.string_types): - s_value = self._string_value(s) + s_value = self._string_value(this) other_value = self._string_value(other) if s_value < other_value: return -1 diff --git a/setup.cfg b/setup.cfg index 11ad9c5..09f1ced 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,5 +61,4 @@ from_first = true line_length = 120 known_first_party = pymaven default_section = THIRDPARTY -not_skip = __init__.py skip = migrations, south_migrations diff --git a/tests/test_client.py b/tests/test_client.py index 3fc5c9c..bc807b7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -201,14 +201,18 @@ def test_get_versions(self, _os): "LocalRepository.get_versions(%s)" % input def test_open(self): - with tempfile.NamedTemporaryFile() as tmp: - repo = LocalRepository(os.path.dirname(tmp.name)) + with tempfile.NamedTemporaryFile(delete=False) as tmp: tmp.write(b"the file\n") - tmp.flush() + + try: + repo = LocalRepository(os.path.dirname(tmp.name)) with repo.open(tmp.name) as fh: assert "the file\n" == fh.read() - self.assertRaises(MissingPathError, repo.open, "/does/not/exist") + self.assertRaises(MissingPathError, repo.open, "/does/not/exist") + finally: + # clean up temporary file + os.remove(tmp.name) SIMPLE_METADATA = """\ diff --git a/tests/test_pom.py b/tests/test_pom.py index 83b37e9..9152cd8 100644 --- a/tests/test_pom.py +++ b/tests/test_pom.py @@ -20,8 +20,8 @@ from six import BytesIO import six -from pymaven import VersionRange as VR from pymaven import Artifact +from pymaven import VersionRange as VR from pymaven.client import MavenClient from pymaven.client import Struct from pymaven.pom import Pom diff --git a/tox.ini b/tox.ini index 0c663ec..9e5057e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,30 +1,19 @@ [tox] -envlist = clean, check, py{27,34,35,36,py}, report +envlist = clean, check, py{36,37,38,py}, report [testenv] -basepython = - {py27,docs}: {env:TOXPYTHON:python2.7} - py34: {env:TOXPYTHON:python3.4} - py35: {env:TOXPYTHON:python3.5} - py36: {env:TOXPYTHON:python3.6} - pypy: {env:TOXPYTHON:pypy} - {clean,check,report}: python3 setenv = PYTHONPATH={toxinidir}/tests PYTHONUNBUFFERED=yes -passenv = - * +passenv = * deps = -rrequirements.txt -rtest-requirements.txt - pytest-travis-fold -usedevelop = false commands = {posargs:py.test --cov --cov-report=term-missing -vv tests/} [testenv:docs] -deps = - -r{toxinidir}/docs/requirements.txt +deps = -r{toxinidir}/docs/requirements.txt commands = sphinx-build {posargs:-E} -b doctest docs dist/docs sphinx-build {posargs:-E} -b html docs dist/docs @@ -40,8 +29,8 @@ deps = skip_install = true commands = python setup.py check --strict --metadata --restructuredtext - flake8 src tests setup.py - isort --verbose --check-only --diff --recursive pymaven/ tests/ setup.py + flake8 pymaven/ tests/ setup.py + isort --verbose --check-only --diff pymaven/ tests/ setup.py [testenv:clean] deps = coverage