Skip to content

Commit ddc24be

Browse files
chore: add initial pylint check
Initial pylint check is added. A LONG list of disabled checks is also added. In the future we should work through the list and resolve the errors or disable them on a more granular level.
1 parent 2708f91 commit ddc24be

File tree

6 files changed

+88
-21
lines changed

6 files changed

+88
-21
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ jobs:
3535
run: tox -e mypy
3636
- name: Run isort import order checker (https://pycqa.github.io/isort/)
3737
run: tox -e isort -- --check
38+
- name: Run pylint Python code static checker (https://www.pylint.org/)
39+
run: tox -e pylint

gitlab/v4/objects/merge_request_approvals.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def set_approvers(
140140
approval_rules: ProjectMergeRequestApprovalRuleManager = (
141141
self._parent.approval_rules
142142
)
143-
""" update any existing approval rule matching the name"""
143+
# update any existing approval rule matching the name
144144
existing_approval_rules = approval_rules.list()
145145
for ar in existing_approval_rules:
146146
if ar.name == approval_rule_name:
@@ -149,7 +149,7 @@ def set_approvers(
149149
ar.group_ids = data["group_ids"]
150150
ar.save()
151151
return ar
152-
""" if there was no rule matching the rule name, create a new one"""
152+
# if there was no rule matching the rule name, create a new one
153153
return approval_rules.create(data=data)
154154

155155

@@ -171,13 +171,13 @@ def save(self, **kwargs: Any) -> None:
171171
GitlabAuthenticationError: If authentication is not correct
172172
GitlabUpdateError: If the server cannot perform the request
173173
"""
174-
# There is a mismatch between the name of our id attribute and the put REST API name for the
175-
# project_id, so we override it here.
174+
# There is a mismatch between the name of our id attribute and the put
175+
# REST API name for the project_id, so we override it here.
176176
self.approval_rule_id = self.id
177177
self.merge_request_iid = self._parent_attrs["mr_iid"]
178178
self.id = self._parent_attrs["project_id"]
179-
# save will update self.id with the result from the server, so no need to overwrite with
180-
# what it was before we overwrote it."""
179+
# save will update self.id with the result from the server, so no need
180+
# to overwrite with what it was before we overwrote it.
181181
SaveMixin.save(self, **kwargs)
182182

183183

@@ -198,8 +198,9 @@ class ProjectMergeRequestApprovalRuleManager(
198198
),
199199
optional=("user_ids", "group_ids"),
200200
)
201-
# Important: When approval_project_rule_id is set, the name, users and groups of
202-
# project-level rule will be copied. The approvals_required specified will be used. """
201+
# Important: When approval_project_rule_id is set, the name, users and
202+
# groups of project-level rule will be copied. The approvals_required
203+
# specified will be used.
203204
_create_attrs = RequiredOptional(
204205
required=("id", "merge_request_iid", "name", "approvals_required"),
205206
optional=("approval_project_rule_id", "user_ids", "group_ids"),

gitlab/v4/objects/projects.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,12 @@ def artifact(
597597
chunk_size: int = 1024,
598598
**kwargs: Any,
599599
) -> Optional[bytes]:
600-
"""Download a single artifact file from a specific tag or branch from within the job’s artifacts archive.
600+
"""Download a single artifact file from a specific tag or branch from
601+
within the job’s artifacts archive.
601602
602603
Args:
603-
ref_name: Branch or tag name in repository. HEAD or SHA references are not supported.
604+
ref_name: Branch or tag name in repository. HEAD or SHA references
605+
are not supported.
604606
artifact_path: Path to a file inside the artifacts archive.
605607
job: The name of the job.
606608
streamed: If True the data will be processed by chunks of
@@ -619,7 +621,10 @@ def artifact(
619621
The artifacts if `streamed` is False, None otherwise.
620622
"""
621623

622-
path = f"/projects/{self.get_id()}/jobs/artifacts/{ref_name}/raw/{artifact_path}?job={job}"
624+
path = (
625+
f"/projects/{self.get_id()}/jobs/artifacts/{ref_name}/raw/"
626+
f"{artifact_path}?job={job}"
627+
)
623628
result = self.manager.gitlab.http_get(
624629
path, streamed=streamed, raw=True, **kwargs
625630
)
@@ -857,7 +862,8 @@ def import_bitbucket_server(
857862
858863
.. note::
859864
This request may take longer than most other API requests.
860-
So this method will specify a 60 second default timeout if none is specified.
865+
So this method will specify a 60 second default timeout if none is
866+
specified.
861867
A timeout can be specified via kwargs to override this functionality.
862868
863869
Args:
@@ -945,7 +951,8 @@ def import_github(
945951
946952
.. note::
947953
This request may take longer than most other API requests.
948-
So this method will specify a 60 second default timeout if none is specified.
954+
So this method will specify a 60 second default timeout if none is
955+
specified.
949956
A timeout can be specified via kwargs to override this functionality.
950957
951958
Args:

pyproject.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,50 @@ branch = "main"
2525
version_variable = "gitlab/__version__.py:__version__"
2626
commit_subject = "chore: release v{version}"
2727
commit_message = ""
28+
29+
[tool.pylint.messages_control]
30+
max-line-length = 88
31+
# TODO(jlvilla): Work on removing these disables over time.
32+
disable = [
33+
"arguments-differ",
34+
"arguments-renamed",
35+
"attribute-defined-outside-init",
36+
"broad-except",
37+
"consider-using-f-string",
38+
"consider-using-generator",
39+
"consider-using-sys-exit",
40+
"cyclic-import",
41+
"duplicate-code",
42+
"expression-not-assigned",
43+
"fixme",
44+
"implicit-str-concat",
45+
"import-outside-toplevel",
46+
"invalid-name",
47+
"missing-class-docstring",
48+
"missing-function-docstring",
49+
"missing-module-docstring",
50+
"no-else-return",
51+
"no-self-use",
52+
"protected-access",
53+
"raise-missing-from",
54+
"redefined-builtin",
55+
"redefined-outer-name",
56+
"signature-differs",
57+
"super-with-arguments",
58+
"too-few-public-methods",
59+
"too-many-ancestors",
60+
"too-many-arguments",
61+
"too-many-branches",
62+
"too-many-instance-attributes",
63+
"too-many-lines",
64+
"too-many-locals",
65+
"too-many-statements",
66+
"unexpected-keyword-arg",
67+
"unnecessary-pass",
68+
"unspecified-encoding",
69+
"unsubscriptable-object",
70+
"unused-argument",
71+
"useless-import-alias",
72+
"useless-object-inheritance",
73+
74+
]

requirements-lint.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
argcomplete==1.12.3
12
black==21.11b1
23
flake8==4.0.1
34
isort==5.10.1
45
mypy==0.910
5-
pytest
6+
pylint==2.12.2
7+
pytest==6.2.5
68
types-PyYAML==6.0.1
79
types-requests==2.26.1
810
types-setuptools==57.4.4

tox.ini

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ setenv = VIRTUAL_ENV={envdir}
99
whitelist_externals = true
1010
usedevelop = True
1111
install_command = pip install {opts} {packages}
12+
isolated_build = True
1213

1314
deps = -r{toxinidir}/requirements.txt
1415
-r{toxinidir}/requirements-test.txt
1516
commands =
1617
pytest tests/unit tests/meta {posargs}
1718

18-
[testenv:pep8]
19-
basepython = python3
20-
envdir={toxworkdir}/lint
21-
deps = -r{toxinidir}/requirements-lint.txt
22-
commands =
23-
flake8 {posargs} .
24-
2519
[testenv:black]
2620
basepython = python3
2721
envdir={toxworkdir}/lint
@@ -43,6 +37,20 @@ deps = -r{toxinidir}/requirements-lint.txt
4337
commands =
4438
mypy {posargs}
4539

40+
[testenv:pep8]
41+
basepython = python3
42+
envdir={toxworkdir}/lint
43+
deps = -r{toxinidir}/requirements-lint.txt
44+
commands =
45+
flake8 {posargs} .
46+
47+
[testenv:pylint]
48+
basepython = python3
49+
envdir={toxworkdir}/lint
50+
deps = -r{toxinidir}/requirements-lint.txt
51+
commands =
52+
pylint {posargs} gitlab/
53+
4654
[testenv:twine-check]
4755
basepython = python3
4856
deps = -r{toxinidir}/requirements.txt

0 commit comments

Comments
 (0)