Skip to content

Fix some unused imports and unnecessary f-strings#82

Open
noahp wants to merge 1 commit intonoahp/colored-loggingfrom
noahp/ruff-check
Open

Fix some unused imports and unnecessary f-strings#82
noahp wants to merge 1 commit intonoahp/colored-loggingfrom
noahp/ruff-check

Conversation

@noahp
Copy link
Copy Markdown
Contributor

@noahp noahp commented Mar 20, 2026

Via uvx ruff check --fix ..

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies automated Ruff fixes (uvx ruff check --fix .) to remove unused imports and simplify unnecessary f-strings across the test suite and CLI utilities.

Changes:

  • Remove unused imports (e.g., pytest, Serial, Mock, coloredlogs, OS helpers) across tests and modules.
  • Replace unnecessary f-strings with regular string literals in logging/messages and tests.
  • Simplify exception handlers where the exception variable was unused.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_modem_credentials_parser.py Removes unused pytest/Mock imports.
tests/test_gather_attestation_tokens.py Removes unused Serial/pytest imports.
tests/test_device_credentials_installer.py Removes unused Serial/pytest imports.
tests/test_create_device_credentials.py Removes unused pytest/Mock imports.
tests/test_create_ca_cert.py Removes unused pytest/Mock imports.
tests/test_claim_and_provision_device.py Removes unused imports and an unnecessary f-string in args construction.
src/nrfcloud_utils/nrf_cloud_onboard.py Removes unused imports and simplifies except clause in check_file_path.
src/nrfcloud_utils/nrf_cloud_diap.py Removes unused coloredlogs import; keeps logging.
src/nrfcloud_utils/modem_credentials_parser.py Removes unused path/makedirs imports.
src/nrfcloud_utils/gather_attestation_tokens.py Removes unused OS helper imports and trims CLI helper imports.
src/nrfcloud_utils/device_credentials_installer.py Removes unused OS helper imports and replaces unnecessary f-strings in logs.
src/nrfcloud_utils/create_device_credentials.py Removes unused cryptography.x509 imports.
src/nrfcloud_utils/cli_helpers.py Simplifies unused exception binding in write_file.
src/nrfcloud_utils/claim_devices.py Removes unused OS helper imports.
src/nrfcloud_utils/claim_and_provision_device.py Removes unused OS helper/TLS shell imports and replaces unnecessary f-strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

makedirs(path, exist_ok=True)
except OSError as e:
except OSError:
logger.error("Error creating file path: " + path)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In check_file_path, the except OSError: branch logs a generic message and drops the underlying exception details. Consider using logger.exception(...) or logger.error(..., exc_info=True) so permission/path issues include the original OSError/traceback in logs.

Suggested change
logger.error("Error creating file path: " + path)
logger.exception("Error creating file path: %s", path)

Copilot uses AI. Check for mistakes.
Comment on lines +65 to 66
except OSError:
raise RuntimeError(f"Error creating file path [{pathname}]")
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write_file catches OSError and raises a new RuntimeError without explicitly chaining the original exception. While Python will still attach context, using except OSError as e: ... raise RuntimeError(...) from e makes the causal relationship explicit and keeps the original errno/message easy to find in tracebacks.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants