Skip to content

Commit c20a203

Browse files
fix: import error (#567)
* fix: import get_cli_args in get_report_results * chore: address linting errors * build: use ruff for linting and run linting this uses ruff for linting, it adds a configuration for ignoring certain rules (F401: unused import) and excluding certain directories (default + languages/ + samples/) * fix: remove as _ from except statements * build: update ci to lint with make lint
1 parent 1f04560 commit c20a203

34 files changed

Lines changed: 161 additions & 95 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@ jobs:
1616
- uses: actions/checkout@v4
1717
with:
1818
submodules: true
19-
- name: Install dependencies
19+
- name: Check linting with ruff
2020
run: |
21-
python -m pip install --upgrade pip
22-
pip install black==22.3.0 isort==5.10.1
23-
- name: Check linting with black
24-
run: |
25-
black --check codecov_cli
26-
- name: Check imports order with isort
27-
run: |
28-
isort --check --profile=black codecov_cli -p staticcodecov_languages
21+
make lint
22+
2923
3024
codecov-startup:
3125
runs-on: ubuntu-latest

Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@ name ?= codecovcli
22
# Semantic versioning format https://semver.org/
33
tag_regex := ^v([0-9]{1,}\.){2}[0-9]{1,}([-_]\w+)?$
44

5+
lint.install:
6+
echo "Installing ruff..."
7+
pip install -Iv ruff
8+
9+
# The preferred method (for now) w.r.t. fixable rules is to manually update the makefile
10+
# with --fix and re-run 'make lint.' Since ruff is constantly adding rules this is a slight
11+
# amount of "needed" friction imo.
12+
lint.run:
13+
ruff check --ignore F401 --exclude languages --exclude samples
14+
ruff format --exclude languages --exclude samples
15+
16+
lint.check:
17+
echo "Linting..."
18+
ruff check --ignore F401 --exclude languages --exclude samples
19+
echo "Formatting..."
20+
ruff format --check --exclude languages --exclude samples
21+
522
lint:
6-
pip install black==22.3.0 isort==5.10.1
7-
black codecov_cli
8-
isort --profile=black codecov_cli -p staticcodecov_languages
9-
black tests
10-
isort --profile black tests
23+
make lint.install
24+
make lint.run
1125

1226
tag.release:
1327
ifeq ($(shell echo ${version} | egrep "${tag_regex}"),)

codecov_cli/commands/get_report_results.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import click
44

55
from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
6+
from codecov_cli.helpers.args import get_cli_args
67
from codecov_cli.helpers.encoder import encode_slug
78
from codecov_cli.helpers.git import GitService
89
from codecov_cli.helpers.options import global_options
910
from codecov_cli.services.report import send_reports_result_get_request
1011
from codecov_cli.types import CommandContext
1112

13+
1214
logger = logging.getLogger("codecovcli")
1315

1416

codecov_cli/commands/labelanalysis.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ def _dry_run_list_output(
390390
logger.warning(f"label-analysis didn't run correctly. Error: {fallback_reason}")
391391

392392
to_run_line = " ".join(
393-
sorted(map(lambda l: f"'{l}'", runner_options))
394-
+ sorted(map(lambda l: f"'{l}'", labels_to_run))
393+
sorted(map(lambda option: f"'{option}'", runner_options))
394+
+ sorted(map(lambda label: f"'{label}'", labels_to_run))
395395
)
396396
to_skip_line = " ".join(
397-
sorted(map(lambda l: f"'{l}'", runner_options))
398-
+ sorted(map(lambda l: f"'{l}'", labels_to_skip))
397+
sorted(map(lambda option: f"'{option}'", runner_options))
398+
+ sorted(map(lambda label: f"'{label}'", labels_to_skip))
399399
)
400400
# ⚠️ DON'T use logger
401401
# logger goes to stderr, we want it in stdout

codecov_cli/commands/process_test_results.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def process_test_results(
103103
dir, exclude_folders, files, disable_search, report_type="test_results"
104104
)
105105

106-
upload_collection_results: List[
107-
UploadCollectionResultFile
108-
] = file_finder.find_files()
106+
upload_collection_results: List[UploadCollectionResultFile] = (
107+
file_finder.find_files()
108+
)
109109
if len(upload_collection_results) == 0:
110110
raise click.ClickException(
111111
"No JUnit XML files were found. Make sure to specify them using the --file option."

codecov_cli/helpers/args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def get_cli_args(ctx: click.Context):
2020
filtered_args = {}
2121
for k in args.keys():
2222
try:
23-
if type(args[k]) == PosixPath:
23+
if isinstance(args[k], PosixPath):
2424
filtered_args[k] = str(args[k])
2525
else:
2626
json.dumps(args[k])
2727
filtered_args[k] = args[k]
28-
except Exception as e:
28+
except Exception:
2929
continue
3030

3131
return filtered_args

codecov_cli/helpers/request.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def backoff_time(curr_retry):
5252
return 2 ** (curr_retry - 1)
5353

5454

55-
class RetryException(Exception):
56-
...
55+
class RetryException(Exception): ...
5756

5857

5958
def retry_request(func):
@@ -73,7 +72,7 @@ def wrapper(*args, **kwargs):
7372
requests.exceptions.ConnectionError,
7473
requests.exceptions.Timeout,
7574
RetryException,
76-
) as exp:
75+
):
7776
logger.warning(
7877
"Request failed. Retrying",
7978
extra=dict(extra_log_attributes=dict(retry=retry)),

codecov_cli/plugins/pycoverage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def __init__(self, config: dict):
5454
self.config = PycoverageConfig(config)
5555

5656
def run_preparation(self, collector) -> PreparationPluginReturn:
57-
5857
if shutil.which("coverage") is None:
5958
logger.warning("coverage.py is not installed or can't be found.")
6059
return

codecov_cli/runners/dan_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def process_labelanalysis_result(self, result: LabelAnalysisRequestResult):
5454
"DAN runner missing 'process_labelanalysis_result_command' configuration value"
5555
)
5656
command_list = []
57-
if type(command) == list:
57+
if isinstance(command, list):
5858
command_list.extend(command)
5959
else:
6060
command_list.append(command)

codecov_cli/runners/pytest_standard_runner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def get_available_params(cls) -> List[str]:
5757

5858

5959
class PytestStandardRunner(LabelAnalysisRunnerInterface):
60-
6160
dry_run_runner_options = ["--cov-context=test"]
6261
params: PytestStandardRunnerConfigParams
6362

0 commit comments

Comments
 (0)