Skip to content
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

Use ruff instead of flake8 + isort #126

Merged
merged 2 commits into from
Jul 18, 2023
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
13 changes: 2 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: pip
cache-dependency-path: |
requirements-dev.txt
setup.py
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements-dev.txt
- name: Run flake8
run: flake8
python-version: 3.11
- uses: pre-commit/action@v3.0.0
build:
runs-on: ubuntu-latest
strategy:
Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
minimum_pre_commit_version: 2.15.0
ci:
autofix_prs: false
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: ruff
args:
- --fix
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
47 changes: 44 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@ line-length = 99
target-version = ['py36']
skip-string-normalization = true

[tool.isort]
profile = "black"
multi_line_output = 3
[tool.ruff]
exclude = [
".git",
"ENV",
"__pycache__",
"build",
]
ignore = [
"D100",
"D104",
"D105",
"D200",
"D202",
"D203",
"D205",
"D212",
"D400",
"D401",
"D403",
"D415",
"E501",
]
line-length = 99
select = [
# NB: `hacking` rules aren't supported by ruff
"B",
"D",
"E",
"F",
"I",
"S",
"W",
]

[tool.ruff.per-file-ignores]
"*/__init__.py" = ["F401"]
"test/*" = [
"D",
"F841",
"S101",
"S105",
"S106",
"B011",
]
11 changes: 0 additions & 11 deletions requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
black~=21.4b1; platform_python_implementation != "PyPy"
flake8
flake8-bandit
flake8-black; platform_python_implementation != "PyPy"
flake8-bugbear
flake8-docstrings
flake8-isort
flake8-pytest
hacking
isort
mock
pip-tools
pytest
pytest-cov
responses
safety
110 changes: 9 additions & 101 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,88 +1,27 @@
#
# This file is autogenerated by pip-compile
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements-dev.in
#
appdirs==1.4.4
# via black
attrs==20.3.0
# via
# flake8-bugbear
# pytest
bandit==1.7.0
# via flake8-bandit
black==21.4b1 ; platform_python_implementation != "PyPy"
# via
# -r requirements-dev.in
# flake8-black
# via pytest
certifi==2020.12.5
# via requests
chardet==4.0.0
# via requests
click==7.1.2
# via
# black
# pip-tools
# safety
# via pip-tools
coverage==5.5
# via pytest-cov
dparse==0.5.1
# via safety
flake8-bandit==2.1.2
# via -r requirements-dev.in
flake8-black==0.2.1 ; platform_python_implementation != "PyPy"
# via -r requirements-dev.in
flake8-bugbear==21.4.3
# via -r requirements-dev.in
flake8-docstrings==1.6.0
# via -r requirements-dev.in
flake8-isort==4.0.0
# via -r requirements-dev.in
flake8-polyfill==1.0.2
# via flake8-bandit
flake8-pytest==1.3
# via -r requirements-dev.in
flake8==3.8.4
# via
# -r requirements-dev.in
# flake8-bandit
# flake8-black
# flake8-bugbear
# flake8-docstrings
# flake8-isort
# flake8-polyfill
# flake8-pytest
# hacking
gitdb==4.0.7
# via gitpython
gitpython==3.1.14
# via bandit
hacking==4.1.0
# via -r requirements-dev.in
idna==2.10
# via requests
iniconfig==1.1.1
# via pytest
isort==5.8.0
# via
# -r requirements-dev.in
# flake8-isort
mccabe==0.6.1
# via flake8
mock==4.0.3
# via -r requirements-dev.in
mypy-extensions==0.4.3
# via black
packaging==20.9
# via
# dparse
# pytest
# safety
pathspec==0.8.1
# via black
pbr==5.6.0
# via stevedore
# via pytest
pep517==0.10.0
# via pip-tools
pip-tools==6.1.0
Expand All @@ -91,52 +30,22 @@ pluggy==0.13.1
# via pytest
py==1.10.0
# via pytest
pycodestyle==2.6.0
# via
# flake8
# flake8-bandit
pydocstyle==6.0.0
# via flake8-docstrings
pyflakes==2.2.0
# via flake8
pyparsing==2.4.7
# via packaging
pytest-cov==2.11.1
# via -r requirements-dev.in
pytest==6.2.3
# via
# -r requirements-dev.in
# pytest-cov
pyyaml==6.0.1
# via
# bandit
# dparse
regex==2021.4.4
# via black
pytest-cov==2.11.1
# via -r requirements-dev.in
requests==2.25.1
# via
# responses
# safety
# via responses
responses==0.13.2
# via -r requirements-dev.in
safety==1.10.3
# via -r requirements-dev.in
six==1.15.0
# via
# bandit
# responses
smmap==4.0.0
# via gitdb
snowballstemmer==2.1.0
# via pydocstyle
stevedore==3.3.0
# via bandit
testfixtures==6.17.1
# via flake8-isort
# via responses
toml==0.10.2
# via
# black
# dparse
# pep517
# pytest
urllib3==1.26.5
Expand All @@ -146,4 +55,3 @@ urllib3==1.26.5

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
2 changes: 0 additions & 2 deletions test/test_server_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def test_server_prepare_post_body_optional_attributes(self):

@responses.activate
def test_create_server(self, manager):

responses.add(
responses.POST,
Mock.base_url + '/server',
Expand Down Expand Up @@ -213,7 +212,6 @@ def test_create_server_with_dict(self, manager):

@responses.activate
def test_create_server_from_template(self, manager):

UUID = '01215a5a-c330-4565-81ca-0e0e22eac672'

def _from_template_callback(request):
Expand Down
1 change: 0 additions & 1 deletion test/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def test_cancel_storage_import(self, manager):

@responses.activate
def test_storage_update(self, manager):

Mock.mock_put("storage/01d4fcd4-e446-433b-8a9c-551a1284952e")
storage = manager.modify_storage(
"01d4fcd4-e446-433b-8a9c-551a1284952e", title="my bigger data collection", size=15
Expand Down
2 changes: 0 additions & 2 deletions test/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def test_get_tags(self, manager):

@responses.activate
def test_create_new_tag(self, manager):

for _ in range(1, 4):
responses.add_callback(
responses.POST,
Expand All @@ -69,7 +68,6 @@ def test_create_new_tag(self, manager):

@responses.activate
def test_edit_tag(self, manager):

Mock.mock_get('tag/TheTestTag')
tag = manager.get_tag('TheTestTag')

Expand Down
1 change: 1 addition & 0 deletions upcloud_api/cloud_manager/server_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def create_server(self, server: Server) -> Server:
serialised into JSON. Refer to the REST API documentation for correct format.

Example:
-------
server1 = Server( core_number = 1,
memory_amount = 1024,
hostname = "my.example.1",
Expand Down
3 changes: 2 additions & 1 deletion upcloud_api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class UpCloudClientError(Exception):


class UpCloudAPIError(UpCloudClientError):
"""Custom Error class for UpCloud API error responses.
"""
Custom Error class for UpCloud API error responses.

Each API call returns an `error_code` and `error_message` that
are available as attributes via instances of this class.
Expand Down
3 changes: 2 additions & 1 deletion upcloud_api/ip_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class IPAddress(UpCloudResource):
"""
Class representation of the API's IP address. Extends UpCloudResource.

Attributes:
Attributes
----------
access -- "public" or "private"
address -- the actual IPAddress (string)
family -- IPv4 or IPv6
Expand Down
3 changes: 2 additions & 1 deletion upcloud_api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def prepare_post_body(self):
# set password_delivery default as 'none' to prevent API from sending
# emails (with credentials) about each created server
if not hasattr(self, 'password_delivery'):
body['server']['password_delivery'] = 'none'
# noqa reason: no, this is not a hard-coded password
body['server']['password_delivery'] = 'none' # noqa: S105

# collect storage devices and create a unique title (see: Storage.title in API doc)
# for each of them
Expand Down
1 change: 0 additions & 1 deletion upcloud_api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def to_dict(self):

@staticmethod
def _create_storage_objs(storages, cloud_manager):

# storages might be provided as a flat array or as a following dict:
# {'storage_devices': {'storage_device': [...]}} || {'storage_device': [...]}

Expand Down
3 changes: 2 additions & 1 deletion upcloud_api/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Tag(UpCloudResource):
"""
Class representation of the API's tags. Extends UpCloudResource.

Attributes:
Attributes
----------
name -- unique name for the tag
description -- optional description
servers -- list of Server objects (with only uuid populated)
Expand Down