Skip to content

Commit

Permalink
Add workflow to lint and test pymaven
Browse files Browse the repository at this point in the history
Fixes some linting errors and drops old, unsupported versions of python.

Closes #7

Change-Id: I8684668fa8d259f751b211d053734023135ea53d
  • Loading branch information
wfscheper committed Jan 26, 2021
1 parent 471ea1f commit 73fe503
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 91 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions pymaven/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

VERSION = (0, 2, 0)


def get_version():
return '.'.join(str(v) for v in VERSION)
40 changes: 20 additions & 20 deletions pymaven/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 5 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 73fe503

Please sign in to comment.