Skip to content

Commit 55ab7c5

Browse files
Apply black formatting
1 parent 4971c71 commit 55ab7c5

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

src/py_sonar_scanner/configuration.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class Configuration:
3232
scan_arguments: list[str]
3333

3434
def __init__(self):
35-
self.sonar_scanner_path = '.scanner'
36-
self.sonar_scanner_version = '4.6.2.2472'
37-
self.sonar_scanner_executable_path = ''
35+
self.sonar_scanner_path = ".scanner"
36+
self.sonar_scanner_version = "4.6.2.2472"
37+
self.sonar_scanner_executable_path = ""
3838
self.scan_arguments = []
3939

4040
def setup(self):
41-
""" This is executed when run from the command line """
41+
"""This is executed when run from the command line"""
4242
parser = argparse.ArgumentParser()
4343

4444
# Required positional argument
@@ -51,12 +51,7 @@ def setup(self):
5151
parser.add_argument("-n", "--name", action="store", dest="name")
5252

5353
# Optional verbosity counter (eg. -v, -vv, -vvv, etc.)
54-
parser.add_argument(
55-
"-v",
56-
"--verbose",
57-
action="count",
58-
default=0,
59-
help="Verbosity (-v, -vv, etc)")
54+
parser.add_argument("-v", "--verbose", action="count", default=0, help="Verbosity (-v, -vv, etc)")
6055

6156
# Specify output of "--version"
6257
# parser.add_argument(
@@ -82,14 +77,14 @@ def _read_jvm_args(self) -> list[str]:
8277
def _read_toml_args(self) -> list[str]:
8378
scan_arguments: list[str] = []
8479
try:
85-
if os.path.isfile('pyproject.toml'):
86-
with open('pyproject.toml', 'r') as file:
80+
if os.path.isfile("pyproject.toml"):
81+
with open("pyproject.toml", "r") as file:
8782
# TODO: actually search for pyproject.toml
8883
toml_data = file.read()
8984
parsed_data = toml.loads(toml_data)
9085
print(parsed_data)
91-
if 'sonar' in parsed_data:
92-
sonar_properties = parsed_data['sonar']
86+
if "sonar" in parsed_data:
87+
sonar_properties = parsed_data["sonar"]
9388
for key, value in sonar_properties.items():
9489
self._add_parameter_to_scanner_args(scan_arguments, key, value)
9590
except BaseException as e:

src/py_sonar_scanner/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
from logging import Logger
2222
from typing import Optional
2323

24-
class ApplicationLogger():
2524

25+
class ApplicationLogger:
2626
_log: Optional[Logger] = None
2727

2828
@classmethod
2929
def get_logger(cls) -> Logger:
3030
if not cls._log:
3131
cls._log = logging.getLogger("main")
3232
cls._setup_logger(cls._log)
33-
return cls._log
33+
return cls._log
3434

3535
@staticmethod
3636
def _setup_logger(log: Logger):

src/py_sonar_scanner/utils/binaries_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#
2020
import zipfile
2121

22+
2223
def write_binaries(scanner_res: bytes, destination: str):
2324
with open(destination, "wb") as output:
2425
output.write(scanner_res.read())
2526

27+
2628
def unzip_binaries(scanner_zip_path: str, destination: str):
2729
with zipfile.ZipFile(scanner_zip_path, "r") as zip_ref:
2830
zip_ref.extractall(destination)

tests/test_environment.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
class TestEnvironment(unittest.TestCase):
28-
2928
@patch("py_sonar_scanner.environment.write_binaries")
3029
@patch("py_sonar_scanner.environment.urllib.request.urlopen")
3130
def test_download_scanner(self, mock_urlopen, mock_write_binaries):
@@ -79,22 +78,18 @@ def test_install_scanner(self, mock_os, mock_unzip_binaries):
7978
environment._install_scanner(system_name)
8079

8180
mock_os.mkdir.assert_called_once_with(scanner_path)
82-
environment._download_scanner_binaries.assert_called_once_with(
83-
scanner_path, scanner_version, system_name
84-
)
81+
environment._download_scanner_binaries.assert_called_once_with(scanner_path, scanner_version, system_name)
8582
mock_unzip_binaries.assert_called_once_with(download_destination, scanner_path)
8683

8784
mock_os.remove.assert_called_once_with(download_destination)
88-
environment._change_permissions_recursive.assert_called_once_with(
89-
scanner_path, 0o777
90-
)
85+
environment._change_permissions_recursive.assert_called_once_with(scanner_path, 0o777)
9186

9287
def test_setup_when_scanner_is_on_path(self):
9388
cfg = Configuration()
9489
environment = Environment(cfg)
9590
environment.cleanup = Mock()
9691
environment._is_sonar_scanner_on_path = Mock(return_value=True)
97-
92+
9893
environment.setup()
9994

10095
environment.cleanup.assert_called_once()
@@ -145,7 +140,7 @@ def test_cleanup_when_scanner_path_does_not_exist(self, mock_shutil, mock_os_pat
145140
environment = Environment(cfg)
146141
mock_os_path.exists = Mock(return_value=False)
147142
mock_shutil.rmtree = Mock()
148-
143+
149144
environment.cleanup()
150145

151146
mock_os_path.exists.assert_called_once_with(scanner_path)
@@ -158,7 +153,7 @@ def test_is_sonar_scanner_on_path(self, mock_shutil):
158153
cfg.sonar_scanner_path = scanner_path
159154
environment = Environment(cfg)
160155
mock_shutil.which = Mock()
161-
156+
162157
environment._is_sonar_scanner_on_path()
163158

164159
mock_shutil.which.assert_called_once_with("sonar-scanner")

tests/test_scanner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
class TestScanner(unittest.TestCase):
28-
2928
def test_scanner_compute_command(self):
3029
cfg = Configuration()
3130
cfg.sonar_scanner_executable_path = "test"

0 commit comments

Comments
 (0)