Skip to content

Commit 5b64b51

Browse files
cclaussjmbowman
authored andcommittedFeb 27, 2019
[INCR-98] and [INCR-99] Run Python modernize -w . (#147)
* [INCR-98] Run Python modernize * Placate pylint
1 parent 1bb25c0 commit 5b64b51

38 files changed

+124
-60
lines changed
 

‎.travis.yml

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
dist: latest
22
language: python
3+
python:
4+
- 2.7
5+
- 3.6
6+
- 3.7
7+
env:
8+
- TOXENV=django111
9+
- TOXENV=django20
10+
- TOXENV=django21
311
matrix:
4-
allow_failures:
5-
- python: 3.6
6-
- python: 3.7
7-
812
include:
913
- python: 2.7
10-
env: TOXENV=django111
11-
- python: 3.6
12-
env: TOXENV=django111
14+
env: TOXENV=quality
1315
- python: 3.7
14-
env: TOXENV=django111
15-
- python: 3.6
16+
env: TOXENV=quality
17+
exclude:
18+
- python: 2.7
1619
env: TOXENV=django20
17-
- python: 3.6
20+
- python: 2.7
1821
env: TOXENV=django21
22+
allow_failures:
23+
- python: 3.6
1924
- python: 3.7
20-
env: TOXENV=django20
21-
- python: 3.7
22-
env: TOXENV=django21
23-
- python: 2.7
24-
env: TOXENV=quality
2525

2626
addons:
2727
firefox: "52.0.1"

‎bin/workbench-make-xblock

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import textwrap
99

1010
from cookiecutter.main import cookiecutter
1111

12-
1312
EXPLANATION = """\
1413
This script will create a new XBlock project.
1514

‎doc/conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14+
from __future__ import absolute_import
15+
1416
import os
1517
import sys
1618

‎manage.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22
"""Manage.py file for XBlock"""
3+
from __future__ import absolute_import
4+
35
import os
46
import sys
57

‎prototype/{{cookiecutter.short_name}}/setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Setup for {{cookiecutter.short_name|lower}} XBlock."""
22

3+
from __future__ import absolute_import
4+
35
import os
46

57
from setuptools import setup

‎prototype/{{cookiecutter.short_name}}/{{cookiecutter.short_name}}/{{cookiecutter.short_name}}.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""TO-DO: Write a description of what this XBlock is."""
22

33
import pkg_resources
4+
45
from xblock.core import XBlock
56
from xblock.fields import Integer, Scope
67
from xblock.fragment import Fragment

‎requirements/dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fs==2.0.27 # via django-pyfs, fs-s3fs, xblock
3434
funcsigs==1.0.2 # via mock, pytest
3535
future==0.17.1 # via backports.os
3636
futures==3.2.0 ; python_version == "2.7" # via isort, s3transfer
37-
isort==4.3.4
37+
isort==4.3.9
3838
jinja2==2.10 # via cookiecutter
3939
jmespath==0.9.3 # via boto3, botocore
4040
lazy-object-proxy==1.3.1 # via astroid

‎requirements/quality.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ configparser==3.7.1 # via pydocstyle, pylint
1212
edx-lint==1.1.1
1313
enum34==1.1.6 # via astroid
1414
futures==3.2.0 ; python_version == "2.7" # via isort
15-
isort==4.3.4
15+
isort==4.3.9
1616
lazy-object-proxy==1.3.1 # via astroid
1717
mccabe==0.6.1 # via pylint
1818
pycodestyle==2.5.0

‎sample_xblocks/basic/content.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# -*- coding: utf-8 -*-
22
"""Content-oriented XBlocks."""
33

4+
from __future__ import absolute_import
5+
46
from string import Template
57

68
from lxml import etree
79
from six import text_type
10+
811
from xblock.core import Scope, String, XBlock
912
from xblock.fragment import Fragment
1013

‎sample_xblocks/basic/problem.py

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
3535
"""
3636

37+
from __future__ import absolute_import
38+
3739
import inspect
3840
import random
3941
import string

‎sample_xblocks/basic/slider.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
WARNING: This is an experimental module, subject to future change or removal.
44
"""
55

6+
from __future__ import absolute_import
7+
68
import json
79

810
from webob import Response

‎sample_xblocks/basic/structure.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Structure-oriented XBlocks."""
22

3+
from __future__ import absolute_import
4+
35
from xblock.core import XBlock
46
from xblock.fragment import Fragment
57

‎sample_xblocks/basic/test/test_problem.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
Tests of the Problem XBlock, and its components.
33
"""
44

5+
from __future__ import absolute_import
6+
57
import json
68

79
import pytest
8-
import webob
9-
from xblock.test.tools import assert_equals
1010

11+
import webob
1112
from workbench.runtime import WorkbenchRuntime
13+
from xblock.test.tools import assert_equals
1214

1315

1416
def make_request(body):

‎sample_xblocks/basic/test/test_view_counter.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
""" Simple test for the view counter that verifies that it is updating properly """
22

3+
from __future__ import absolute_import
4+
5+
from six.moves import range
6+
37
from mock import Mock
8+
from sample_xblocks.basic.view_counter import ViewCounter
49
from xblock.runtime import DictKeyValueStore, KvsFieldData
510
from xblock.test.tools import TestRuntime as Runtime # Workaround for pytest trying to collect "TestRuntime" as a test
611
from xblock.test.tools import assert_equals, assert_in
712

8-
from sample_xblocks.basic.view_counter import ViewCounter
9-
1013

1114
def test_view_counter_state():
1215
key_store = DictKeyValueStore()
@@ -17,7 +20,7 @@ def test_view_counter_state():
1720
assert_equals(tester.views, 0)
1821

1922
# View the XBlock five times
20-
for i in xrange(5):
23+
for i in range(5):
2124
generated_html = tester.student_view({})
2225
# Make sure the html fragment we're expecting appears in the body_html
2326
assert_in('<span class="views">{0}</span>'.format(i + 1), generated_html.body_html())

‎sample_xblocks/basic/view_counter.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
""" Simple View Counting XBlock"""
2+
from __future__ import absolute_import
3+
24
from xblock.core import XBlock
35
from xblock.fields import Integer, Scope
46
from xblock.fragment import Fragment

‎sample_xblocks/filethumbs/filethumbs.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
1818
"""
1919

20+
from __future__ import absolute_import
21+
2022
import json
2123
import logging
2224

2325
import pkg_resources
24-
import png
2526
from six import text_type
27+
from six.moves import map
28+
29+
import png
2630
from xblock.core import XBlock
2731
from xblock.fields import Boolean, Scope
2832
from xblock.fragment import Fragment
@@ -31,7 +35,7 @@
3135
log = logging.getLogger(__name__)
3236

3337
ARROW = [
34-
map(int, value)
38+
list(map(int, value))
3539
for value in [
3640
'11011',
3741
'10001',

‎sample_xblocks/thumbs/thumbs.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""An XBlock providing thumbs-up/thumbs-down voting."""
22

3+
from __future__ import absolute_import
4+
35
import logging
46

57
import pkg_resources
68
from six import text_type
9+
710
from xblock.core import XBlock, XBlockAside
811
from xblock.fields import Boolean, Integer, Scope
912
from xblock.fragment import Fragment

‎settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import
2+
13
import warnings
24

35
from workbench.settings import *

‎setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Set up for XBlock SDK"""
2+
from __future__ import absolute_import
3+
24
import os
35
import os.path
46

‎tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ deps =
3333

3434
commands =
3535
pylint workbench sample_xblocks
36-
isort --check-only --recursive workbench sample_xblocks manage.py setup.py settings.py
36+
isort --check-only --recursive .

‎workbench/admin.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Basic admin screens for displaying XBlock state and filtering/searching on the
33
fields.
44
"""
5+
from __future__ import absolute_import
6+
57
from django.contrib import admin
68

79
from .models import XBlockState

‎workbench/blocks.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
"""
66

7+
from __future__ import absolute_import
8+
79
from xblock.core import XBlock
810
from xblock.fragment import Fragment
911

‎workbench/migrations/0001_initial.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Generated by Django 1.11.3 on 2017-08-01 12:30
33
from __future__ import unicode_literals
44

5+
from __future__ import absolute_import
56
from django.db import migrations, models
67
import django.utils.timezone
78

‎workbench/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
Admin gives us a lot of basic search/filtering for free.
88
99
"""
10-
from xblock.fields import BlockScope, Scope
10+
from __future__ import absolute_import
1111

1212
from django.db import models
1313
from django.utils.timezone import now
1414

15+
from xblock.fields import BlockScope, Scope
16+
1517

1618
def shorten_scope_name(scope_name):
1719
"""

‎workbench/runtime.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
Code in this file is a mix of Runtime layer and Workbench layer.
44
55
"""
6+
from __future__ import absolute_import
7+
68
import importlib
79
import itertools
810
import logging
911
from collections import defaultdict
1012

1113
from six import iteritems
12-
from xblock.core import XBlockAside
13-
from xblock.exceptions import NoSuchDefinition, NoSuchUsage
14-
from xblock.fragment import Fragment
15-
from xblock.reference.user_service import UserService, XBlockUser
16-
from xblock.runtime import IdGenerator, IdReader, KeyValueStore, KvsFieldData, NoSuchViewError, NullI18nService, Runtime
1714

1815
import django.utils.translation
1916
from django.conf import settings
2017
from django.core.urlresolvers import reverse
2118
from django.template import loader as django_template_loader
2219
from django.templatetags.static import static
2320

21+
from xblock.core import XBlockAside
22+
from xblock.exceptions import NoSuchDefinition, NoSuchUsage
23+
from xblock.fragment import Fragment
24+
from xblock.reference.user_service import UserService, XBlockUser
25+
from xblock.runtime import IdGenerator, IdReader, KeyValueStore, KvsFieldData, NoSuchViewError, NullI18nService, Runtime
26+
2427
from .models import XBlockState
2528
from .util import make_safe_for_html
2629

‎workbench/scenarios.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
This code is in the Workbench layer.
44
55
"""
6+
from __future__ import absolute_import
7+
68
import logging
79
from collections import namedtuple
810

9-
from xblock.core import XBlock
10-
1111
from django.conf import settings
1212
from django.template.defaultfilters import slugify
1313

14+
from xblock.core import XBlock
15+
1416
log = logging.getLogger(__name__)
1517

1618
# Build the scenarios, which are named trees of usages.

‎workbench/settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Django settings for workbench project."""
2+
from __future__ import absolute_import
3+
24
import json
35
import os
46

‎workbench/test/selenium_test.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
Helpers for Selenium tests.
33
"""
44

5+
from __future__ import absolute_import
6+
57
import pytest
6-
from bok_choy.web_app_test import WebAppTest
7-
from selenium.webdriver.support.expected_conditions import staleness_of
8-
from selenium.webdriver.support.ui import WebDriverWait
98

109
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
1110

11+
from bok_choy.web_app_test import WebAppTest
12+
from selenium.webdriver.support.expected_conditions import staleness_of
13+
from selenium.webdriver.support.ui import WebDriverWait
1214
from workbench.runtime_util import reset_global_state
1315

1416

‎workbench/test/test_filethumbs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the thumbs module"""
2-
from bok_choy.promise import EmptyPromise
2+
from __future__ import absolute_import
33

4+
from bok_choy.promise import EmptyPromise
45
from workbench import scenarios
56
from workbench.test.selenium_test import SeleniumTest
67

‎workbench/test/test_problems.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Test that problems and problem submission works well."""
2-
from __future__ import print_function
2+
from __future__ import absolute_import, print_function
33

44
import time
55
import unittest
66

7+
from six.moves import range
8+
79
from bok_choy.query import BrowserQuery
810
from selenium.common.exceptions import StaleElementReferenceException
9-
1011
from workbench import scenarios
1112
from workbench.test.selenium_test import SeleniumTest
1213

‎workbench/test/test_runtime.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
"""Test Workbench Runtime"""
22

3+
from __future__ import absolute_import
4+
35
from unittest import TestCase
46

5-
import mock
67
import pytest
8+
9+
from django.conf import settings
10+
11+
import mock
712
from xblock.fields import Scope
813
from xblock.reference.user_service import UserService
914
from xblock.runtime import KeyValueStore, KvsFieldData
1015

11-
from django.conf import settings
12-
1316
from ..runtime import ScenarioIdManager, WorkbenchDjangoKeyValueStore, WorkbenchRuntime
1417

1518

‎workbench/test/test_scenarios.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
Test that all scenarios render successfully.
33
"""
44

5+
from __future__ import absolute_import
6+
57
import unittest
68

79
import lxml.html
810
import pytest
9-
from xblock.test.tools import assert_equals
1011

1112
from django.core.urlresolvers import reverse
1213
from django.test.client import Client
1314

1415
from workbench import scenarios
1516
from workbench.runtime_util import reset_global_state
17+
from xblock.test.tools import assert_equals
1618

1719
pytestmark = pytest.mark.django_db # pylint: disable=invalid-name
1820

@@ -36,7 +38,7 @@ def test_all_scenarios(self):
3638
a_tags = list(html.xpath('//a'))
3739

3840
# Load the loaded_scenarios from the classes.
39-
loaded_scenarios = scenarios.get_scenarios().values()
41+
loaded_scenarios = list(scenarios.get_scenarios().values())
4042

4143
# We should have an <a> tag for each scenario.
4244
assert_equals(len(a_tags), len(loaded_scenarios))
@@ -60,7 +62,7 @@ def test_scenario(self):
6062
serve it. Normally we would get scenario_ids through a fixture, but
6163
it forces database access, which pytest_django doesn't like.
6264
"""
63-
scenario_ids = scenarios.get_scenarios().keys()
65+
scenario_ids = list(scenarios.get_scenarios().keys())
6466

6567
for scenario_id in scenario_ids:
6668
url = reverse('workbench_show_scenario', kwargs={'scenario_id': scenario_id})

‎workbench/test/test_thumbs.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Tests for the thumbs module"""
2+
from __future__ import absolute_import
3+
24
import pytest
3-
from bok_choy.promise import EmptyPromise
45

6+
from bok_choy.promise import EmptyPromise
57
from workbench import scenarios
68
from workbench.test.selenium_test import SeleniumTest
79

‎workbench/test/test_views.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
"""Test the workbench views."""
2-
from __future__ import print_function
2+
from __future__ import absolute_import, print_function
33

44
import functools
55
import json
66

77
import pytest
8-
from webob import Response
9-
from xblock.core import Scope, String, XBlock
10-
from xblock.exceptions import DisallowedFileError
11-
from xblock.fragment import Fragment
12-
from xblock.runtime import NoSuchHandlerError
13-
from xblock.test.tools import assert_equals, assert_in, assert_raises, assert_raises_regexp, assert_true
8+
from six.moves import zip
149

1510
from django.core.urlresolvers import reverse
1611
from django.test.client import Client
1712

13+
from webob import Response
1814
from workbench import scenarios
1915
from workbench.runtime import ID_MANAGER
16+
from xblock.core import Scope, String, XBlock
17+
from xblock.exceptions import DisallowedFileError
18+
from xblock.fragment import Fragment
19+
from xblock.runtime import NoSuchHandlerError
20+
from xblock.test.tools import assert_equals, assert_in, assert_raises, assert_raises_regexp, assert_true
2021

2122
pytestmark = pytest.mark.django_db # pylint: disable=invalid-name
2223

‎workbench/test_utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
33
These utilities use the workbench runtime to load XML scenarios.
44
"""
5-
from __future__ import print_function
5+
from __future__ import absolute_import, print_function
66

77
import json
88
from functools import wraps
99

1010
import webob
11-
1211
from workbench.runtime import WorkbenchRuntime
1312

1413

‎workbench/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Provide XBlock urls"""
22

3+
from __future__ import absolute_import
4+
35
from django.conf.urls import include, url
46
from django.contrib import admin
57
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

‎workbench/views.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
55
"""
66

7+
from __future__ import absolute_import
8+
79
import json
810
import logging
911
import mimetypes
1012

13+
from django.http import Http404, HttpResponse
14+
from django.shortcuts import redirect, render_to_response
15+
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
16+
1117
from xblock.core import XBlock, XBlockAside
1218
from xblock.django.request import django_to_webob_request, webob_to_django_response
1319
from xblock.exceptions import NoSuchUsage
1420
from xblock.plugin import PluginMissingError
1521

16-
from django.http import Http404, HttpResponse
17-
from django.shortcuts import redirect, render_to_response
18-
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
19-
2022
from .models import XBlockState
2123
from .runtime import WorkbenchRuntime
2224
from .runtime_util import reset_global_state

‎workbench/wsgi.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
framework.
1414
1515
"""
16+
from __future__ import absolute_import
17+
1618
import os
1719

1820
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workbench.settings")

0 commit comments

Comments
 (0)
Please sign in to comment.