Skip to content

Commit 7524ed6

Browse files
committed
Fix PEP8 issues
1 parent 84fed9a commit 7524ed6

File tree

8 files changed

+49
-51
lines changed

8 files changed

+49
-51
lines changed

Diff for: pypuppetdb/QueryBuilder.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ def add_array(self, values):
288288
if self.query is not None:
289289
raise APIError("Only one array is supported by the InOperator")
290290
elif isinstance(values, list):
291-
def depth(l):
292-
return (isinstance(l, list) and len(l) != 0) \
293-
and max(map(depth, l)) + 1
291+
def depth(a_list):
292+
return (isinstance(a_list, list) and len(a_list) != 0) \
293+
and max(map(depth, a_list)) + 1
294294

295295
if depth(values) == 1:
296296
self.query = True
@@ -358,8 +358,8 @@ def add_query(self, query):
358358
"Operator Objects")
359359

360360
def add_order_by(self, fields):
361-
def depth(l):
362-
return isinstance(l, list) and max(map(depth, l)) + 1
361+
def depth(a_list):
362+
return isinstance(a_list, list) and max(map(depth, a_list)) + 1
363363

364364
fields_depth = depth(fields)
365365

Diff for: pypuppetdb/api/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def _query(self, endpoint=None, path=None, query=None,
325325
:rtype: :obj:`dict` or :obj:`list`
326326
"""
327327

328-
log.debug(f"_query called with ",
328+
log.debug("_query called with ",
329329
# comma-separated list of method arguments with their values
330330
", ".join([f"{arg}: {locals().get(arg, 'None')}"
331331
for arg in locals().keys() if arg != 'self'])

Diff for: pypuppetdb/api/pql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pypuppetdb.QueryBuilder import (EqualsOperator)
1010
from pypuppetdb.api.base import BaseAPI
1111
from pypuppetdb.errors import (APIError)
12-
from pypuppetdb.types import (Catalog, Node, Report)
12+
from pypuppetdb.types import (Node, Report)
1313

1414
log = logging.getLogger(__name__)
1515

@@ -151,5 +151,5 @@ def _get_type_from_query(pql):
151151
f" but it is not supported by this library yet.")
152152
return None
153153
else:
154-
log.debug(f"No match!")
154+
log.debug("No match!")
155155
return None

Diff for: pypuppetdb/api/query.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
from datetime import datetime
66

7-
import pypuppetdb
87
from pypuppetdb.QueryBuilder import (EqualsOperator)
98
from pypuppetdb.api.base import BaseAPI
109
from pypuppetdb.types import (Catalog, Edge, Event, Fact, Inventory,
@@ -39,7 +38,7 @@ def nodes(self, unreported=2, with_status=False, with_event_numbers=True,
3938
This provides performance benefits as potentially
4039
slow event-counts query is omitted completely.
4140
:type with_event_numbers: :bool:
42-
:param \*\*kwargs: The rest of the keyword arguments are passed
41+
:param **kwargs: The rest of the keyword arguments are passed
4342
to the _query function
4443
4544
:returns: A generator yieling Nodes.
@@ -81,7 +80,7 @@ def node(self, name):
8180
def edges(self, **kwargs):
8281
"""Get the known catalog edges, formed between two resources.
8382
84-
:param \*\*kwargs: The rest of the keyword arguments are passed
83+
:param **kwargs: The rest of the keyword arguments are passed
8584
to the _query function.
8685
8786
:returns: A generating yielding Edges.
@@ -95,7 +94,7 @@ def edges(self, **kwargs):
9594
def environments(self, **kwargs):
9695
"""Get all known environments from Puppetdb.
9796
98-
:param \*\*kwargs: The rest of the keyword arguments are passed
97+
:param **kwargs: The rest of the keyword arguments are passed
9998
to the _query function.
10099
101100
:returns: A list of dictionaries containing the results.
@@ -112,7 +111,7 @@ def facts(self, name=None, value=None, **kwargs):
112111
match this value. Use of this parameter requires the `name`\
113112
parameter be set.
114113
:type value: :obj:`string`
115-
:param \*\*kwargs: The rest of the keyword arguments are passed
114+
:param **kwargs: The rest of the keyword arguments are passed
116115
to the _query function
117116
118117
:returns: A generator yielding Facts.
@@ -132,7 +131,7 @@ def facts(self, name=None, value=None, **kwargs):
132131
def factsets(self, **kwargs):
133132
"""Returns a set of all facts or for a single certname.
134133
135-
:param \*\*kwargs: The rest of the keyword arguments are passed
134+
:param **kwargs: The rest of the keyword arguments are passed
136135
to the _query function.
137136
138137
:returns: A list of dictionaries containg the results.
@@ -145,7 +144,7 @@ def fact_contents(self, **kwargs):
145144
to descend into structured facts and retreive the values associated
146145
with fact paths.
147146
148-
:param \*\*kwargs: The rest of the keyword arguments are passed
147+
:param **kwargs: The rest of the keyword arguments are passed
149148
to the _query function.
150149
151150
:returns: A list of dictionaries containg the results.
@@ -159,7 +158,7 @@ def fact_paths(self, **kwargs):
159158
facts and may be used for building GUI autocompletions or other
160159
applications that require a basic top-level view of fact paths.
161160
162-
:param \*\*kwargs: The rest of the keyword arguments are passed
161+
:param **kwargs: The rest of the keyword arguments are passed
163162
to the _query function.
164163
165164
:returns: A list of dictionaries containg the results.
@@ -179,7 +178,7 @@ def resources(self, type_=None, title=None, **kwargs):
179178
'namevar' in the Puppet Manifests. This parameter requires the\
180179
`type_` parameter be set.
181180
:type title: :obj:`string`
182-
:param \*\*kwargs: The rest of the keyword arguments are passed
181+
:param **kwargs: The rest of the keyword arguments are passed
183182
to the _query function
184183
185184
:returns: A generator yielding Resources
@@ -218,7 +217,7 @@ def catalogs(self, **kwargs):
218217
and/or paging parameters for this endpoint to prevent large result
219218
sets or PuppetDB performance bottlenecks.
220219
221-
:param \*\*kwargs: The rest of the keyword arguments are passed
220+
:param **kwargs: The rest of the keyword arguments are passed
222221
to the _query function.
223222
224223
:returns: A generator yielding Catalogs
@@ -240,7 +239,7 @@ def events(self, **kwargs):
240239
endpoint to prevent large result sets or PuppetDB performance
241240
bottlenecks.
242241
243-
:param \*\*kwargs: The rest of the keyword arguments are passed
242+
:param **kwargs: The rest of the keyword arguments are passed
244243
to the _query function
245244
246245
:returns: A generator yielding Events
@@ -268,7 +267,7 @@ def event_counts(self, summarize_by, **kwargs):
268267
`<`, `>=`, and `<=`. Supported fields are
269268
`failures`, `successes`, `noops`, and `skips`.
270269
:type count_filter: :obj:`string`
271-
:param \*\*kwargs: The rest of the keyword arguments are passed
270+
:param **kwargs: The rest of the keyword arguments are passed
272271
to the _query function.
273272
274273
:returns: A list of dictionaries containing the results.
@@ -319,7 +318,7 @@ def reports(self, **kwargs):
319318
prevent large result sets and potential PuppetDB performance
320319
bottlenecks.
321320
322-
:param \*\*kwargs: The rest of the keyword arguments are passed
321+
:param **kwargs: The rest of the keyword arguments are passed
323322
to the _query function
324323
325324
:returns: A generating yielding Reports
@@ -334,7 +333,7 @@ def inventory(self, **kwargs):
334333
for structured facts instead of using the facts, fact-contents and
335334
factsets endpoints for many fact-related queries.
336335
337-
:param \*\*kwargs: The rest of the keyword arguments are passed
336+
:param **kwargs: The rest of the keyword arguments are passed
338337
to the _query function.
339338
340339
:returns: A generator yielding Inventory

Diff for: pypuppetdb/types.py

+22-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from datetime import timedelta
66

7-
from pypuppetdb.QueryBuilder import (EqualsOperator)
7+
from pypuppetdb.QueryBuilder import (EqualsOperator, AndOperator)
88
from pypuppetdb.utils import json_to_datetime
99

1010
log = logging.getLogger(__name__)
@@ -20,22 +20,22 @@ class Event(object):
2020
:type status: :obj:`string`
2121
:param timestamp: A timestamp of when this event occured.
2222
:type timestamp: :obj:`string` formatted as ``%Y-%m-%dT%H:%M:%S.%fZ``
23-
:param hash\_: The hash of the report that contains this event.
24-
:type hash\_: :obj:`string`
23+
:param hash_: The hash of the report that contains this event.
24+
:type hash_: :obj:`string`
2525
:param title: The resource title this event was fired for.
2626
:type title: :obj:`string`
27-
:param property\_: The property of the resource this event was fired for.
28-
:type property\_: :obj:`string`
27+
:param property_: The property of the resource this event was fired for.
28+
:type property_: :obj:`string`
2929
:param message: A message associated with this event.
3030
:type message: :obj:`string`
3131
:param new_value: The new value/state of the resource.
3232
:type new_value: :obj:`string`
3333
:param old_value: The old value/state of the resource.
3434
:type old_value: :obj:`string`
35-
:param type\_: The type of the resource this event fired for.
36-
:type type\_: :obj:`string`
37-
:param class\_: The class responsible for running this event.
38-
:type class\_: :obj:`string`
35+
:param type_: The type of the resource this event fired for.
36+
:type type_: :obj:`string`
37+
:param class_: The class responsible for running this event.
38+
:type class_: :obj:`string`
3939
:param execution_path: The path used to reach this particular resource.
4040
:type execution_path: :obj:`string`
4141
:param source_file: The puppet source code file containing the class.
@@ -50,7 +50,7 @@ class Event(object):
5050
:ivar timestamp: A :obj:`datetime.datetime` of when this event happend.
5151
:ivar node: The hostname of the machine this event\
5252
occured on.
53-
:ivar hash\_: The hash of this event.
53+
:ivar hash_: The hash of this event.
5454
:ivar item: :obj:`dict` with information about the item/resource this\
5555
event was triggered for.
5656
"""
@@ -109,8 +109,8 @@ class Report(object):
109109
:type api: :class:`pypuppetdb.api.BaseAPI`
110110
:param node: The hostname of the node this report originated on.
111111
:type node: :obj:`string`
112-
:param hash\_: A string uniquely identifying this report.
113-
:type hash\_: :obj:`string`
112+
:param hash_: A string uniquely identifying this report.
113+
:type hash_: :obj:`string`
114114
:param start: The start time of the agent run.
115115
:type start: :obj:`string` formatted as ``%Y-%m-%dT%H:%M:%S.%fZ``
116116
:param end: The time the agent finished its run.
@@ -119,8 +119,8 @@ class Report(object):
119119
:type received: :obj:`string` formatted as ``%Y-%m-%dT%H:%M:%S.%fZ``
120120
:param version: The catalog / configuration version.
121121
:type version: :obj:`string`
122-
:param format\_: The catalog format version.
123-
:type format\_: :obj:`int`
122+
:param format_: The catalog format version.
123+
:type format_: :obj:`int`
124124
:param agent_version: The Puppet agent version.
125125
:type agent_version: :obj:`string`
126126
:param transaction: The UUID of this transaction.
@@ -156,13 +156,12 @@ class Report(object):
156156
:type producer: :obj:`string`
157157
158158
:ivar node: The hostname this report originated from.
159-
:ivar hash\_: Unique identifier of this report.
159+
:ivar hash_: Unique identifier of this report.
160160
:ivar start: :obj:`datetime.datetime` when the Puppet agent run started.
161161
:ivar end: :obj:`datetime.datetime` when the Puppet agent run ended.
162-
:ivar received: :obj:`datetime.datetime` when the report finished\
163-
uploading.
162+
:ivar received: :obj:`datetime.datetime` when the report finished uploading.
164163
:ivar version: :obj:`string` catalog configuration version.
165-
:ivar format\_: :obj:`int` catalog format version.
164+
:ivar format_: :obj:`int` catalog format version.
166165
:ivar agent_version: :obj:`string` Puppet Agent version.
167166
:ivar run_time: :obj:`datetime.timedelta` of **end** - **start**.
168167
:ivar transaction: UUID identifying this transaction.
@@ -299,11 +298,11 @@ class Resource(object):
299298
parameters are required.
300299
301300
:param node: The hostname this resource is located on.
302-
:type noode: :obj:`string`
301+
:type node: :obj:`string`
303302
:param name: The name of the resource in the Puppet manifest.
304303
:type name: :obj:`string`
305-
:param type\_: Type of the Puppet resource.
306-
:type type\_: :obj:`string`
304+
:param type_: Type of the Puppet resource.
305+
:type type_: :obj:`string`
307306
:param tags: Tags associated with this resource.
308307
:type tags: :obj:`list`
309308
:param exported: If it's an exported resource.
@@ -321,7 +320,7 @@ class Resource(object):
321320
322321
:ivar node: The hostname this resources is located on.
323322
:ivar name: The name of the resource in the Puppet manifest.
324-
:ivar type\_: The type of Puppet resource.
323+
:ivar type_: The type of Puppet resource.
325324
:ivar exported: :obj:`bool` if the resource is exported.
326325
:ivar sourcefile: The Puppet manifest this resource is declared in.
327326
:ivar sourceline: The line this resource is declared at.
@@ -420,7 +419,7 @@ class Node(object):
420419
:param cached_catalog_status: Cached catalog status of the last puppet run\
421420
on this node, possible values are 'explicitly_requested',\
422421
'on_failure', 'not_used' or None.
423-
:type cache_catalog_status: :obj:`string`
422+
:type cached_catalog_status: :obj:`string`
424423
425424
:ivar name: Hostname of this node.
426425
:ivar deactivated: :obj:`datetime.datetime` when this host was\

Diff for: tests/test_api_base_init.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_defaults(self, api):
4444
assert api.protocol == 'http'
4545
assert api.url_path == ''
4646
assert api.session.auth is None
47-
assert api.metric_api_version is 'v2'
47+
assert api.metric_api_version == 'v2'
4848

4949
def test_host(self):
5050
api = pypuppetdb.api.API(host='127.0.0.1')
@@ -102,7 +102,7 @@ def test_override_protocol(self):
102102

103103
def test_invalid_protocol(self):
104104
with pytest.raises(ValueError):
105-
api = pypuppetdb.api.API(protocol='ftp')
105+
pypuppetdb.api.API(protocol='ftp')
106106

107107
def test_url_path(self):
108108
api = pypuppetdb.api.API(url_path='puppetdb')

Diff for: tests/test_querybuilder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def test_init_from(self):
515515
str(fr) == "unimportant_no_query"
516516

517517
with pytest.raises(APIError):
518-
fr2 = FromOperator('invalid_entity')
518+
FromOperator('invalid_entity')
519519

520520
def test_add_query(self):
521521
fr = FromOperator("facts")

Diff for: tests/test_types.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_with_status_unreported(self):
4242
assert node.catalog_timestamp == \
4343
json_to_datetime('2013-08-01T09:57:00.000Z')
4444
assert node.status == 'unreported'
45-
assert node.unreported_time is '0d 5h 20m'
45+
assert node.unreported_time == '0d 5h 20m'
4646
assert str(node) == str('node')
4747
assert str(node) == str('node')
4848
assert repr(node) == str('<Node: node>')
@@ -66,7 +66,7 @@ def test_with_status_unreported_from_noop(self):
6666
assert node.catalog_timestamp == \
6767
json_to_datetime('2013-08-01T09:57:00.000Z')
6868
assert node.status == 'unreported'
69-
assert node.unreported_time is '0d 5h 20m'
69+
assert node.unreported_time == '0d 5h 20m'
7070
assert str(node) == str('node')
7171
assert str(node) == str('node')
7272
assert repr(node) == str('<Node: node>')
@@ -90,7 +90,7 @@ def test_with_status_unreported_from_failed(self):
9090
assert node.catalog_timestamp == \
9191
json_to_datetime('2013-08-01T09:57:00.000Z')
9292
assert node.status == 'unreported'
93-
assert node.unreported_time is '0d 5h 20m'
93+
assert node.unreported_time == '0d 5h 20m'
9494
assert str(node) == str('node')
9595
assert str(node) == str('node')
9696
assert repr(node) == str('<Node: node>')

0 commit comments

Comments
 (0)