Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Force usage of f-strings #9954

Merged
merged 6 commits into from
Nov 29, 2021
Merged

[CI] Force usage of f-strings #9954

merged 6 commits into from
Nov 29, 2021

Conversation

mx-psi
Copy link
Member

@mx-psi mx-psi commented Nov 18, 2021

What does this PR do?

Add a Python linter to force people to use f-strings as the preferred string formatting option.
Change existing usages to f-strings with the help of flynt, and skip some of the more troublesome refactors.

Motivation

  • Ensure consistent string formatting usage across all codebase
  • Ensure linters can detect unused or undefined variables (which are detected reliably, unlike dictionary keys)

Additional Notes

I divided the code rewriting into the automatic and manual parts; please look more carefully into the manual changes.

Possible Drawbacks / Trade-offs

  1. The automatic change is pretty simple and the flynt tool seems to be widely used, so I wouldn't worry that much about these.
  2. We may find that using format is necessary in some cases (e.g. when formatting raw strings or repeating the same arg several times). We can skip the linter in those places but I would expect them to be rare.
  3. This bumps the Python requirement for tooling to Python 3.7 or later (2018); I think that should be fine.

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • The appropriate team/.. label has been applied, if known.
  • A release note has been added or the changelog/no-changelog label has been applied.
  • Changed code has automated tests for its functionality.
  • Adequate QA/testing plan information is provided if the qa/skip-qa label is not applied.
  • If applicable, docs team has been notified or an issue has been opened on the documentation repo.
  • If applicable, the need-change/operator and need-change/helm labels have been applied.
  • If applicable, the config template has been updated.

@mx-psi mx-psi added changelog/no-changelog dev/tooling [deprecated] qa/skip-qa - use other qa/ labels [DEPRECATED] Please use qa/done or qa/no-code-change to skip creating a QA card [deprecated] team/agent-platform labels Nov 18, 2021
@mx-psi mx-psi added this to the 7.34.0 milestone Nov 18, 2021
@mx-psi mx-psi marked this pull request as ready for review November 18, 2021 11:31
@mx-psi mx-psi requested review from a team as code owners November 18, 2021 11:31

go_cmd = 'INTEGRATION=yes go test -mod={go_mod} {race_opt} -v'.format(**test_args)
go_cmd = f'INTEGRATION=yes go test -mod={go_mod} {race_opt} -v -tags "{go_build_tags}" {exec_opts}'
Copy link
Member Author

Choose a reason for hiding this comment

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

This was missing the build tags and exec opts

pkg/config/legacy/tests/config.py Outdated Show resolved Hide resolved
tasks/release.py Outdated Show resolved Hide resolved
Co-authored-by: Albert Vaca Cintora <albert.vaca@datadoghq.com>
Copy link
Contributor

@alai97 alai97 left a comment

Choose a reason for hiding this comment

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

Looks good for docs!

@mx-psi mx-psi merged commit f972bde into main Nov 29, 2021
@mx-psi mx-psi deleted the mx-psi/f-strings branch November 29, 2021 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants