Skip to content

Commit 022ee4c

Browse files
author
Mike Taylor
authored
Merge pull request #2829 from karlcow/2828/1
Fixes #2828 - Changes from pep8 to pycodestyle
2 parents 18598f8 + e2645f2 commit 022ee4c

20 files changed

+83
-75
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
name: run tests
5353
command: |
5454
. venv/bin/activate
55-
pep8 --ignore=E402 webcompat/ tests/ config/secrets.py.example
55+
pycodestyle --ignore=E402,W504 webcompat/ tests/ config/secrets.py.example
5656
npm run lint
5757
npm run build
5858
nosetests

config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import requests
1919

20-
from environment import * # nopep8
21-
from secrets import * # nopep8
20+
from environment import * # noqa
21+
from secrets import * # noqa
2222

2323
MILESTONE_ERROR = """It failed with {msg}!
2424
We will read from data/milestones.json.

config/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Flask-WTF==0.14.2
77
GitHub-Flask==3.2.0
88
mock==2.0.0
99
nose==1.3.7
10-
pep8==1.7.1
1110
Pillow==5.4.1
11+
pycodestyle==2.5.0
1212
requests==2.21.0
1313
ua-parser==0.8
1414
WTForms==2.2.1

docs/pr-coding-guidelines.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ For product and design contributions, check out the [Design Repo](https://github
9191
Try to take care to follow existing conventions. Some of these are defined in an [.editorconfig](https://github.com/webcompat/webcompat.com/blob/master/.editorconfig) file. You can download the plugin for your editor here http://editorconfig.org/#download.
9292

9393
### Python
94-
As we are still very early in the project, we do not yet have that many conventions for naming, routes, APIs. If in doubt, ask us or open an issue. All Python code should pass [pep8](http://pep8.readthedocs.org/en/1.4.6/intro.html).
94+
As we are still very early in the project, we do not yet have that many conventions for naming, routes, APIs. If in doubt, ask us or open an issue. All Python code should pass [pycodestyle](http://pycodestyle.pycqa.org/en/latest/intro.html).
9595

96-
You can check this by installing the pep8 module.
96+
You can check this by installing the pycodestyle module. This is usually installed through the requirements file in the project. If you wish to install it yourself on your computer, you can do.
9797

98-
sudo pip install pep8
98+
pip install --user pycodestyle
9999

100100
Once at the root of the project you can run it with
101101

102-
pep8 --show-source --show-pep8 .
102+
pycodestyle --ignore=E402,W504 webcompat/ tests/ config/secrets.py.example
103103

104104
That will show you the list of errors and their explanations. Another tool, we have used for checking consistency of the code is `flake8` + `hacking`. [Hacking](https://github.com/openstack-dev/hacking) is a set of [OpenStack guidelines](http://docs.openstack.org/developer/hacking/) which is used by the community for the stability of their projects. You will see that there's nothing really hard about it.
105105
106-
sudo pip install hacking
106+
pip install --user hacking
107107
108108
will install the relevant flake8 and hacking modules. In the same fashion, if you do
109109

tests/unit/test_api_urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'rv:31.0) Gecko/20100101 Firefox/31.0'),
2323
'HTTP_ACCEPT': 'application/json'}
2424

25-
STATUSES = {u'sitewait': {'color': '', 'state': 'open', 'id': 5, 'order': 5}, u'worksforme': {'color': '', 'state': 'closed', 'id': 11, 'order': 7}, u'non-compat': {'color': '', 'state': 'closed', 'id': 12, 'order': 5}, u'needsdiagnosis': {'color': '', 'state': 'open', 'id': 2, 'order': 2}, u'contactready': {'color': '', 'state': 'open', 'id': 4, 'order': 4}, u'wontfix': {'color': '', 'state': 'closed', 'id': 6, 'order': 6}, u'needscontact': {'color': '', 'state': 'open', 'id': 3, 'order': 3}, u'invalid': {'color': '', 'state': 'closed', 'id': 8, 'order': 4}, u'needstriage': {'color': '', 'state': 'open', 'id': 1, 'order': 1}, u'duplicate': {'color': '', 'state': 'closed', 'id': 10, 'order': 1}, u'fixed': {'color': '', 'state': 'closed', 'id': 9, 'order': 2}, u'incomplete': {'color': '', 'state': 'closed', 'id': 7, 'order': 3}} # nopep8
25+
STATUSES = {u'sitewait': {'color': '', 'state': 'open', 'id': 5, 'order': 5}, u'worksforme': {'color': '', 'state': 'closed', 'id': 11, 'order': 7}, u'non-compat': {'color': '', 'state': 'closed', 'id': 12, 'order': 5}, u'needsdiagnosis': {'color': '', 'state': 'open', 'id': 2, 'order': 2}, u'contactready': {'color': '', 'state': 'open', 'id': 4, 'order': 4}, u'wontfix': {'color': '', 'state': 'closed', 'id': 6, 'order': 6}, u'needscontact': {'color': '', 'state': 'open', 'id': 3, 'order': 3}, u'invalid': {'color': '', 'state': 'closed', 'id': 8, 'order': 4}, u'needstriage': {'color': '', 'state': 'open', 'id': 1, 'order': 1}, u'duplicate': {'color': '', 'state': 'closed', 'id': 10, 'order': 1}, u'fixed': {'color': '', 'state': 'closed', 'id': 9, 'order': 2}, u'incomplete': {'color': '', 'state': 'closed', 'id': 7, 'order': 3}} # noqa
2626

2727

2828
def mock_api_response(response_config={}):
@@ -63,7 +63,7 @@ def test_api_issues_out_of_range(self):
6363
with patch('webcompat.helpers.proxy_request') as github_data:
6464
github_data.return_value = mock_api_response({
6565
'status_code': 404,
66-
'content': '[{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}]' # nopep8
66+
'content': '[{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}]' # noqa
6767
})
6868
rv = self.app.get('/api/issues/1', environ_base=headers)
6969
json_body = json.loads(rv.data)
@@ -110,7 +110,7 @@ def test_api_comments_link_header_auth(self):
110110
'status_code': 200,
111111
'content': '[]',
112112
'headers': {
113-
'Link': '<https://api.github.com/repositories/17839063/issues/398/comments?page=2>; rel="next", <https://api.github.com/repositories/17839063/issues/398/comments?page=4>; rel="last"', # nopep8
113+
'Link': '<https://api.github.com/repositories/17839063/issues/398/comments?page=2>; rel="next", <https://api.github.com/repositories/17839063/issues/398/comments?page=4>; rel="last"', # noqa
114114
},
115115
}),
116116
mock_api_response({'status_code': 200, 'content': '[]'})

tests/unit/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ def test_update_status_config(self):
5353
actual = update_status_config(milestones_json)
5454
self.assertEqual(actual, expected)
5555

56+
5657
if __name__ == '__main__':
5758
unittest.main()

tests/unit/test_dashboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Add webcompat module to import path
2323
sys.path.append(os.path.realpath(os.pardir))
24-
import webcompat # nopep8
24+
import webcompat # noqa
2525

2626
# Any request that depends on parsing HTTP Headers (basically anything
2727
# on the index route, will need to include the following: environ_base=headers
@@ -87,5 +87,6 @@ def test_browser_labels(self):
8787
labels = ['status-foo', 'blah', 'browser-', 'browser-firefox']
8888
self.assertListEqual(['firefox'], browser_labels(labels))
8989

90+
9091
if __name__ == '__main__':
9192
unittest.main()

tests/unit/test_form.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from webcompat import form
1313
from webcompat import helpers
1414

15-
FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0' # nopep8
15+
FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0' # noqa
1616

1717

1818
class TestForm(unittest.TestCase):
@@ -144,7 +144,7 @@ def test_get_metadata(self):
144144
metadata_keys = ['browser', 'ua_header', 'reported_with',
145145
'extra_labels']
146146
actual = form.get_metadata(metadata_keys, form_object)
147-
expected = u'<!-- @browser: Firefox 59.0 -->\n<!-- @ua_header: Mozilla/5.0...Firefox 59.0 -->\n<!-- @reported_with: desktop-reporter -->\n<!-- @extra_labels: type-webrender-enabled -->\n' # nopep8
147+
expected = u'<!-- @browser: Firefox 59.0 -->\n<!-- @ua_header: Mozilla/5.0...Firefox 59.0 -->\n<!-- @reported_with: desktop-reporter -->\n<!-- @extra_labels: type-webrender-enabled -->\n' # noqa
148148
self.assertEqual(actual, expected)
149149

150150
def test_get_metadata_browser_as_extra(self):
@@ -158,7 +158,7 @@ def test_get_metadata_browser_as_extra(self):
158158
metadata_keys = ['browser', 'ua_header', 'reported_with',
159159
'extra_labels']
160160
actual = form.get_metadata(metadata_keys, form_object)
161-
expected = u'<!-- @browser: Firefox 59.0 -->\n<!-- @ua_header: Mozilla/5.0...Firefox 59.0 -->\n<!-- @reported_with: desktop-reporter -->\n<!-- @extra_labels: browser-focus-geckoview -->\n' # nopep8
161+
expected = u'<!-- @browser: Firefox 59.0 -->\n<!-- @ua_header: Mozilla/5.0...Firefox 59.0 -->\n<!-- @reported_with: desktop-reporter -->\n<!-- @extra_labels: browser-focus-geckoview -->\n' # noqa
162162
self.assertEqual(actual, expected)
163163

164164
def test_normalize_metadata(self):
@@ -181,18 +181,18 @@ def test_build_formdata(self):
181181
# even if the data are empty
182182
form_object = {'foo': 'bar'}
183183
actual = form.build_formdata(form_object)
184-
expected = {'body': u'<!-- @browser: None -->\n<!-- @ua_header: None -->\n<!-- @reported_with: None -->\n\n**URL**: None\n\n**Browser / Version**: None\n**Operating System**: None\n**Tested Another Browser**: Unknown\n\n**Problem type**: Unknown\n**Description**: None\n**Steps to Reproduce**:\nNone\n\n\n\n_From [webcompat.com](https://webcompat.com/) with \u2764\ufe0f_', 'title': 'None - unknown'} # nopep8
184+
expected = {'body': u'<!-- @browser: None -->\n<!-- @ua_header: None -->\n<!-- @reported_with: None -->\n\n**URL**: None\n\n**Browser / Version**: None\n**Operating System**: None\n**Tested Another Browser**: Unknown\n\n**Problem type**: Unknown\n**Description**: None\n**Steps to Reproduce**:\nNone\n\n\n\n_From [webcompat.com](https://webcompat.com/) with \u2764\ufe0f_', 'title': 'None - unknown'} # noqa
185185
self.assertIs(type(actual), dict)
186186
self.assertEqual(actual, expected)
187187
# testing for double URL Schemes.
188188
form_object = {'url': 'http://https://example.com/'}
189189
actual = form.build_formdata(form_object)
190-
expected = {'body': u'<!-- @browser: None -->\n<!-- @ua_header: None -->\n<!-- @reported_with: None -->\n\n**URL**: https://example.com/\n\n**Browser / Version**: None\n**Operating System**: None\n**Tested Another Browser**: Unknown\n\n**Problem type**: Unknown\n**Description**: None\n**Steps to Reproduce**:\nNone\n\n\n\n_From [webcompat.com](https://webcompat.com/) with \u2764\ufe0f_', 'title': 'example.com - unknown'} # nopep8
190+
expected = {'body': u'<!-- @browser: None -->\n<!-- @ua_header: None -->\n<!-- @reported_with: None -->\n\n**URL**: https://example.com/\n\n**Browser / Version**: None\n**Operating System**: None\n**Tested Another Browser**: Unknown\n\n**Problem type**: Unknown\n**Description**: None\n**Steps to Reproduce**:\nNone\n\n\n\n_From [webcompat.com](https://webcompat.com/) with \u2764\ufe0f_', 'title': 'example.com - unknown'} # noqa
191191
self.assertEqual(actual, expected)
192192
# testing with unicode strings.
193193
form_object = {'url': u'愛'}
194194
actual = form.build_formdata(form_object)
195-
expected = {'body': u'<!-- @browser: None -->\n<!-- @ua_header: None -->\n<!-- @reported_with: None -->\n\n**URL**: http://\u611b\n\n**Browser / Version**: None\n**Operating System**: None\n**Tested Another Browser**: Unknown\n\n**Problem type**: Unknown\n**Description**: None\n**Steps to Reproduce**:\nNone\n\n\n\n_From [webcompat.com](https://webcompat.com/) with \u2764\ufe0f_', 'title': u'\u611b - unknown'} # nopep8
195+
expected = {'body': u'<!-- @browser: None -->\n<!-- @ua_header: None -->\n<!-- @reported_with: None -->\n\n**URL**: http://\u611b\n\n**Browser / Version**: None\n**Operating System**: None\n**Tested Another Browser**: Unknown\n\n**Problem type**: Unknown\n**Description**: None\n**Steps to Reproduce**:\nNone\n\n\n\n_From [webcompat.com](https://webcompat.com/) with \u2764\ufe0f_', 'title': u'\u611b - unknown'} # noqa
196196
self.assertEqual(actual, expected)
197197

198198
def test_get_details(self):
@@ -209,26 +209,26 @@ def test_build_details(self):
209209
# Test for receiving JSON object as a string
210210
actual_json_arg = form.build_details(json.dumps(
211211
{'a': 'b', 'c': False}))
212-
expected_json_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>a: b</li><li>c: false</li>\n</ul>\n\n</details>' # nopep8
212+
expected_json_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>a: b</li><li>c: false</li>\n</ul>\n\n</details>' # noqa
213213
self.assertEqual(actual_json_arg, expected_json_arg)
214214
# Test for receiving a JSON value which is not an object
215215
actual_json_arg = form.build_details('null')
216-
expected_json_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>None</li>\n</ul>\n\n</details>' # nopep8
216+
expected_json_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>None</li>\n</ul>\n\n</details>' # noqa
217217
self.assertEqual(actual_json_arg, expected_json_arg)
218218
# Test for receiving a string
219219
actual_string_arg = form.build_details(u'cool')
220-
expected_string_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>cool</li>\n</ul>\n\n</details>' # nopep8
220+
expected_string_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>cool</li>\n</ul>\n\n</details>' # noqa
221221
self.assertEqual(actual_string_arg, expected_string_arg)
222222

223223
def test_build_details_with_console_logs(self):
224224
"""Expected HTML is returned for a json object with console logs."""
225225
actual_json_arg = form.build_details(json.dumps(
226226
{'a': 'b', 'c': False, 'consoleLog': ['console.log(hi)']}))
227-
expected_json_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>a: b</li><li>c: false</li>\n</ul>\n<p>Console Messages:</p>\n<pre>\n[u\'console.log(hi)\']\n</pre>\n</details>' # nopep8
227+
expected_json_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>a: b</li><li>c: false</li>\n</ul>\n<p>Console Messages:</p>\n<pre>\n[u\'console.log(hi)\']\n</pre>\n</details>' # noqa
228228
self.assertEqual(actual_json_arg, expected_json_arg)
229229
actual_empty_log_arg = form.build_details(json.dumps(
230230
{'a': 'b', 'c': False, 'consoleLog': ''}))
231-
expected_empty_log_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>a: b</li><li>c: false</li>\n</ul>\n\n</details>' # nopep8
231+
expected_empty_log_arg = '<details>\n<summary>Browser Configuration</summary>\n<ul>\n <li>a: b</li><li>c: false</li>\n</ul>\n\n</details>' # noqa
232232
self.assertEqual(actual_empty_log_arg, expected_empty_log_arg)
233233

234234
def test_get_console_section(self):

0 commit comments

Comments
 (0)