Skip to content

Commit

Permalink
Python Code Cleanup (#14)
Browse files Browse the repository at this point in the history
* Python code cleanup by the cleanup-python-code Jenkins job.

This pull request was generated by the cleanup-python-code Jenkins job, which ran
```
modernize_travis;modernize_tox;make upgrade;find . -type f -name '*.py' | while read fname; do pyupgrade --exit-zero-even-if-changed --keep-percent-format --py3-plus --py36-plus --py38-plus "$fname"; done
```

The following packages were installed:
`pyupgrade,git+https://github.com/edx/repo-tools.git@c05453b733602ba7a2224ffbbf58a8d0903b62d8`

* Drop Python 3.5

Co-authored-by: Zulqarnain <[email protected]>
  • Loading branch information
edx-requirements-bot and Zulqarnain authored Jan 15, 2021
1 parent d41cce9 commit 07c74fc
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 109 deletions.
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
language: python
python:
- 3.5
- 3.8
- '3.8'
install:
- pip install pip==20.0.2
- make requirements
- pip install coveralls
envs:
- TOXENV=quality
matrix:
include:
- python: 3.5
env: TOXENV=py35
- python: 3.8
env: TOXENV=py38
- TOXENV=py38
script:
- tox
after_success:
Expand Down
8 changes: 3 additions & 5 deletions ccx_keys/locator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
""" Locator module. """
import re

Expand All @@ -25,7 +24,6 @@ class CCXLocator(CourseLocator, CCXKey):

# pep8 and pylint don't agree on the indentation in this block; let's make
# pep8 happy and ignore pylint as that's easier to do.
# pylint: disable=bad-continuation
URL_RE_SOURCE = r"""
((?P<org>{ALLOWED_ID_CHARS}+)\+(?P<course>{ALLOWED_ID_CHARS}+)(\+(?P<run>{ALLOWED_ID_CHARS}+))?{SEP})??
({BRANCH_PREFIX}@(?P<branch>{ALLOWED_ID_CHARS}+){SEP})?
Expand Down Expand Up @@ -56,7 +54,7 @@ def __init__(self, **kwargs):
if kwargs.get('deprecated', False):
raise InvalidKeyError(self.__class__, "cannot be deprecated")

super(CCXLocator, self).__init__(**kwargs)
super().__init__(**kwargs)

@classmethod
def from_course_locator(cls, course_locator, ccx):
Expand Down Expand Up @@ -89,7 +87,7 @@ def _to_string(self):
"""
Return a string representing this location.
"""
string = super(CCXLocator, self)._to_string()
string = super()._to_string()
# append the identifier for the ccx to the existing course string
string += "+{prefix}@{ccx}".format(
prefix=self.CCX_PREFIX, ccx=self.ccx
Expand Down Expand Up @@ -141,7 +139,7 @@ def replace(self, **kwargs):
if course_key_kwargs:
kwargs['course_key'] = self.course_key.replace(**course_key_kwargs)

return super(CCXBlockUsageLocator, self).replace(**kwargs)
return super().replace(**kwargs)

@classmethod
def _from_string(cls, serialized):
Expand Down
19 changes: 9 additions & 10 deletions ccx_keys/tests/test_ccx_keys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Tests for the ccx_keys package. """
import six
import ddt
import itertools # pylint: disable=wrong-import-order
from bson.objectid import ObjectId
Expand Down Expand Up @@ -135,9 +134,9 @@ def test_missing_ccx_id(self, fields):
'run': '2014_T2',
'branch': 'draft-1',
}
use_fields = dict(
(k, v) for k, v in list(available_fields.items()) if k in fields
)
use_fields = {
k: v for k, v in list(available_fields.items()) if k in fields
}
with self.assertRaises(InvalidKeyError) as context_manager:
CCXLocator(**use_fields)

Expand Down Expand Up @@ -182,9 +181,9 @@ def test_locator_from_good_url(self, fields, url_template):
}
this_url = url_template.format(**available_fields)
testobj = CourseKey.from_string(this_url)
use_keys = dict(
(k, v) for k, v in list(available_fields.items()) if k in fields
)
use_keys = {
k: v for k, v in list(available_fields.items()) if k in fields
}

if 'version_guid' in use_keys:
use_keys['version_guid'] = ObjectId(use_keys['version_guid'])
Expand Down Expand Up @@ -235,7 +234,7 @@ def test_from_course_locator_constructor(self, fields):
'branch': 'draft-1',
}
ccx = '1'
use_fields = dict((k, v) for k, v in list(available_fields.items()) if k in fields)
use_fields = {k: v for k, v in list(available_fields.items()) if k in fields}
course_id = CourseLocator(**use_fields)
testobj = CCXLocator.from_course_locator(course_id, ccx)

Expand Down Expand Up @@ -289,14 +288,14 @@ class TestCCXBlockUsageLocator(LocatorBaseTest):
"i4x://org.dept%sub-prof/course.num%section-4/category/name:12%33-44",
)
def test_string_roundtrip(self, url):
actual = six.text_type(UsageKey.from_string(url))
actual = str(UsageKey.from_string(url))
self.assertEqual(
url,
actual
)

@ddt.data(
"ccx-block-v1:org+course+run+ccx@1+{}@category".format(CCXBlockUsageLocator.BLOCK_TYPE_PREFIX),
f"ccx-block-v1:org+course+run+ccx@1+{CCXBlockUsageLocator.BLOCK_TYPE_PREFIX}@category",
"ccx-block-v1:org+course+run+{}@revision+ccx@1+{}@category".format(CourseLocator.BRANCH_PREFIX,
CCXBlockUsageLocator.BLOCK_TYPE_PREFIX),
)
Expand Down
10 changes: 5 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# make upgrade
#
edx-opaque-keys==2.1.0 # via -r requirements/base.in
pbr==5.4.5 # via stevedore
pymongo==3.10.1 # via edx-opaque-keys
six==1.14.0 # via -r requirements/base.in, edx-opaque-keys, stevedore
stevedore==1.32.0 # via edx-opaque-keys
edx-opaque-keys==2.1.1 # via -r requirements/base.in
pbr==5.5.1 # via stevedore
pymongo==3.11.2 # via edx-opaque-keys
six==1.15.0 # via -r requirements/base.in, edx-opaque-keys
stevedore==3.3.0 # via edx-opaque-keys
52 changes: 24 additions & 28 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,40 @@
#
# make upgrade
#
appdirs==1.4.3 # via -r requirements/test.txt, -r requirements/travis.txt, virtualenv
astroid==2.3.3 # via -r requirements/test.txt, pylint, pylint-celery
appdirs==1.4.4 # via -r requirements/test.txt, -r requirements/travis.txt, virtualenv
astroid==2.4.2 # via -r requirements/test.txt, pylint, pylint-celery
click-log==0.3.2 # via -r requirements/test.txt, edx-lint
click==7.1.2 # via -r requirements/pip-tools.txt, -r requirements/test.txt, click-log, edx-lint, pip-tools
coverage==5.1 # via -r requirements/test.txt
ddt==1.3.1 # via -r requirements/test.txt
distlib==0.3.0 # via -r requirements/test.txt, -r requirements/travis.txt, virtualenv
edx-lint==1.4.1 # via -r requirements/test.txt
edx-opaque-keys==2.1.0 # via -r requirements/test.txt
coverage==5.3.1 # via -r requirements/test.txt
ddt==1.4.1 # via -r requirements/test.txt
distlib==0.3.1 # via -r requirements/test.txt, -r requirements/travis.txt, virtualenv
edx-lint==1.6 # via -r requirements/test.txt
edx-opaque-keys==2.1.1 # via -r requirements/test.txt
filelock==3.0.12 # via -r requirements/test.txt, -r requirements/travis.txt, tox, virtualenv
importlib-metadata==1.6.0 # via -r requirements/test.txt, -r requirements/travis.txt, importlib-resources, pluggy, tox, virtualenv
importlib-resources==1.5.0 # via -r requirements/test.txt, -r requirements/travis.txt, virtualenv
isort==4.3.21 # via -r requirements/test.txt, pylint
isort==5.7.0 # via -r requirements/test.txt, pylint
lazy-object-proxy==1.4.3 # via -r requirements/test.txt, astroid
mccabe==0.6.1 # via -r requirements/test.txt, pylint
mock==3.0.5 # via -r requirements/test.txt
mock==4.0.3 # via -r requirements/test.txt
nose==1.3.7 # via -r requirements/test.txt
packaging==20.3 # via -r requirements/test.txt, -r requirements/travis.txt, tox
pbr==5.4.5 # via -r requirements/test.txt, stevedore
pip-tools==5.1.2 # via -r requirements/pip-tools.txt
packaging==20.8 # via -r requirements/test.txt, -r requirements/travis.txt, tox
pbr==5.5.1 # via -r requirements/test.txt, stevedore
pip-tools==5.5.0 # via -r requirements/pip-tools.txt
pluggy==0.13.1 # via -r requirements/test.txt, -r requirements/travis.txt, tox
py==1.8.1 # via -r requirements/test.txt, -r requirements/travis.txt, tox
pycodestyle==2.5.0 # via -r requirements/test.txt
py==1.10.0 # via -r requirements/test.txt, -r requirements/travis.txt, tox
pycodestyle==2.6.0 # via -r requirements/test.txt
pylint-celery==0.3 # via -r requirements/test.txt, edx-lint
pylint-django==2.0.11 # via -r requirements/test.txt, edx-lint
pylint-django==2.3.0 # via -r requirements/test.txt, edx-lint
pylint-plugin-utils==0.6 # via -r requirements/test.txt, pylint-celery, pylint-django
pylint==2.4.2 # via -r requirements/test.txt, edx-lint, pylint-celery, pylint-django, pylint-plugin-utils
pymongo==3.10.1 # via -r requirements/test.txt, edx-opaque-keys
pylint==2.6.0 # via -r requirements/test.txt, edx-lint, pylint-celery, pylint-django, pylint-plugin-utils
pymongo==3.11.2 # via -r requirements/test.txt, edx-opaque-keys
pyparsing==2.4.7 # via -r requirements/test.txt, -r requirements/travis.txt, packaging
six==1.14.0 # via -r requirements/pip-tools.txt, -r requirements/test.txt, -r requirements/travis.txt, astroid, edx-lint, edx-opaque-keys, mock, packaging, pip-tools, stevedore, tox, virtualenv
stevedore==1.32.0 # via -r requirements/test.txt, edx-opaque-keys
toml==0.10.0 # via -r requirements/test.txt, -r requirements/travis.txt, tox
tox-battery==0.5.2 # via -r requirements/dev.in
tox==3.15.0 # via -r requirements/test.txt, -r requirements/travis.txt, tox-battery
typed-ast==1.4.1 # via -r requirements/test.txt, astroid
virtualenv==20.0.20 # via -r requirements/test.txt, -r requirements/travis.txt, tox
wrapt==1.11.2 # via -r requirements/test.txt, astroid
zipp==1.2.0 # via -r requirements/test.txt, -r requirements/travis.txt, importlib-metadata, importlib-resources
six==1.15.0 # via -r requirements/test.txt, -r requirements/travis.txt, astroid, edx-lint, edx-opaque-keys, tox, virtualenv
stevedore==3.3.0 # via -r requirements/test.txt, edx-opaque-keys
toml==0.10.2 # via -r requirements/test.txt, -r requirements/travis.txt, pylint, tox
tox-battery==0.6.1 # via -r requirements/dev.in
tox==3.21.0 # via -r requirements/test.txt, -r requirements/travis.txt, tox-battery
virtualenv==20.3.0 # via -r requirements/test.txt, -r requirements/travis.txt, tox
wrapt==1.12.1 # via -r requirements/test.txt, astroid

# The following packages are considered to be unsafe in a requirements file:
# pip
3 changes: 1 addition & 2 deletions requirements/pip-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# make upgrade
#
click==7.1.2 # via pip-tools
pip-tools==5.1.2 # via -r requirements/pip-tools.in
six==1.14.0 # via pip-tools
pip-tools==5.5.0 # via -r requirements/pip-tools.in

# The following packages are considered to be unsafe in a requirements file:
# pip
48 changes: 22 additions & 26 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,35 @@
#
# make upgrade
#
appdirs==1.4.3 # via virtualenv
astroid==2.3.3 # via pylint, pylint-celery
appdirs==1.4.4 # via virtualenv
astroid==2.4.2 # via pylint, pylint-celery
click-log==0.3.2 # via edx-lint
click==7.1.2 # via click-log, edx-lint
coverage==5.1 # via -r requirements/test.in
ddt==1.3.1 # via -r requirements/test.in
distlib==0.3.0 # via virtualenv
edx-lint==1.4.1 # via -r requirements/test.in
edx-opaque-keys==2.1.0 # via -r requirements/base.txt
coverage==5.3.1 # via -r requirements/test.in
ddt==1.4.1 # via -r requirements/test.in
distlib==0.3.1 # via virtualenv
edx-lint==1.6 # via -r requirements/test.in
edx-opaque-keys==2.1.1 # via -r requirements/base.txt
filelock==3.0.12 # via tox, virtualenv
importlib-metadata==1.6.0 # via importlib-resources, pluggy, tox, virtualenv
importlib-resources==1.5.0 # via virtualenv
isort==4.3.21 # via pylint
isort==5.7.0 # via pylint
lazy-object-proxy==1.4.3 # via -r requirements/test.in, astroid
mccabe==0.6.1 # via pylint
mock==3.0.5 # via -r requirements/test.in
mock==4.0.3 # via -r requirements/test.in
nose==1.3.7 # via -r requirements/test.in
packaging==20.3 # via tox
pbr==5.4.5 # via -r requirements/base.txt, stevedore
packaging==20.8 # via tox
pbr==5.5.1 # via -r requirements/base.txt, stevedore
pluggy==0.13.1 # via tox
py==1.8.1 # via tox
pycodestyle==2.5.0 # via -r requirements/test.in
py==1.10.0 # via tox
pycodestyle==2.6.0 # via -r requirements/test.in
pylint-celery==0.3 # via edx-lint
pylint-django==2.0.11 # via edx-lint
pylint-django==2.3.0 # via edx-lint
pylint-plugin-utils==0.6 # via pylint-celery, pylint-django
pylint==2.4.2 # via edx-lint, pylint-celery, pylint-django, pylint-plugin-utils
pymongo==3.10.1 # via -r requirements/base.txt, edx-opaque-keys
pylint==2.6.0 # via edx-lint, pylint-celery, pylint-django, pylint-plugin-utils
pymongo==3.11.2 # via -r requirements/base.txt, edx-opaque-keys
pyparsing==2.4.7 # via packaging
six==1.14.0 # via -r requirements/base.txt, astroid, edx-lint, edx-opaque-keys, mock, packaging, stevedore, tox, virtualenv
stevedore==1.32.0 # via -r requirements/base.txt, edx-opaque-keys
toml==0.10.0 # via tox
tox==3.15.0 # via -r requirements/test.in
typed-ast==1.4.1 # via astroid
virtualenv==20.0.20 # via tox
wrapt==1.11.2 # via astroid
zipp==1.2.0 # via importlib-metadata, importlib-resources
six==1.15.0 # via -r requirements/base.txt, astroid, edx-lint, edx-opaque-keys, tox, virtualenv
stevedore==3.3.0 # via -r requirements/base.txt, edx-opaque-keys
toml==0.10.2 # via pylint, tox
tox==3.21.0 # via -r requirements/test.in
virtualenv==20.3.0 # via tox
wrapt==1.12.1 # via astroid
19 changes: 8 additions & 11 deletions requirements/travis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
#
# make upgrade
#
appdirs==1.4.3 # via virtualenv
distlib==0.3.0 # via virtualenv
appdirs==1.4.4 # via virtualenv
distlib==0.3.1 # via virtualenv
filelock==3.0.12 # via tox, virtualenv
importlib-metadata==1.6.0 # via importlib-resources, pluggy, tox, virtualenv
importlib-resources==1.5.0 # via virtualenv
packaging==20.3 # via tox
packaging==20.8 # via tox
pluggy==0.13.1 # via tox
py==1.8.1 # via tox
py==1.10.0 # via tox
pyparsing==2.4.7 # via packaging
six==1.14.0 # via packaging, tox, virtualenv
toml==0.10.0 # via tox
tox==3.15.0 # via -r requirements/travis.in
virtualenv==20.0.20 # via tox
zipp==1.2.0 # via importlib-metadata, importlib-resources
six==1.15.0 # via tox, virtualenv
toml==0.10.2 # via tox
tox==3.21.0 # via -r requirements/travis.in
virtualenv==20.3.0 # via tox
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Package metadata for edx-ccx-keys.
"""
from io import open

from setuptools import setup

Expand Down Expand Up @@ -35,7 +33,7 @@ def is_requirement(line):

setup(
name='edx-ccx-keys',
version='1.1.0',
version='1.2.0',
author='edX',
author_email='[email protected]',
description='Opaque key support custom courses on edX',
Expand All @@ -49,7 +47,6 @@ def is_requirement(line):
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.8',
],
packages=[
Expand Down
20 changes: 10 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tox]
envlist = py{35,38},quality
envlist = py38,quality

[testenv]
deps =
-r{toxinidir}/requirements/test.txt

commands =
coverage run -m nose
coverage report -m
deps =
-r{toxinidir}/requirements/test.txt
commands =
coverage run -m nose
coverage report -m

[testenv:quality]
commands =
pycodestyle --config=.pep8 ccx_keys
pylint --rcfile=pylintrc ccx_keys
commands =
pycodestyle --config=.pep8 ccx_keys
pylint --rcfile=pylintrc ccx_keys

0 comments on commit 07c74fc

Please sign in to comment.