diff --git a/bazel/wrapper_hook/lint.py b/bazel/wrapper_hook/lint.py index 44caf981016..f70d623c9b5 100644 --- a/bazel/wrapper_hook/lint.py +++ b/bazel/wrapper_hook/lint.py @@ -202,7 +202,7 @@ def run_rules_lint(bazel_bin: str, args: List[str]) -> bool: return False lint_all = "..." in args or "--all" in args or "//..." in args - files_to_format = args + files_to_lint = args if not lint_all and len([arg for arg in args if not arg.startswith("--")]) == 0: origin_branch = "origin/master" for arg in args: @@ -221,34 +221,33 @@ def run_rules_lint(bazel_bin: str, args: List[str]) -> bool: ) lint_all = True else: - files_to_format = [ + files_to_lint = [ file for file in _get_files_changed_since_fork_point(origin_branch) - if file.endswith((".cpp", ".c", ".h", ".py", ".js", ".mjs", ".json")) + if file.endswith((".cpp", ".c", ".h", ".py", ".js", ".mjs", ".json", ".lock", ".toml")) ] # Default to linting everything in rules_lint if no path was passed in. if len([arg for arg in args if not arg.startswith("--")]) == 0: args = ["//..."] + args - if lint_all or "sbom.json" in files_to_format: + if lint_all or "sbom.json" in files_to_lint: subprocess.run([bazel_bin, "run", "//buildscripts:sbom_linter"], check=True) - if lint_all or any(file.endswith(".h") or file.endswith(".cpp") for file in files_to_format): + if lint_all or any(file.endswith((".h", ".cpp")) for file in files_to_lint): subprocess.run( [bazel_bin, "run", "//buildscripts:quickmongolint", "--", "lint"], check=True ) if lint_all or any( - file.endswith(".cpp") - or file.endswith(".c") - or file.endswith(".h") - or file.endswith(".py") - or file.endswith(".idl") - for file in files_to_format + file.endswith((".cpp", ".c", ".h", ".py", ".idl")) + for file in files_to_lint ): subprocess.run([bazel_bin, "run", "//buildscripts:errorcodes", "--", "--quiet"], check=True) + if lint_all or "poetry.lock" in files_to_lint or "pyproject.toml" in files_to_lint: + subprocess.run([bazel_bin, "run", "//buildscripts:poetry_lock_check"], check=True) + fix = "" with tempfile.NamedTemporaryFile(delete=False) as buildevents: buildevents_path = buildevents.name diff --git a/buildscripts/BUILD.bazel b/buildscripts/BUILD.bazel index d9a044c506c..2a2b32ddfc2 100644 --- a/buildscripts/BUILD.bazel +++ b/buildscripts/BUILD.bazel @@ -270,6 +270,18 @@ py_binary( )], ) +py_binary( + name = "poetry_lock_check", + srcs = ["poetry_lock_check.py"], + visibility = ["//visibility:public"], + deps = [ + dependency( + "poetry", + group = "export", + ), + ], +) + # TODO(SERVER-105817): The following library is autogenerated, please split these out into individual python targets py_library( name = "all_python_files", diff --git a/evergreen/functions/poetry_lock_check.py b/buildscripts/poetry_lock_check.py similarity index 77% rename from evergreen/functions/poetry_lock_check.py rename to buildscripts/poetry_lock_check.py index ef56ded2342..7ec1fa4d7d0 100644 --- a/evergreen/functions/poetry_lock_check.py +++ b/buildscripts/poetry_lock_check.py @@ -5,17 +5,20 @@ Check to make sure poetry.lock is synced with pyproject.toml. Returns nonzero if poetry.lock and pyproject.toml are not synced """ +import os import subprocess POETRY_LOCK_V200 = ( """# This file is automatically @generated by Poetry 2.0.0 and should not be changed by hand.""" ) + +REPO_ROOT = os.environ.get("BUILD_WORKSPACE_DIRECTORY", ".") # This has a great error message as part of the failure case -subprocess.run(["poetry", "check", "--lock"], check=True) +subprocess.run(["python", "-m", "poetry", "check", "--lock"], check=True, cwd=REPO_ROOT) # Check if the poetry lock file was generated with poetry 2.0.0 -with open("poetry.lock", "r") as poetry_lock: +with open(f"{REPO_ROOT}/poetry.lock", "r") as poetry_lock: if POETRY_LOCK_V200 not in poetry_lock.read(len(POETRY_LOCK_V200)): raise Exception("""Poetry lockfile was not generated by poetry 2.0.0. Make sure to have poetry 2.0.0 installed when running poetry lock. diff --git a/etc/evergreen_yml_components/tasks/misc_tasks.yml b/etc/evergreen_yml_components/tasks/misc_tasks.yml index fba4acca3d2..087fa44662f 100644 --- a/etc/evergreen_yml_components/tasks/misc_tasks.yml +++ b/etc/evergreen_yml_components/tasks/misc_tasks.yml @@ -824,36 +824,6 @@ tasks: - "--exclude" - "src/third_party/*" - # Confirm that the poetry.lock file is up to date with pyproject.toml - - name: lint_poetry_lock - tags: - [ - "assigned_to_jira_team_devprod_build", - "development_critical_single_variant", - "lint", - ] - commands: - - command: timeout.update - params: - # 20 mins - exec_timeout_secs: 1200 - - func: "f_expansions_write" - - command: manifest.load - - func: "git get project and add git tag" - - func: "f_expansions_write" - - func: "kill processes" - - func: "cleanup environment" - - func: "set up venv" - - func: "upload pip requirements" - - command: subprocess.exec - type: test - params: - binary: bash - args: - - "src/evergreen/run_python_script_with_report.sh" - - "lint-poetry-lock" - - "evergreen/functions/poetry_lock_check.py" - - name: lint_pyright tags: [