Skip to content

Fix all issues reported by running: tox -e pep8 and enable pep8 as a linter check #1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ env:
PY_COLORS: 1

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@stable
with:
black_args: ". --check"
commitlint:
runs-on: ubuntu-latest
steps:
Expand All @@ -28,10 +20,15 @@ jobs:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v3

mypy:
linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install --upgrade tox
- run: tox -e mypy
- name: Run black code formatter (https://black.readthedocs.io/en/stable/)
run: tox -e black -- --check
- name: Run flake8 (https://flake8.pycqa.org/en/latest/)
run: tox -e pep8
- name: Run mypy static typing checker (http://mypy-lang.org/)
run: tox -e mypy
10 changes: 5 additions & 5 deletions gitlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

import warnings

import gitlab.config
from gitlab.__version__ import (
import gitlab.config # noqa: F401
from gitlab.__version__ import ( # noqa: F401
__author__,
__copyright__,
__email__,
__license__,
__title__,
__version__,
)
from gitlab.client import Gitlab, GitlabList
from gitlab.const import * # noqa
from gitlab.exceptions import * # noqa
from gitlab.client import Gitlab, GitlabList # noqa: F401
from gitlab.const import * # noqa: F401,F403
from gitlab.exceptions import * # noqa: F401,F403


warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab")
3 changes: 1 addition & 2 deletions gitlab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import sys
from typing import Any, Callable, Dict, Optional, Tuple, Union

import gitlab.config
import gitlab.config # noqa: F401

camel_re = re.compile("(.)([A-Z])")

Expand Down Expand Up @@ -162,7 +162,6 @@ def docs() -> argparse.ArgumentParser:
if "sphinx" not in sys.modules:
sys.exit("Docs parser is only intended for build_sphinx")

parser = _get_base_parser(add_help=False)
# NOTE: We must delay import of gitlab.v4.cli until now or
# otherwise it will cause circular import errors
import gitlab.v4.cli
Expand Down
1 change: 0 additions & 1 deletion gitlab/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Dict,
List,
Optional,
Tuple,
Type,
TYPE_CHECKING,
Union,
Expand Down
8 changes: 4 additions & 4 deletions gitlab/tests/mixins/test_mixin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def resp_cont(url, request):


def test_refresh_mixin(gl):
class O(RefreshMixin, FakeObject):
class TestClass(RefreshMixin, FakeObject):
pass

@urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests/42", method="get")
Expand All @@ -55,7 +55,7 @@ def resp_cont(url, request):

with HTTMock(resp_cont):
mgr = FakeManager(gl)
obj = O(mgr, {"id": 42})
obj = TestClass(mgr, {"id": 42})
res = obj.refresh()
assert res is None
assert obj.foo == "bar"
Expand Down Expand Up @@ -265,7 +265,7 @@ def test_save_mixin(gl):
class M(UpdateMixin, FakeManager):
pass

class O(SaveMixin, base.RESTObject):
class TestClass(SaveMixin, base.RESTObject):
pass

@urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests/42", method="put")
Expand All @@ -276,7 +276,7 @@ def resp_cont(url, request):

with HTTMock(resp_cont):
mgr = M(gl)
obj = O(mgr, {"id": 42, "foo": "bar"})
obj = TestClass(mgr, {"id": 42, "foo": "bar"})
obj.foo = "baz"
obj.save()
assert obj._attrs["foo"] == "baz"
Expand Down
24 changes: 12 additions & 12 deletions gitlab/tests/mixins/test_object_mixins_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@


def test_access_request_mixin():
class O(AccessRequestMixin):
class TestClass(AccessRequestMixin):
pass

obj = O()
obj = TestClass()
assert hasattr(obj, "approve")


def test_subscribable_mixin():
class O(SubscribableMixin):
class TestClass(SubscribableMixin):
pass

obj = O()
obj = TestClass()
assert hasattr(obj, "subscribe")
assert hasattr(obj, "unsubscribe")


def test_todo_mixin():
class O(TodoMixin):
class TestClass(TodoMixin):
pass

obj = O()
obj = TestClass()
assert hasattr(obj, "todo")


def test_time_tracking_mixin():
class O(TimeTrackingMixin):
class TestClass(TimeTrackingMixin):
pass

obj = O()
obj = TestClass()
assert hasattr(obj, "time_stats")
assert hasattr(obj, "time_estimate")
assert hasattr(obj, "reset_time_estimate")
Expand All @@ -64,16 +64,16 @@ class O(TimeTrackingMixin):


def test_set_mixin():
class O(SetMixin):
class TestClass(SetMixin):
pass

obj = O()
obj = TestClass()
assert hasattr(obj, "set")


def test_user_agent_detail_mixin():
class O(UserAgentDetailMixin):
class TestClass(UserAgentDetailMixin):
pass

obj = O()
obj = TestClass()
assert hasattr(obj, "user_agent_detail")
2 changes: 1 addition & 1 deletion gitlab/tests/objects/test_appearance.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ def test_get_update_appearance(gl, resp_application_appearance):


def test_update_appearance(gl, resp_application_appearance):
resp = gl.appearance.update(title=new_title, description=new_description)
gl.appearance.update(title=new_title, description=new_description)
4 changes: 1 addition & 3 deletions gitlab/tests/objects/test_bridges.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
GitLab API: https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-bridges
"""
import re

import pytest
import responses

from gitlab.v4.objects import Project, ProjectPipelineBridge
from gitlab.v4.objects import ProjectPipelineBridge


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions gitlab/tests/objects/test_project_merge_request_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def test_project_approval_manager_update_uses_post(project, resp_snippet):
assert isinstance(
approvals, gitlab.v4.objects.merge_request_approvals.ProjectApprovalManager
)
assert approvals._update_uses_post == True
assert approvals._update_uses_post is True


def test_list_merge_request_approval_rules(project, resp_snippet):
Expand All @@ -257,7 +257,7 @@ def test_update_merge_request_approvals_set_approvers(project, resp_snippet):
approvals,
gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestApprovalManager,
)
assert approvals._update_uses_post == True
assert approvals._update_uses_post is True
response = approvals.set_approvers(
updated_approval_rule_approvals_required,
approver_ids=updated_approval_rule_user_ids,
Expand All @@ -277,7 +277,7 @@ def test_create_merge_request_approvals_set_approvers(project, resp_snippet):
approvals,
gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestApprovalManager,
)
assert approvals._update_uses_post == True
assert approvals._update_uses_post is True
response = approvals.set_approvers(
new_approval_rule_approvals_required,
approver_ids=new_approval_rule_user_ids,
Expand Down
14 changes: 7 additions & 7 deletions gitlab/tests/objects/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,31 @@ def resp_runner_verify():

def test_owned_runners_list(gl: gitlab.Gitlab, resp_get_runners_list):
runners = gl.runners.list()
assert runners[0].active == True
assert runners[0].active is True
assert runners[0].id == 6
assert runners[0].name == "test-name"
assert len(runners) == 1


def test_project_runners_list(gl: gitlab.Gitlab, resp_get_runners_list):
runners = gl.projects.get(1, lazy=True).runners.list()
assert runners[0].active == True
assert runners[0].active is True
assert runners[0].id == 6
assert runners[0].name == "test-name"
assert len(runners) == 1


def test_group_runners_list(gl: gitlab.Gitlab, resp_get_runners_list):
runners = gl.groups.get(1, lazy=True).runners.list()
assert runners[0].active == True
assert runners[0].active is True
assert runners[0].id == 6
assert runners[0].name == "test-name"
assert len(runners) == 1


def test_all_runners_list(gl: gitlab.Gitlab, resp_get_runners_list):
runners = gl.runners.all()
assert runners[0].active == True
assert runners[0].active is True
assert runners[0].id == 6
assert runners[0].name == "test-name"
assert len(runners) == 1
Expand All @@ -238,7 +238,7 @@ def test_create_runner(gl: gitlab.Gitlab, resp_runner_register):

def test_get_update_runner(gl: gitlab.Gitlab, resp_runner_detail):
runner = gl.runners.get(6)
assert runner.active == True
assert runner.active is True
runner.tag_list.append("new")
runner.save()

Expand All @@ -259,14 +259,14 @@ def test_disable_group_runner(gl: gitlab.Gitlab, resp_runner_disable):

def test_enable_project_runner(gl: gitlab.Gitlab, resp_runner_enable):
runner = gl.projects.get(1, lazy=True).runners.create({"runner_id": 6})
assert runner.active == True
assert runner.active is True
assert runner.id == 6
assert runner.name == "test-name"


def test_enable_group_runner(gl: gitlab.Gitlab, resp_runner_enable):
runner = gl.groups.get(1, lazy=True).runners.create({"runner_id": 6})
assert runner.active == True
assert runner.active is True
assert runner.id == 6
assert runner.name == "test-name"

Expand Down
2 changes: 0 additions & 2 deletions gitlab/tests/objects/test_submodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import pytest
import responses

from gitlab.v4.objects import Project


@pytest.fixture
def resp_update_submodule():
Expand Down
6 changes: 3 additions & 3 deletions gitlab/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_instantiate(self, fake_gitlab, fake_manager):

assert {"foo": "bar"} == obj._attrs
assert {} == obj._updated_attrs
assert None == obj._create_managers()
assert obj._create_managers() is None
assert fake_manager == obj.manager
assert fake_gitlab == obj.manager.gitlab

Expand All @@ -92,7 +92,7 @@ def test_picklability(self, fake_manager):
assert isinstance(unpickled, FakeObject)
assert hasattr(unpickled, "_module")
assert unpickled._module == original_obj_module
pickled2 = pickle.dumps(unpickled)
pickle.dumps(unpickled)

def test_attrs(self, fake_manager):
obj = FakeObject(fake_manager, {"foo": "bar"})
Expand All @@ -112,7 +112,7 @@ def test_get_id(self, fake_manager):
assert 42 == obj.get_id()

obj.id = None
assert None == obj.get_id()
assert obj.get_id() is None

def test_custom_id_attr(self, fake_manager):
class OtherFakeObject(FakeObject):
Expand Down
17 changes: 8 additions & 9 deletions gitlab/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import unittest
from textwrap import dedent

import mock
Expand Down Expand Up @@ -154,9 +153,9 @@ def test_valid_data(m_open, path_exists):
assert "one" == cp.gitlab_id
assert "http://one.url" == cp.url
assert "ABCDEF" == cp.private_token
assert None == cp.oauth_token
assert cp.oauth_token is None
assert 2 == cp.timeout
assert True == cp.ssl_verify
assert cp.ssl_verify is True
assert cp.per_page is None

fd = io.StringIO(valid_config)
Expand All @@ -166,9 +165,9 @@ def test_valid_data(m_open, path_exists):
assert "two" == cp.gitlab_id
assert "https://two.url" == cp.url
assert "GHIJKL" == cp.private_token
assert None == cp.oauth_token
assert cp.oauth_token is None
assert 10 == cp.timeout
assert False == cp.ssl_verify
assert cp.ssl_verify is False

fd = io.StringIO(valid_config)
fd.close = mock.Mock(return_value=None)
Expand All @@ -177,7 +176,7 @@ def test_valid_data(m_open, path_exists):
assert "three" == cp.gitlab_id
assert "https://three.url" == cp.url
assert "MNOPQR" == cp.private_token
assert None == cp.oauth_token
assert cp.oauth_token is None
assert 2 == cp.timeout
assert "/path/to/CA/bundle.crt" == cp.ssl_verify
assert 50 == cp.per_page
Expand All @@ -188,10 +187,10 @@ def test_valid_data(m_open, path_exists):
cp = config.GitlabConfigParser(gitlab_id="four")
assert "four" == cp.gitlab_id
assert "https://four.url" == cp.url
assert None == cp.private_token
assert cp.private_token is None
assert "STUV" == cp.oauth_token
assert 2 == cp.timeout
assert True == cp.ssl_verify
assert cp.ssl_verify is True


@mock.patch("os.path.exists")
Expand Down Expand Up @@ -227,7 +226,7 @@ def test_data_from_helper(m_open, path_exists, tmp_path):
cp = config.GitlabConfigParser(gitlab_id="helper")
assert "helper" == cp.gitlab_id
assert "https://helper.url" == cp.url
assert None == cp.private_token
assert cp.private_token is None
assert "secret" == cp.oauth_token


Expand Down
Loading