8000 Merge pull request #1729 from python-gitlab/jlvillal/pylint · python-gitlab/python-gitlab@3a7d6f6 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a7d6f6

Browse files
authored
Merge pull request #1729 from python-gitlab/jlvillal/pylint
chore: add initial pylint check
2 parents 1c33080 + b67a6ad commit 3a7d6f6

File tree

8 files changed

+130
-21
lines changed

8 files changed

+130
-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

.github/workflows/pre_commit.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: pre_commit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
.github/workflows/pre_commit.yml
9+
.pre-commit-config.yaml
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
paths:
15+
- .github/workflows/pre_commit.yml
16+
- .pre-commit-config.yaml
17+
18+
env:
19+
PY_COLORS: 1
20+
21+
jobs:
22+
23+
pre_commit:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- uses: actions/setup-python@v2
28+
- run: pip install --upgrade -r requirements.txt -r requirements-lint.txt pre-commit
29+
- name: Run pre-commit install
30+
run: pre-commit install
31+
- name: pre-commit run all-files
32+
run: pre-commit run --all-files

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@ repos:
2020
rev: 5.9.3
2121
hooks:
2222
- id: isort
23+
- repo: https://github.com/pycqa/pylint
24+
rev: v2.12.2
25+
hooks:
26+
- id: pylint
27+
additional_dependencies:
28+
- argcomplete==1.12.3
29+
- requests==2.26.0
30+
- requests-toolbelt==0.9.1
31+
files: 'gitlab/'
2332
- repo: https://github.com/pre-commit/mirrors-mypy
2433
rev: v0.910
2534
hooks:
2635
- id: mypy
36+
args: []
2737
additional_dependencies:
2838
- types-PyYAML==6.0.1
2939
- types-requests==2.26.1

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< 6DB6 code class="diff-text syntax-highlighted-line">
)
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 10000 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
@@ -41,3 +41,50 @@ branch = "main"
4141
version_variable = "gitlab/__version__.py:__version__"
4242
commit_subject = "chore: release v{version}"
4343
commit_message = ""
44+
45+
[tool.pylint.messages_control]
46+
max-line-length = 88
47+
# TODO(jlvilla): Work on removing these disables over time.
48+
disable = [
49+
"arguments-differ",
50+
"arguments-renamed",
51+
"attribute-defined-outside-init",
52+
"broad-except",
53+
"consider-using-f-string",
54+
"consider-using-generator",
55+
"consider-using-sys-exit",
56+
"cyclic-import",
57+
"duplicate-code",
58+
"expression-not-assigned",
59+
"fixme",
60+
"implicit-str-concat",
61+
"import-outside-toplevel",
62+
"invalid-name",
63+
"missing-class-docstring",
64+
"missing-function-docstring",
65+
"missing-module-docstring",
66+
"no-else-return",
67+
"no-self-use",
68+
"protected-access",
69+
"raise-missing-from",
70+
"redefined-builtin",
71+
"redefined-outer-name",
72+
"signature-differs",
73+
"super-with-arguments",
74+
"too-few-public-methods",
75+
"too-many-ancestors",
76+
"too-many-arguments",
77+
"too-many-branches",
78+
"too-many-instance-attributes",
79+
"too-many-lines",
80+
"too-many-locals",
81+
"too-many-statements",
82+
"unexpected-keyword-arg",
83+
"unnecessary-pass",
84+
"unspecified-encoding",
85+
"unsubscriptable-object",
86+
"unused-argument",
87+
"useless-import-alias",
88+
"useless-object-inheritance",
89+
90+
]

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.12b0
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)
0