Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/problem-matchers/black.json

This file was deleted.

17 changes: 17 additions & 0 deletions .github/problem-matchers/ruff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "ruff",
"pattern": [
{
"regexp": "^(.+?):(\\d+):(\\d+): (?:([A-Z0-9]+) )?(.+)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Check format
continue-on-error: ${{inputs.soft-linting == 'true'}}
run: |
echo '::add-matcher::.github/problem-matchers/black.json'
echo '::add-matcher::.github/problem-matchers/ruff.json'
check/format-incremental

- name: Check lint
Expand Down
59 changes: 30 additions & 29 deletions check/format-incremental
Original file line number Diff line number Diff line change
Expand Up @@ -112,48 +112,49 @@ if (( ${#format_files[@]} == 0 )); then
exit 0
fi

# Apply isort only on Python files with the exception of __init__.py files.
declare -a isort_files=()
for f in "${format_files[@]}"; do
if [[ "${f}" == *.py && "${f##*/}" != __init__.py ]]; then
isort_files+=("${f}")
fi
done

# Color the output if it goes to a terminal or GitHub Actions log.
arg_color=()
if [[ -t 1 || "${CI}" == true ]]; then
arg_color=("--color")
# Check if ruff supports --color (it might be missing in older/some versions).
if ruff --help 2>&1 | grep -q -- '--color'; then
arg_color=("--color" "always")
fi
fi

ISORTVERSION=$(isort --version-number)

echo "Sorting imports with isort... (version: $ISORTVERSION)"

args=("${arg_color[@]}")
if (( only_print == 1 )); then
args+=("--check" "--diff")
# Run ruff for import sorting.
# We do this first so that if it changes files, the formatting step will pick them up.
echo "Running ruff check (isort)..."
check_args=("check" "--select" "I" "${arg_color[@]}")
if (( only_print == 0 )); then
check_args+=("--fix")
else
# In check mode, we want to see diffs if possible, but ruff check usually just prints violations.
# To match previous behavior of "checking" without modifying, we don't add --fix.
# If we want diffs for imports, --diff can be used.
check_args+=("--diff")
fi

ISORTSTATUS=0
if (( "${#isort_files[@]}" )); then
isort "${args[@]}" "${isort_files[@]}"
ISORTSTATUS=$?
RUFF_CHECK_STATUS=0
if (( "${#format_files[@]}" )); then
# We pass all files to ruff; it handles excluding those that shouldn't be touched if configured,
# but here we are passing a specific list of files.
ruff "${check_args[@]}" "${format_files[@]}"
RUFF_CHECK_STATUS=$?
fi

BLACKVERSION=$(black --version | head -1)

echo "Running the black formatter... (version: $BLACKVERSION)"

args=("${arg_color[@]}")
echo "Running ruff format..."
format_args=("format" "${arg_color[@]}")
if (( only_print == 1 )); then
args+=("--check" "--diff")
format_args+=("--check" "--diff")
fi

black "${args[@]}" "${format_files[@]}"
BLACKSTATUS=$?
RUFF_FORMAT_STATUS=0
if (( "${#format_files[@]}" )); then
ruff "${format_args[@]}" "${format_files[@]}"
RUFF_FORMAT_STATUS=$?
fi

if (( BLACKSTATUS || ISORTSTATUS )); then
if (( RUFF_CHECK_STATUS || RUFF_FORMAT_STATUS )); then
exit 1
fi
exit 0
4 changes: 2 additions & 2 deletions docs/_scripts/build_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
# ==============================================================================
"""Tool to generate external api_docs for qsim shameless copy from TFQ."""

import os

from absl import app, flags
Expand All @@ -24,7 +25,7 @@

flags.DEFINE_string(
"code_url_prefix",
("https://github.com/quantumlib/qsim/tree/main/" "qsimcirq"),
("https://github.com/quantumlib/qsim/tree/main/qsimcirq"),
"The url prefix for links to code.",
)

Expand All @@ -40,7 +41,6 @@


def main(unused_argv):

doc_generator = generate_lib.DocGenerator(
root_title="qsim",
py_modules=[("qsimcirq", qs)],
Expand Down
Loading
Loading