Skip to content

Black formatting#699

Merged
aylusltd merged 12 commits into
mainfrom
proper_black_support
Mar 10, 2025
Merged

Black formatting#699
aylusltd merged 12 commits into
mainfrom
proper_black_support

Conversation

@SeanTConrad
Copy link
Copy Markdown
Collaborator

@SeanTConrad SeanTConrad commented Mar 7, 2025

Why are these changes needed?

Two changes:

  • Ran black
  • Removed flake8 from github actions so it won't conflict

I will open another PR to remove flake8 completely and make sure black runs in actions.

Related issue number

Checks

  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed.

Summary by Sourcery

Apply black formatting to the codebase and remove flake8 from GitHub Actions to avoid conflicts.

Enhancements:

  • Apply black formatting to the codebase.

CI:

  • Remove flake8 from GitHub Actions workflow.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Mar 7, 2025

Reviewer's Guide by Sourcery

This pull request includes changes to format the code with black and remove flake8 from the GitHub Actions workflow. The primary goal is to enforce consistent code formatting and avoid conflicts between formatting tools.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Applied black formatting to the codebase.
  • Ran black to reformat the code to adhere to a consistent style.
  • Updated code to comply with black's formatting standards.
src/verinfast/agent.py
src/verinfast/cloud/aws/instances.py
src/verinfast/config.py
src/verinfast/cloud/azure/instances.py
src/verinfast/utils/utils.py
tests/test_truncate.py
src/verinfast/cloud/gcp/instances.py
src/verinfast/cloud/aws/blocks.py
src/verinfast/dependencies/walkers/gemwalker.py
src/verinfast/cloud/azure/costs.py
src/verinfast/cloud/azure/blocks.py
src/verinfast/cloud/aws/costs.py
src/verinfast/dependencies/walkers/composer.py
src/verinfast/utils/git_metrics.py
tests/test_dependency.py
src/verinfast/upload.py
src/verinfast/dependencies/walk.py
src/verinfast/dependencies/walkers/classes.py
tests/test_costs.py
tests/test_package_lock.py
src/verinfast/user.py
src/verinfast/dependencies/walkers/dockerwalker.py
tests/test_yaml.py
src/verinfast/dependencies/walkers/nuget.py
tests/test_args.py
src/verinfast/cloud/gcp/blocks.py
tests/test_dry.py
tests/test_local.py
src/verinfast/cloud/cloud_dataclass.py
src/verinfast/dependencies/walkers/npm.py
src/verinfast/dependencies/walkers/python.py
tests/test_aws.py
src/verinfast/utils/license.py
tests/test_tsx.py
tests/test_print_cloud_provider.py
src/verinfast/cloud/aws/get_profile.py
src/verinfast/dependencies/walkers/package_lock.py
src/verinfast/dependencies/walkers/maven.py
src/verinfast/system/sysinfo.py
src/verinfast/dependencies/walkers/go.py
tests/test_gcp.py
tests/test_cache.py
tests/test_repo_name.py
tests/test_template.py
src/verinfast/cloud/aws/regions.py
src/verinfast/cloud/gcp/zones.py
tests/test_non_unicode.py
tests/test_sysinfo.py
src/verinfast/cloud/aws/regions.py
Removed flake8 from GitHub Actions.
  • Removed the flake8 step from the GitHub Actions workflow.
  • Stopped running flake8 checks during CI.
.github/workflows/release.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @SeanTConrad - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a brief description of what each function does using docstrings.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/verinfast/config.py Outdated
Comment thread src/verinfast/agent.py
Comment on lines +151 to +153
raise Exception(
f"{self.scanId} returned for failed report Id fetch."
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Raise a specific error instead of the general Exception or BaseException (raise-specific-error)

ExplanationIf a piece of code raises a specific exception type rather than the generic [`BaseException`](https://docs.python.org/3/library/exceptions.html#BaseException) or [`Exception`](https://docs.python.org/3/library/exceptions.html#Exception), the calling code can:
  • get more information about what type of error it is
  • define specific exception handling for it

This way, callers of the code can handle the error appropriately.

How can you solve this?

So instead of having code raising Exception or BaseException like

if incorrect_input(value):
    raise Exception("The input is incorrect")

you can have code raising a specific error like

if incorrect_input(value):
    raise ValueError("The input is incorrect")

or

class IncorrectInputError(Exception):
    pass


if incorrect_input(value):
    raise IncorrectInputError("The input is incorrect")

Comment thread src/verinfast/cloud/aws/instances.py Outdated
Comment thread src/verinfast/cloud/aws/instances.py Outdated
Comment thread src/verinfast/cloud/aws/instances.py Outdated
)

bearer_token = "Bearer "+results.stdout.decode().strip()
bearer_token = "Bearer " + results.stdout.decode().strip()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

dry=False,
log=None
):
def get_instances(sub_id: str, path_to_output: str = "./", dry=False, log=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:


Explanation

The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

Comment thread src/verinfast/config.py
Comment on lines 433 to 438
# protocol_separator
ps = "://"
for sp in supported_protocols:
if s.lower().startswith(sp+ps):
if s.lower().startswith(sp + ps):
return True
return False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): We've found these issues:

Suggested change
# protocol_separator
ps = "://"
for sp in supported_protocols:
if s.lower().startswith(sp+ps):
if s.lower().startswith(sp + ps):
return True
return False
return any(s.lower().startswith(f"{sp}://") for sp in supported_protocols)

Comment thread src/verinfast/dependencies/walkers/classes.py
Comment thread src/verinfast/dependencies/walkers/composer.py
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 7, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 92 lines in your changes missing coverage. Please review.

Project coverage is 78.01%. Comparing base (1a6b95c) to head (276f8a3).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/verinfast/agent.py 65.74% 37 Missing ⚠️
src/verinfast/cloud/azure/instances.py 12.50% 14 Missing ⚠️
src/verinfast/cloud/azure/costs.py 0.00% 6 Missing ⚠️
src/verinfast/dependencies/walkers/gemwalker.py 72.22% 5 Missing ⚠️
src/verinfast/cloud/azure/blocks.py 0.00% 4 Missing ⚠️
src/verinfast/config.py 78.94% 4 Missing ⚠️
src/verinfast/dependencies/walkers/composer.py 69.23% 4 Missing ⚠️
src/verinfast/cloud/aws/instances.py 91.89% 3 Missing ⚠️
src/verinfast/upload.py 50.00% 3 Missing ⚠️
src/verinfast/dependencies/walkers/classes.py 71.42% 2 Missing ⚠️
... and 8 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #699   +/-   ##
=======================================
  Coverage   78.00%   78.01%           
=======================================
  Files          31       31           
  Lines        2228     2229    +1     
=======================================
+ Hits         1738     1739    +1     
  Misses        490      490           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread tests/test_dry.py Outdated
assert get_url == "/report/uuid/9a6e8696-f93a-4402-a64e-342ccb37592b/CorsisCode", get_url # noqa: E501
assert (
agent.config.use_uuid is True
), f"Expected True, config {agent.config}" # noqa: E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we remove the flake comments?

Comment thread src/verinfast/upload.py Outdated
raise Exception("Invocation Error: must supply either a report ID or UUID") # noqa: E501
raise Exception(
"Invocation Error: must supply either a report ID or UUID"
) # noqa: E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same thing here

license_resp = self.getUrl(f"https://registry.npmjs.org/{entry.name}/{entry.specifier}/") # NOQA:E501
license_resp = self.getUrl(
f"https://registry.npmjs.org/{entry.name}/{entry.specifier}/"
) # NOQA:E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again, if we're here

license_resp = self.getUrl(f"{self.registrationUrl}{name}/{version}.json") # NOQA:E501
license_resp = self.getUrl(
f"{self.registrationUrl}{name}/{version}.json"
) # NOQA:E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is really repetitive. I struggled a lot to spell that. Can you tell I started this review at the bottom?

.content
.decode('utf-8-sig')
)
return self.requestx.get( # noqa: E271 # NOQA: E131
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is silly

Comment thread src/verinfast/cloud/gcp/blocks.py Outdated
MetricServiceClient,
TimeInterval,
ListTimeSeriesRequest,
) # noqa: E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this line is not too long.

Comment thread tests/test_truncate.py Outdated
findings_file_path = results_dir.joinpath('small-test-repo.git.findings.json') # NOQA: E501
findings_file_path = results_dir.joinpath(
"small-test-repo.git.findings.json"
) # NOQA: E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove flake8 directives

Comment thread tests/test_truncate.py Outdated
assert (
m
== "Data is being eval'd from a `curl` command. An attacker with control of the server in the `curl` command could inject malicious code into the `eval`, resulting in a system comrpomise. Avoid eval'ing untrusted data if you can. If you must do this, consider checking the SHA sum of the content returned by the server to verify its integrity."
) # noqa: E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here too

Comment thread src/verinfast/cloud/gcp/instances.py Outdated
MetricServiceClient,
TimeInterval,
ListTimeSeriesRequest,
) # noqa: E501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove directives

Comment thread src/verinfast/cloud/gcp/instances.py Outdated
Utilization_Datum as Datum,
)

# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/Users/jason/.config/gcloud/application_default_credentials.json" # noqa: E501
Copy link
Copy Markdown
Contributor

@aylusltd aylusltd Mar 10, 2025

Choose a reason for hiding this comment

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

it's a comment, within a comment. yodawg.gif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and this is a comment in response to a comment about a comment within a comment. headsplode.gif

Comment thread src/verinfast/config.py
"code" in self.config["modules"] and
"git" in self.config["modules"]["code"]
"repos" in self.config
and "modules" in self.config
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh we gotta find a way to fix that. ands and other joiners have to be at the end of the line. This isn't just PEP wrong, it's all interpreter wrong. We should open a PR to black. (later)

SeanTConrad and others added 7 commits March 10, 2025 11:32
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ SeanTConrad
❌ Sean T. Conrad


Sean T. Conrad seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@aylusltd aylusltd merged commit bef3992 into main Mar 10, 2025
@aylusltd aylusltd deleted the proper_black_support branch March 10, 2025 18:21
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.

4 participants