Merge ~jugmac00/launchpadlib:flake8-code into launchpadlib:main

Proposed by Jürgen Gmach
Status: Merged
Merge reported by: Jürgen Gmach
Merged at revision: 1effcf41eb84cd394e6a39aa8fd030de30aa3c1d
Proposed branch: ~jugmac00/launchpadlib:flake8-code
Merge into: launchpadlib:main
Diff against target: 305 lines (+47/-26)
13 files modified
.pre-commit-config.yaml (+7/-0)
setup.cfg (+14/-0)
setup.py (+4/-2)
src/launchpadlib/apps.py (+0/-2)
src/launchpadlib/bin/launchpad-request-token (+3/-1)
src/launchpadlib/credentials.py (+7/-7)
src/launchpadlib/docs/conf.py (+0/-3)
src/launchpadlib/errors.py (+1/-1)
src/launchpadlib/launchpad.py (+4/-5)
src/launchpadlib/testing/helpers.py (+2/-2)
src/launchpadlib/tests/test_credential_store.py (+1/-1)
src/launchpadlib/tests/test_launchpad.py (+2/-0)
src/launchpadlib/uris.py (+2/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+410890@code.launchpad.net

Commit message

Use flake8 via pre-commit

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
2index 015c36c..8ef0d2f 100644
3--- a/.pre-commit-config.yaml
4+++ b/.pre-commit-config.yaml
5@@ -1,5 +1,7 @@
6 # See https://pre-commit.com for more information
7 # See https://pre-commit.com/hooks.html for more hooks
8+exclude: ^contrib/
9+
10 repos:
11 - repo: https://github.com/pre-commit/pre-commit-hooks
12 rev: v3.2.0
13@@ -8,3 +10,8 @@ repos:
14 - id: check-merge-conflict
15 - id: check-xml
16 - id: check-yaml
17+ - id: debug-statements
18+- repo: https://github.com/PyCQA/flake8
19+ rev: 3.9.2
20+ hooks:
21+ - id: flake8
22diff --git a/setup.cfg b/setup.cfg
23index 2a9acf1..121ec76 100644
24--- a/setup.cfg
25+++ b/setup.cfg
26@@ -1,2 +1,16 @@
27 [bdist_wheel]
28 universal = 1
29+
30+[flake8]
31+ignore =
32+ # indentation / whitespace issues -> will be auto-fixed by black
33+ E123
34+ E125
35+ E126
36+ E127
37+ E128
38+ E129
39+ E501
40+ # binary operator on same or next line; mutually exclusive
41+ W503
42+ W504
43\ No newline at end of file
44diff --git a/setup.py b/setup.py
45index 656888e..fbb9cab 100755
46--- a/setup.py
47+++ b/setup.py
48@@ -21,6 +21,7 @@
49 import sys
50 from setuptools import setup, find_packages
51
52+
53 # generic helpers primarily for the long_description
54 def generate(*docname_or_string):
55 marker = '.. pypi description ends here'
56@@ -38,6 +39,7 @@ def generate(*docname_or_string):
57 return '\n'.join(res)
58 # end generic helpers
59
60+
61 install_requires = [
62 'httplib2',
63 'importlib-metadata; python_version < "3.8"',
64@@ -53,14 +55,14 @@ setup(
65 name='launchpadlib',
66 version='1.10.15.1',
67 packages=find_packages('src'),
68- package_dir={'':'src'},
69+ package_dir={'': 'src'},
70 include_package_data=True,
71 zip_safe=False,
72 author='The Launchpad developers',
73 author_email='launchpadlib@lists.launchpad.net',
74 maintainer='LAZR Developers',
75 maintainer_email='lazr-developers@lists.launchpad.net',
76- download_url= 'https://launchpad.net/launchpadlib/+download',
77+ download_url='https://launchpad.net/launchpadlib/+download',
78 description=open('README.rst').readline().strip(),
79 long_description=generate(
80 'src/launchpadlib/docs/index.rst',
81diff --git a/src/launchpadlib/apps.py b/src/launchpadlib/apps.py
82index f58dcb4..dc716da 100644
83--- a/src/launchpadlib/apps.py
84+++ b/src/launchpadlib/apps.py
85@@ -48,5 +48,3 @@ class RequestTokenApp(object):
86 self.context, self.web_root,
87 token_format=Credentials.DICT_TOKEN_FORMAT)
88 return json.dumps(token)
89-
90-
91diff --git a/src/launchpadlib/bin/launchpad-request-token b/src/launchpadlib/bin/launchpad-request-token
92index 2cc7db1..0690b28 100755
93--- a/src/launchpadlib/bin/launchpad-request-token
94+++ b/src/launchpadlib/bin/launchpad-request-token
95@@ -22,6 +22,8 @@ This script will create a Launchpad request token and print to STDOUT
96 some JSON data about the token and the available access levels.
97 """
98
99+from __future__ import print_function
100+
101 __metaclass__ = type
102
103 from optparse import OptionParser
104@@ -45,4 +47,4 @@ if __name__ == '__main__':
105 consumer_name = args[0]
106 app = RequestTokenApp(
107 options.web_root, consumer_name, options.context)
108- print app.run()
109+ print(app.run())
110diff --git a/src/launchpadlib/credentials.py b/src/launchpadlib/credentials.py
111index 5607d20..e2a3350 100644
112--- a/src/launchpadlib/credentials.py
113+++ b/src/launchpadlib/credentials.py
114@@ -63,16 +63,16 @@ from six.moves.urllib.parse import parse_qs
115
116 if bytes is str:
117 # Python 2
118- unicode_type = unicode
119+ unicode_type = unicode # noqa: F821
120 else:
121 unicode_type = str
122-
123+
124 from lazr.restfulclient.errors import HTTPError
125 from lazr.restfulclient.authorize.oauth import (
126 AccessToken as _AccessToken,
127 Consumer,
128 OAuthAuthorizer,
129- SystemWideConsumer # Not used directly, just re-imported into here.
130+ SystemWideConsumer # Not used directly, just re-imported into here.
131 )
132
133 from launchpadlib import uris
134@@ -271,7 +271,7 @@ class AnonymousAccessToken(_AccessToken):
135 This token can be used for anonymous access.
136 """
137 def __init__(self):
138- super(AnonymousAccessToken, self).__init__('','')
139+ super(AnonymousAccessToken, self).__init__('', '')
140
141
142 class CredentialStore(object):
143@@ -436,7 +436,7 @@ class KeyringCredentialStore(CredentialStore):
144 try:
145 credentials = Credentials.from_string(credential_string)
146 return credentials
147- except:
148+ except Exception:
149 # If any error occurs at this point the most reasonable thing
150 # to do is return no credentials, which will require
151 # re-authorization but the user will be able to proceed.
152@@ -733,8 +733,8 @@ class AuthorizeRequestTokenWithBrowser(AuthorizeRequestTokenWithURL):
153 # are discarding the passed-in values for consumer_name and
154 # allow_access_levels.
155 super(AuthorizeRequestTokenWithBrowser, self).__init__(
156- service_root, application_name, None,
157- credential_save_failed)
158+ service_root, application_name, None,
159+ credential_save_failed)
160
161 def notify_end_user_authorization_url(self, authorization_url):
162 """Notify the end-user of the URL."""
163diff --git a/src/launchpadlib/docs/conf.py b/src/launchpadlib/docs/conf.py
164index e18d614..2424f52 100644
165--- a/src/launchpadlib/docs/conf.py
166+++ b/src/launchpadlib/docs/conf.py
167@@ -165,6 +165,3 @@ texinfo_documents = [
168 author, 'launchpadlib', 'One line description of project.',
169 'Miscellaneous'),
170 ]
171-
172-
173-
174diff --git a/src/launchpadlib/errors.py b/src/launchpadlib/errors.py
175index b9e59a4..87b6500 100644
176--- a/src/launchpadlib/errors.py
177+++ b/src/launchpadlib/errors.py
178@@ -17,4 +17,4 @@
179
180 """Reimport errors from restfulclient for convenience's sake."""
181
182-from lazr.restfulclient.errors import *
183+from lazr.restfulclient.errors import * # noqa: F401, F403
184diff --git a/src/launchpadlib/launchpad.py b/src/launchpadlib/launchpad.py
185index ec88b01..c2c20ed 100644
186--- a/src/launchpadlib/launchpad.py
187+++ b/src/launchpadlib/launchpad.py
188@@ -25,7 +25,7 @@ import errno
189 import os
190 try:
191 from urllib.parse import urlsplit
192-except:
193+except ImportError:
194 from urlparse import urlsplit
195 import warnings
196
197@@ -35,12 +35,12 @@ except ImportError:
198 from httplib2 import ProxyInfo
199 proxy_info_from_environment = ProxyInfo.from_environment
200
201-from lazr.restfulclient.resource import (
202+from lazr.restfulclient.resource import ( # noqa: F401
203 CollectionWithKeyBasedLookup,
204 HostedFile, # Re-import for client convenience
205 ScalarValue, # Re-import for client convenience
206 ServiceRoot,
207- )
208+)
209 from lazr.restfulclient.authorize.oauth import SystemWideConsumer
210 from lazr.restfulclient._browser import RestfulHttp
211 from launchpadlib.credentials import (
212@@ -58,7 +58,7 @@ from launchpadlib import uris
213
214
215 # Import old constants for backwards compatibility
216-from launchpadlib.uris import STAGING_SERVICE_ROOT, EDGE_SERVICE_ROOT
217+from launchpadlib.uris import STAGING_SERVICE_ROOT, EDGE_SERVICE_ROOT # noqa: F401
218 OAUTH_REALM = 'https://api.launchpad.net'
219
220
221@@ -598,7 +598,6 @@ class Launchpad(ServiceRoot):
222 argument_name, argument_value, object_value,
223 object_name, argument_name, object_name))
224
225-
226 @classmethod
227 def _get_paths(cls, service_root, launchpadlib_dir=None):
228 """Locate launchpadlib-related user paths and ensure they exist.
229diff --git a/src/launchpadlib/testing/helpers.py b/src/launchpadlib/testing/helpers.py
230index 1afddf3..9bec27e 100644
231--- a/src/launchpadlib/testing/helpers.py
232+++ b/src/launchpadlib/testing/helpers.py
233@@ -31,7 +31,7 @@ __all__ = [
234 'nopriv_read_nonprivate',
235 'salgado_read_nonprivate',
236 'salgado_with_full_permissions',
237- ]
238+]
239
240 from contextlib import contextmanager
241
242@@ -41,7 +41,7 @@ from launchpadlib.credentials import (
243 AccessToken,
244 Credentials,
245 RequestTokenAuthorizationEngine,
246- )
247+)
248
249
250 missing = object()
251diff --git a/src/launchpadlib/tests/test_credential_store.py b/src/launchpadlib/tests/test_credential_store.py
252index 0aa308b..5ce9e1b 100644
253--- a/src/launchpadlib/tests/test_credential_store.py
254+++ b/src/launchpadlib/tests/test_credential_store.py
255@@ -24,7 +24,7 @@ from base64 import b64decode
256
257 if bytes is str:
258 # Python 2
259- unicode_type = unicode
260+ unicode_type = unicode # noqa: F821
261 else:
262 unicode_type = str
263
264diff --git a/src/launchpadlib/tests/test_launchpad.py b/src/launchpadlib/tests/test_launchpad.py
265index 9a230d3..e21be2b 100644
266--- a/src/launchpadlib/tests/test_launchpad.py
267+++ b/src/launchpadlib/tests/test_launchpad.py
268@@ -57,6 +57,7 @@ from launchpadlib.credentials import (
269 # A dummy service root for use in tests
270 SERVICE_ROOT = "http://api.example.com/"
271
272+
273 class TestResourceTypeClasses(unittest.TestCase):
274 """launchpadlib must know about restfulclient's resource types."""
275
276@@ -624,6 +625,7 @@ class TestCredenitialSaveFailedCallback(unittest.TestCase):
277 # provided, it is called.
278
279 callback_called = []
280+
281 def callback():
282 # Since we can't rebind "callback_called" here, we'll have to
283 # settle for mutating it to signal success.
284diff --git a/src/launchpadlib/uris.py b/src/launchpadlib/uris.py
285index 2456a34..ae74669 100644
286--- a/src/launchpadlib/uris.py
287+++ b/src/launchpadlib/uris.py
288@@ -30,7 +30,7 @@ try:
289 from urllib.parse import urlparse
290 except ImportError:
291 from urlparse import urlparse
292-
293+
294 import warnings
295 from lazr.uri import URI
296
297@@ -67,7 +67,7 @@ service_roots = dict(
298
299 web_roots = dict(
300 production=LPNET_WEB_ROOT,
301- edge = LPNET_WEB_ROOT,
302+ edge=LPNET_WEB_ROOT,
303 qastaging=QASTAGING_WEB_ROOT,
304 staging=STAGING_WEB_ROOT,
305 dogfood=DOGFOOD_WEB_ROOT,

Subscribers

People subscribed via source and target branches