8000 Upgrade pylint (#3194) · ansible/molecule@646cd29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 646cd29

Browse files
authored
Upgrade pylint (#3194)
Prepares for bumping pylint by fixing some errors reported by newer version.
1 parent 142a52c commit 646cd29

File tree

11 files changed

+58
-46
lines changed

11 files changed

+58
-46
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ repos:
5959
- enrich>=1.2.5
6060
- subprocess-tee>=0.2.0
6161
- repo: https://github.com/PyCQA/pylint
62-
rev: pylint-2.7.2
62+
rev: v2.9.3
6363
hooks:
6464
- id: pylint
6565
additional_dependencies:

src/molecule/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def __getitem__(self, i):
3131
def get(self, key, default):
3232
return self.__dict__.get(key, default)
3333

34-
def append(self, element) -> None:
35-
self.__dict__[str(element)] = element
36-
super(UserListMap, self).append(element)
34+
def append(self, item) -> None:
35+
self.__dict__[str(item)] = item
36+
super(UserListMap, self).append(item)
3737

3838

3939
@lru_cache()

src/molecule/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ def _combine(self, env=os.environ, keep_string=None) -> MutableMapping:
282282
environment variables.
283283
284284
1. Loads Molecule defaults.
285-
2. Loads a base config (if provided) and merges ontop of defaults.
286-
3. Loads the scenario's ``molecule file`` and merges ontop of previous
285+
2. Loads a base config (if provided) and merges on top of defaults.
286+
3. Loads the scenario's ``molecule file`` and merges on top of previous
287287
merge.
288288
289289
:return: dict

src/molecule/dependency/ansible_galaxy/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ def __init__(self, config):
4444

4545
self.command = "ansible-galaxy"
4646

47-
@abc.abstractproperty
47+
@property
48+
@abc.abstractmethod
4849
def install_path(self): # noqa cover
4950
pass
5051

51-
@abc.abstractproperty
52+
@property
53+
@abc.abstractmethod
5254
def requirements_file(self): # noqa cover
5355
pass
5456

src/molecule/dependency/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def execute(self): # pragma: no cover
8989
:return: None
9090
"""
9191

92-
@abc.abstractproperty
92+
@property
93+
@abc.abstractmethod
9394
def default_options(self): # pragma: no cover
9495
"""
9596
Get default CLI arguments provided to ``cmd`` as a dict.

src/molecule/driver/base.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# DEALINGS IN THE SOFTWARE.
2020
"""Base Driver Module."""
2121

22-
import abc
2322
import inspect
2423
import os
24+
from abc import ABCMeta, abstractmethod
2525

2626
import pkg_resources
2727

@@ -32,7 +32,7 @@
3232
class Driver(object):
3333
"""Driver Class."""
3434

35-
__metaclass__ = abc.ABCMeta
35+
__metaclass__ = ABCMeta
3636

3737
def __init__(self, config=None):
3838
"""
@@ -43,20 +43,19 @@ def __init__(self, config=None):
4343
"""
4444
self._config = config
4545
self._path = os.path.abspath(os.path.dirname(inspect.getfile(self.__class__)))
46-
self.module = self.__module__.split(".")[0]
46+
self.module = self.__module__.split(".", maxsplit=1)[0]
4747
self.version = pkg_resources.get_distribution(self.module).version
4848

49-
@property # type: ignore
50-
@abc.abstractmethod
51-
def name(self): # pragma: no cover
49+
@property
50+
@abstractmethod
51+
def name(self) -> str: # pragma: no cover
5252
"""
5353
Name of the driver and returns a string.
5454
5555
:returns: str
5656
"""
5757

5858
@name.setter # type: ignore
59-
@abc.abstractmethod
6059
def name(self, value): # pragma: no cover
6160
"""
6261
Driver name setter and returns None.
@@ -76,7 +75,8 @@ def testinfra_options(self):
7675
"ansible-inventory": self._config.provisioner.inventory_directory,
7776
}
7877

79-
@abc.abstractproperty
78+
@property
79+
@abstractmethod
8080
def login_cmd_template(self): # pragma: no cover
8181
"""
8282
Get the login command template to be populated by ``login_options`` as \
@@ -85,23 +85,25 @@ def login_cmd_template(self): # pragma: no cover
8585
:returns: str
8686
"""
8787

88-
@abc.abstractproperty
88+
@property
89+
@abstractmethod
8990
def default_ssh_connection_options(self): # pragma: no cover
9091
"""
9192
SSH client options and returns a list.
9293
9394
:returns: list
9495
"""
9596

96-
@abc.abstractproperty
97+
@property
98+
@abstractmethod
9799
def default_safe_files(self): # pragma: no cover
98100
"""
99101
Generate files to be preserved.
100102
101103
:returns: list
102104
"""
103105

104-
@abc.abstractmethod
106+
@abstractmethod
105107
def login_options(self, instance_name): # pragma: no cover
106108
"""
107109
Options used in the login command and returns a dict.
@@ -110,7 +112,7 @@ def login_options(self, instance_name): # pragma: no cover
110112
:returns: dict
111113
"""
112114

113-
@abc.abstractmethod
115+
@abstractmethod
114116
def ansible_connection_options(self, instance_name): # pragma: no cover
115117
"""
116118
Ansible specific connection options supplied to inventory and returns a \
@@ -120,7 +122,7 @@ def ansible_connection_options(self, instance_name): # pragma: no cover
120122
:returns: dict
121123
"""
122124

123-
@abc.abstractmethod
125+
@abstractmethod
124126
def sanity_checks(self):
125127
"""
126128
Confirm that driver is usable.

src/molecule/lint/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ def __init__(self, config):
3838
"""
3939
self._config = config
4040

41-
@abc.abstractproperty
41+
@property
42+
@abc.abstractmethod
4243
def default_options(self): # pragma: no cover
4344
"""
4445
Provide Default CLI arguments to ``cmd`` and returns a dict.
4546
4647
:return: dict
4748
"""
4849

49-
@abc.abstractproperty
50+
@property
51+
@abc.abstractmethod
5052
def default_env(self): # pragma: no cover
5153
"""
5254
Provide default env variables to ``cmd`` and returns a dict.

src/molecule/provisioner/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ def __init__(self, config):
3636
"""
3737
self._config = config
3838

39-
@abc.abstractproperty
39+
@property
40+
@abc.abstractmethod
4041
def default_options(self): # pragma: no cover
4142
"""
4243
Get default CLI arguments provided to ``cmd`` as a dict.
4344
4445
:return: dict
4546
"""
4647

47-
@abc.abstractproperty
48+
@property
49+
@abc.abstractmethod
4850
def default_env(self): # pragma: no cover
4951
"""
5052
Get default env variables provided to ``cmd`` as a dict.

src/molecule/scenario.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,22 @@ def ephemeral_directory(self):
166166
path = ephemeral_directory(project_scenario_directory)
167167

168168
if os.environ.get("MOLECULE_PARALLEL", False) and not self._lock:
169-
self._lock = open(os.path.join(path, ".lock"), "w")
170-
for i in range(1, 5):
171-
try:
172-
fcntl.lockf(self._lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
173-
break
174-
except OSError:
175-
delay = 30 * i
176-
LOG.warning(
177-
"Retrying to acquire lock on %s, waiting for %s seconds",
178-
path,
179-
delay,
180-
)
181-
sleep(delay)
182-
else:
183-
LOG.warning("Timedout trying to acquire lock on %s", path)
184-
raise SystemExit(RC_TIMEOUT)
169+
with open(os.path.join(path, ".lock"), "w") as self._lock:
170+
for i in range(1, 5):
171+
try:
172+
fcntl.lockf(self._lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
173+
break
174+
except OSError:
175+
delay = 30 * i
176+
LOG.warning(
177+
"Retrying to acquire lock on %s, waiting for %s seconds",
178+
path,
179+
delay,
180+
)
181+
sleep(delay)
182+
else:
183+
LOG.warning("Timedout trying to acquire lock on %s", path)
184+
raise SystemExit(RC_TIMEOUT)
185185

186186
return path
187187

src/molecule/test/unit/provisioner/test_ansible.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def test_link_vars(_instance):
621621
source_host_vars = os.path.join(scenario_dir, os.path.pardir, "host_vars")
622622
target_host_vars = os.path.join(inventory_dir, "host_vars")
623623

624-
open(source_hosts, "w").close()
624+
open(source_hosts, "w").close() # pylint: disable=consider-using-with
625625
os.mkdir(source_group_vars)
626626
os.mkdir(source_host_vars)
627627

0 commit comments

Comments
 (0)
0