Skip to content

Commit aa485a7

Browse files
Move YAPF style setting to a project-wide .style.yapf file (#1038)
Scripts and workflows that run `yapf` currently each add the option `--style=google` to the invocation of `yapf`. To follow best practices, this PR adds a `.style.yapf` configuration file at the top level of the project to set the style, and removes the flag from where it was added on the command line explicitly. The use of a config file has the following benefits: - It lets tools like IDEs discover the setting automatically. - It reduces the chances that developers will forget to add the flag when they run `yapf` directly on the command line for quick checks, or write new scripts that use `yapf`. - It communicates intentions more clearly to new contributors. Removing the flag from the scripts is not strictly necessary (everything will work the same if there is both a config file and the flag is passed to `yapf`). However, if a config file is used, it's better for maintainability and consistency to also remove the flag from individual invocations. Note: the CI will fail the lint check until PR #1047 is merged. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 2d046b9 commit aa485a7

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

.style.yapf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[style]
2+
based_on_style = google

scripts/format_all.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616
echo "Doing python language formatting..."
17-
python3 -m yapf --style=google --in-place --recursive --parallel \
18-
./benchmarks ./scripts ./tensorflow_quantum
17+
python3 -m yapf --in-place --recursive ./benchmarks ./tensorflow_quantum ./scripts
1918
echo -e "Done! \nDoing notebook formatting..."
2019
python3 ./scripts/format_ipynb.py
2120
echo -e "Done! \nDoing C++ formatting..."

scripts/format_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ for changed_file in ${changed_files}; do
7272
)
7373
if [[ "${changed_line_ranges}" != "--lines=0-0 " ]]; then
7474
# Do the formatting.
75-
results=$(yapf --style=google --diff "${changed_file}" ${changed_line_ranges})
75+
results=$(python3 -m yapf --diff "${changed_file}" ${changed_line_ranges})
7676

7777
# Print colorized error messages.
7878
if [ ! -z "${results}" ]; then

0 commit comments

Comments
 (0)