Skip to content

Commit

Permalink
refactor: migrate to ruff (#374)
Browse files Browse the repository at this point in the history
Refactor black, isort, flake8 to use ruff.
Apply ruff format.

Fixes: GH-373
  • Loading branch information
aciba90 authored May 20, 2024
1 parent a866c23 commit 3fb4664
Show file tree
Hide file tree
Showing 46 changed files with 85 additions and 63 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1!7.0.1
1!7.0.2
1 change: 1 addition & 0 deletions examples/lxd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# This file is part of pycloudlib. See LICENSE file for license information.
"""Basic examples of various lifecycle with a LXD instance."""

import logging
import textwrap

Expand Down
7 changes: 4 additions & 3 deletions pycloudlib/azure/cloud.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is part of pycloudlib. See LICENSE file for license information.
# pylint: disable=C0302
"""Azure Cloud type."""

import base64
import contextlib
import datetime
Expand Down Expand Up @@ -582,9 +583,9 @@ def _create_vm_parameters(
user_data.encode()
).decode()

vm_parameters["storage_profile"][
"image_reference"
] = util.get_image_reference_params(image_id)
vm_parameters["storage_profile"]["image_reference"] = (
util.get_image_reference_params(image_id)
)

# We can have pro images from two different sources; marketplaces
# and snapshots. A snapshot image does not have the necessary metadata
Expand Down
8 changes: 2 additions & 6 deletions pycloudlib/azure/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ def remove_network_interface(self, ip_address: str):
nic_params = []
nic_to_remove: Optional[NetworkInterface] = None
for vm_nic in vm_nics:
nic_private_ip = vm_nic.ip_configurations[
0
].private_ip_address # type: ignore
nic_private_ip = vm_nic.ip_configurations[0].private_ip_address # type: ignore
if nic_private_ip == ip_address:
nic_to_remove = vm_nic
else:
Expand Down Expand Up @@ -382,9 +380,7 @@ def _remove_nic_from_vm(
ip_addr.ip_address
for ip_addr in all_ips
if ip_addr.id
== primary_nic.ip_configurations[
0
].public_ip_address.id # type: ignore
== primary_nic.ip_configurations[0].public_ip_address.id # type: ignore
][0]
if do_start:
self.start()
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/azure/security_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Azure Security Types Classes."""

from enum import Enum
from typing import Any, Dict, Optional

Expand Down
1 change: 1 addition & 0 deletions pycloudlib/azure/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""Azure Util Functions."""

import logging
import re
from typing import Any, Dict, NamedTuple, Optional
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Deal with configuration file."""

import logging
import os
from io import StringIO
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/ec2/cloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""AWS EC2 Cloud type."""

import re
from typing import List, Optional

Expand Down
1 change: 1 addition & 0 deletions pycloudlib/ec2/instance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""EC2 instance."""

import string
import time
from typing import Dict, List, Optional
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Each cloud can have specific errors, please refer to each
`pycloudlib.<cloud>.errors` module.
"""

import enum
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions pycloudlib/gce/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing errors specific to gce."""

from pycloudlib.errors import PycloudlibException


Expand Down
6 changes: 4 additions & 2 deletions pycloudlib/gce/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common GCE utils."""

import os
from urllib.error import HTTPError

Expand All @@ -20,8 +21,9 @@ def raise_on_error(response):
)
if "error" in response:
raise GceException(
"Received error(s)!\n"
"Errors: {}".format(response["error"]["errors"])
"Received error(s)!\n" "Errors: {}".format(
response["error"]["errors"]
)
)


Expand Down
1 change: 1 addition & 0 deletions pycloudlib/ibm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""IBM's __init__."""

from pycloudlib.ibm.errors import IBMException
from pycloudlib.ibm.instance import VPC, IBMInstance

Expand Down
1 change: 1 addition & 0 deletions pycloudlib/ibm/_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""Private utilities for IBM cloud."""

from functools import partial
from time import sleep
from typing import Callable, Iterator, Optional
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/ibm/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing errors specific to ibm."""

from pycloudlib.errors import PycloudlibException


Expand Down
1 change: 1 addition & 0 deletions pycloudlib/lxd/_images.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""LXD/LXD images' related functionalities."""

import functools
import itertools
import json
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/lxd/cloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""LXD Cloud type."""

import warnings
from abc import ABC
from itertools import count
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/lxd/defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""LXD default values to be used by cloud and instance modules."""

import textwrap

LXC_PROFILE_VERSION = "v3"
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/lxd/instance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""LXD instance."""

import json
import re
import time
Expand Down
8 changes: 2 additions & 6 deletions pycloudlib/oci/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,8 @@ def __init__(
self.fault_domain = fault_domain

self._log.debug("Logging into OCI")
self.compute_client = oci.core.ComputeClient(
self.oci_config
) # noqa: E501
self.network_client = oci.core.VirtualNetworkClient(
self.oci_config
) # noqa: E501
self.compute_client = oci.core.ComputeClient(self.oci_config) # noqa: E501
self.network_client = oci.core.VirtualNetworkClient(self.oci_config) # noqa: E501

def delete_image(self, image_id, **kwargs):
"""Delete an image.
Expand Down
16 changes: 6 additions & 10 deletions pycloudlib/oci/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def __init__(
if oci_config is None:
oci_config = oci.config.from_file("~/.oci/config") # noqa: E501
self.compute_client = oci.core.ComputeClient(oci_config) # noqa: E501
self.network_client = oci.core.VirtualNetworkClient(
oci_config
) # noqa: E501
self.network_client = oci.core.VirtualNetworkClient(oci_config) # noqa: E501

def __repr__(self):
"""Create string representation of class."""
Expand Down Expand Up @@ -229,13 +227,11 @@ def remove_network_interface(self, ip_address: str):
Note: In OCI, detaching triggers deletion.
"""
vnic_attachments = (
oci.pagination.list_call_get_all_results_generator( # noqa: E501
self.compute_client.list_vnic_attachments,
"record",
self.compartment_id,
instance_id=self.instance_id,
)
vnic_attachments = oci.pagination.list_call_get_all_results_generator( # noqa: E501
self.compute_client.list_vnic_attachments,
"record",
self.compartment_id,
instance_id=self.instance_id,
)
for vnic_attachment in vnic_attachments:
vnic_data = self.network_client.get_vnic(
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/oci/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""Utilities for OCI images and instances."""

import logging
import time
from typing import TYPE_CHECKING, Dict, Optional
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/openstack/cloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Openstack cloud type."""

import base64
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions pycloudlib/openstack/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing errors specific to openstack."""

from pycloudlib.errors import PycloudlibException


Expand Down
1 change: 1 addition & 0 deletions pycloudlib/openstack/instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Openstack instance type."""

import time
from itertools import chain
from typing import List, Optional
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/qemu/cloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""Cloud class for QEMU."""

import os
import re
import shutil
Expand Down
1 change: 1 addition & 0 deletions pycloudlib/qemu/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for use with QEMU."""

import errno
import socket

Expand Down
1 change: 1 addition & 0 deletions pycloudlib/vmware/instance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""VMWare instance."""

import subprocess
from typing import List, Mapping, Optional

Expand Down
23 changes: 15 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 79
target-version = ['py36']

[tool.isort]
profile = "black"
line_length = 79

[tool.mypy]
follow_imports = "silent"
warn_unused_ignores = "true"
Expand All @@ -31,3 +23,18 @@ module = [
"paramiko.*",
]
ignore_missing_imports = true

[tool.ruff]
line-length = 79

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
extend-select = [
"D", # pydocstyle
"I", # isort
]

[tool.ruff.lint.pydocstyle]
convention = "pep257"
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Legacy Python packaging entry-point."""

from setuptools import setup

setup()
1 change: 1 addition & 0 deletions tests/unit_tests/azure/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.azure.cloud module."""

import datetime
from io import StringIO

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/azure/test_security_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.azure.security_types module."""

from copy import deepcopy

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/gce/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.gce.cloud module."""

import mock
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/ibm/test_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is part of pycloudlib. See LICENSE file for license information.
"""Module for IBM util tests."""

from unittest import mock

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/lxd/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.lxd.cloud module."""

import contextlib
import io
from unittest import mock
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/lxd/test_defaults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.lxd.defaults module."""

import hashlib

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/lxd/test_images.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to lxd._images."""

import json
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/lxd/test_instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for pycloudlib.lxd.instance."""

import re
from copy import deepcopy
from json import dumps
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/openstack/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Openstack cloud tests."""

from io import StringIO
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/openstack/test_instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Openstack instance tests."""

from unittest import mock

from pycloudlib.openstack.instance import OpenstackInstance
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/qemu/test_qemu_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Since the integration tests are the primary tests, these are mostly testing
error conditions and corner cases.
"""

from collections import namedtuple
from pathlib import Path
from unittest import mock
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.cloud module."""

from io import StringIO
from textwrap import dedent

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the config.py module."""

import os
from io import StringIO

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the errors.py module."""

import pytest

from pycloudlib.errors import ResourceNotFoundError, ResourceType
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to pycloudlib.instance module."""

from itertools import repeat
from unittest import mock

Expand Down
Loading

0 comments on commit 3fb4664

Please sign in to comment.