Skip to content

Commit 1475e41

Browse files
noahpmaxd-nordic
authored andcommitted
Fix some unused imports and unnecessary f-strings
Via `uvx ruff check --fix .`.
1 parent 3fea4c0 commit 1475e41

15 files changed

Lines changed: 18 additions & 40 deletions

src/nrfcloud_utils/claim_and_provision_device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
nrf_cloud_diap,
1616
create_device_credentials
1717
)
18-
from nrfcloud_utils.cli_helpers import is_linux, is_windows, is_macos, setup_logging
19-
from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, CMD_TYPE_TLS_SHELL, parser_add_comms_args
18+
from nrfcloud_utils.cli_helpers import setup_logging
19+
from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, parser_add_comms_args
2020
from cryptography import x509
2121
from cryptography.hazmat.primitives import serialization
2222
from nrfcredstore.comms import Comms
@@ -129,7 +129,7 @@ def main(in_args):
129129
error_exit(f'Device ID must not exceed {DEV_ID_MAX_LEN} characters')
130130

131131
if 'CN=' in args.csr_attr:
132-
error_exit(f'Do not include CN in --csr_attr. The device ID will be used as the CN')
132+
error_exit('Do not include CN in --csr_attr. The device ID will be used as the CN')
133133

134134
# load local CA cert and key if needed; assume not needed if using provisioning tags
135135
if args.provisioning_tags is None:
@@ -192,7 +192,7 @@ def main(in_args):
192192
logger.info(f'Unclaiming device {dev_uuid}...')
193193
api_res = nrf_cloud_diap.unclaim_device(args.api_key, dev_uuid)
194194
if api_res.status_code == 204:
195-
logger.info(f'...success')
195+
logger.info('...success')
196196
else:
197197
nrf_cloud_diap.print_api_result("Unclaim device response", api_res)
198198
logger.info("Device may not have been claimed before, continuing...")

src/nrfcloud_utils/claim_devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import argparse
1010
import logging
1111
from nrfcloud_utils import nrf_cloud_diap
12-
from nrfcloud_utils.cli_helpers import is_linux, is_windows, is_macos, setup_logging
12+
from nrfcloud_utils.cli_helpers import setup_logging
1313

1414
logger = logging.getLogger(__name__)
1515

src/nrfcloud_utils/cli_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def write_file(pathname, filename, bytes):
6262
if not path.isdir(pathname):
6363
try:
6464
makedirs(pathname, exist_ok=True)
65-
except OSError as e:
65+
except OSError:
6666
raise RuntimeError(f"Error creating file path [{pathname}]")
6767

6868
full_path = path.join(pathname, filename)

src/nrfcloud_utils/create_device_credentials.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
from cryptography import x509
1616
import uuid
1717
from cryptography.x509 import (
18-
Name,
19-
NameAttribute,
20-
BasicConstraints,
2118
KeyUsage,
22-
AuthorityKeyIdentifier,
23-
SubjectKeyIdentifier,
2419
)
2520

2621
from nrfcloud_utils.cli_helpers import write_file, save_onboarding_csv, setup_logging

src/nrfcloud_utils/device_credentials_installer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import semver
1313
import logging
1414
from nrfcloud_utils import create_device_credentials, ca_certs, modem_credentials_parser
15-
from nrfcloud_utils.cli_helpers import write_file, save_devinfo_csv, save_onboarding_csv, is_linux, is_windows, is_macos, full_encoding, setup_logging
15+
from nrfcloud_utils.cli_helpers import write_file, save_devinfo_csv, save_onboarding_csv, full_encoding, setup_logging
1616
from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, CMD_TYPE_TLS_SHELL, parser_add_comms_args
1717
from nrfcredstore.command_interface import ATCommandInterface, TLSCredShellInterface
1818
from nrfcredstore.comms import Comms
@@ -377,30 +377,30 @@ def main(in_args):
377377
# write CA cert(s) to device
378378
nrf_ca_cert_text = format_cred(ca_certs.get_ca_certs(args.coap, stage=args.stage))
379379

380-
logger.info(f'Writing CA cert(s) to device...')
380+
logger.info('Writing CA cert(s) to device...')
381381
try:
382382
cred_if.write_credential(args.sectag, 0, nrf_ca_cert_text)
383383
except Exception as e:
384-
logger.error(f'Failed to write CA certificate to device')
384+
logger.error('Failed to write CA certificate to device')
385385
logger.debug(f'Error details: {e}')
386386
raise
387387

388388
# write dev cert to device
389-
logger.info(f'Writing dev cert to device...')
389+
logger.info('Writing dev cert to device...')
390390
try:
391391
cred_if.write_credential(args.sectag, 1, dev_text)
392392
except Exception as e:
393-
logger.error(f'Failed to write device certificate to device')
393+
logger.error('Failed to write device certificate to device')
394394
logger.debug(f'Error details: {e}')
395395
raise
396396

397397
# If the private key was locally generated, write it to the device
398398
if prv_text is not None:
399-
logger.info(f'Writing private key to device...')
399+
logger.info('Writing private key to device...')
400400
try:
401401
cred_if.write_credential(args.sectag, 2, prv_text)
402402
except Exception as e:
403-
logger.error(f'Failed to write private key to device')
403+
logger.error('Failed to write private key to device')
404404
logger.debug(f'Error details: {e}')
405405
raise
406406

src/nrfcloud_utils/gather_attestation_tokens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import csv
99
import argparse
1010
from nrfcloud_utils import modem_credentials_parser
11-
from nrfcloud_utils.cli_helpers import is_linux, is_windows, is_macos, setup_logging
12-
from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, CMD_TYPE_TLS_SHELL, parser_add_comms_args
11+
from nrfcloud_utils.cli_helpers import setup_logging
12+
from nrfcloud_utils.cli_helpers import CMD_TERM_DICT, CMD_TYPE_AUTO, CMD_TYPE_AT, CMD_TYPE_AT_SHELL, parser_add_comms_args
1313
from nrfcredstore.comms import Comms
1414
from nrfcredstore.command_interface import ATCommandInterface
1515
from datetime import datetime, timezone

src/nrfcloud_utils/modem_credentials_parser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import argparse
88
import sys
9-
from os import path
10-
from os import makedirs
119
from cbor2 import loads
1210
import base64
1311
import hashlib

src/nrfcloud_utils/nrf_cloud_diap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SPDX-License-Identifier: BSD-3-Clause
66

77
import requests
8-
import coloredlogs, logging
8+
import logging
99
from nrfcloud_utils import ca_certs
1010

1111
DEV_STAGE_DICT = {'dev': '.dev.',

src/nrfcloud_utils/nrf_cloud_onboard.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import os
1414
import io
1515
import logging
16-
from os import path
1716
from os import makedirs
18-
from ast import literal_eval
1917
from enum import Enum
2018
from nrfcloud_utils.cli_helpers import write_file, setup_logging
2119

@@ -349,7 +347,7 @@ def check_file_path(file):
349347
if not os.path.exists(path):
350348
try:
351349
makedirs(path, exist_ok=True)
352-
except OSError as e:
350+
except OSError:
353351
logger.error("Error creating file path: " + path)
354352
return ''
355353

tests/test_claim_and_provision_device.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
"""
44

55
from unittest.mock import patch, Mock
6-
from serial import Serial
7-
import pytest
86
from nrfcloud_utils import claim_and_provision_device
9-
from tempfile import TemporaryDirectory
107
from requests import Response
118
from collections import namedtuple
129

@@ -46,7 +43,7 @@ class TestClaimAndProvisionDevice:
4643
def test_provisioning_tags(self, ser, select_device, diap):
4744
diap.claim_device = Mock(return_value=TEST_RESPONSE)
4845
diap.can_device_be_claimed = Mock(return_value=(True, ""))
49-
args = f"--port /not/a/real/device --cmd-type at --api-key NOTAKEY --provisioning-tags nrf-cloud-onboarding".split()
46+
args = "--port /not/a/real/device --cmd-type at --api-key NOTAKEY --provisioning-tags nrf-cloud-onboarding".split()
5047
# call DUT
5148
claim_and_provision_device.main(args)
5249
diap.claim_device.assert_called_once()

0 commit comments

Comments
 (0)