-
Notifications
You must be signed in to change notification settings - Fork 253
fix: add lint rule to detect bare pip install and fix beval.yml violation #2548
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
Open
pratik wayase (PratikWayase)
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
PratikWayase:fix/add-lint-rule-to-detect-bare-pip-install
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c1dd4a2
fix: add lint rule to detect bare pip install and fix beval.yml viola…
PratikWayase 744a33f
fix: add pip-install-lint to pr-validation-success needs
PratikWayase 55042b9
fix: enforce uv-first convention with bare pip install lint rule and …
PratikWayase d41018d
revert: remove accidental IDE auto-formatting in markdown files
PratikWayase 07571a9
fix: address review comments (pin uv action, exempt %pip, remove inva…
PratikWayase f861b2b
fix: address review nits
PratikWayase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: Pip Install Lint | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| on: | ||
| workflow_call: | ||
|
PratikWayase marked this conversation as resolved.
|
||
| inputs: | ||
| soft-fail: | ||
| description: 'Whether to continue on bare pip install violations' # pip-install-ok | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| check-bare-pip-install: | ||
|
|
||
| name: Check for bare pip install | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| continue-on-error: ${{ inputs.soft-fail }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
PratikWayase marked this conversation as resolved.
|
||
| with: | ||
| persist-credentials: false | ||
| - name: Run bare pip install lint check | ||
| run: pwsh -File scripts/linting/Invoke-PipInstallLint.ps1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
PratikWayase marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # Copyright (c) 2026 Microsoft Corporation. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Lint script to detect bare 'pip install' calls. | ||
| The repository follows a 'uv-first' Python convention. | ||
| #> | ||
|
|
||
| param( | ||
| [string]$TestDirectory = "." | ||
| ) | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| $script:ExcludeDirs = @(".git", "evals", ".venv", "venv", "env", "node_modules", "__pycache__") | ||
| $script:ExcludeFiles = @("THIRD-PARTY-NOTICES", "Invoke-PipInstallLint.ps1", "Invoke-PipInstallLint.Tests.ps1") | ||
| $script:Violations = @() | ||
| $script:ScannedFiles = @{} | ||
|
|
||
| function script:Test-ExcludedPath { | ||
| param([string]$Path) | ||
| $normalizedPath = $Path.Replace("\", "/").ToLowerInvariant() | ||
|
|
||
| foreach ($dir in $script:ExcludeDirs) { | ||
| if ($dir -eq "evals") { | ||
| if ($normalizedPath -match "(^|/)evals(/|$)" -and $normalizedPath -notmatch "(^|/)scripts/evals(/|$)") { | ||
| return $true | ||
| } | ||
| } else { | ||
| if ($normalizedPath -match "(^|/)$([regex]::Escape($dir))(/|$)") { | ||
| return $true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| foreach ($file in $script:ExcludeFiles) { | ||
| if ($normalizedPath -match "(^|/)$([regex]::Escape($file))(/|$)") { | ||
| return $true | ||
| } | ||
| } | ||
| return $false | ||
| } | ||
|
|
||
| function script:Invoke-FileScan { | ||
| param([string]$FilePath) | ||
|
|
||
| $normalizedPath = $FilePath.Replace("\", "/") | ||
| if ($script:ScannedFiles.ContainsKey($normalizedPath)) { return } | ||
| $script:ScannedFiles[$normalizedPath] = $true | ||
|
|
||
| if (script:Test-ExcludedPath -Path $FilePath) { return } | ||
|
|
||
| $ext = [System.IO.Path]::GetExtension($FilePath).ToLowerInvariant() | ||
|
|
||
| if ($ext -notin @(".py", ".ps1", ".yml", ".yaml", ".md", ".sh", "")) { return } | ||
|
|
||
| try { | ||
| $lines = Get-Content -Path $FilePath -Raw -ErrorAction SilentlyContinue | ||
| if (-not $lines) { return } | ||
|
|
||
| $lineNumber = 1 | ||
| foreach ($line in $lines -split "`r?`n") { | ||
| $strippedLine = $line.Trim() | ||
|
|
||
| if ([string]::IsNullOrWhiteSpace($strippedLine)) { | ||
| $lineNumber++ | ||
| continue | ||
| } | ||
|
|
||
| if ($line -match "#\s*pip-install-ok\b" -or $line -match "<!--\s*pip-install-ok\s*-->") { | ||
| $lineNumber++ | ||
| continue | ||
| } | ||
|
|
||
| $cleanedLine = $line -replace "\buv\s+pip3?\s+install\b", "" -replace "%pip\s+install", "" | ||
| if ($cleanedLine -match "\bpip3?\s+install\b") { | ||
| if ($strippedLine -notmatch "^(name:|- name:)") { | ||
| $script:Violations += "$FilePath`:$lineNumber`: $strippedLine" | ||
| } | ||
| } | ||
| $lineNumber++ | ||
| } | ||
| } | ||
| catch { | ||
| Write-Warning "Could not read $FilePath`: $_" | ||
| } | ||
| } | ||
|
|
||
| function script:Invoke-Lint { | ||
| param([string]$TargetDir = ".") | ||
|
|
||
| $script:Violations = @() | ||
| $script:ScannedFiles = @{} | ||
|
|
||
| $extensions = @("*.py", "*.ps1", "*.yml", "*.yaml", "*.md", "*.sh") | ||
|
|
||
| if ($TargetDir -eq ".") { | ||
| $rootDir = (Resolve-Path ".").Path | ||
|
|
||
| $trackedFiles = git -C $rootDir ls-files 2>$null | ||
|
|
||
| if ($LASTEXITCODE -eq 0 -and $trackedFiles) { | ||
| foreach ($file in $trackedFiles) { | ||
| $ext = [System.IO.Path]::GetExtension($file) | ||
| if ($ext -in @(".py", ".ps1", ".yml", ".yaml", ".md", ".sh")) { | ||
| $fullPath = Join-Path $rootDir $file | ||
| script:Invoke-FileScan -FilePath $fullPath | ||
| } | ||
| } | ||
| } else { | ||
| Get-ChildItem -Path $rootDir -Recurse -Include $extensions -File -Force -ErrorAction SilentlyContinue | ForEach-Object { | ||
| script:Invoke-FileScan -FilePath $_.FullName | ||
| } | ||
| } | ||
| } else { | ||
| Get-ChildItem -Path $TargetDir -Recurse -Include $extensions -File -Force -ErrorAction SilentlyContinue | ForEach-Object { | ||
| script:Invoke-FileScan -FilePath $_.FullName | ||
| } | ||
| } | ||
|
|
||
| if ($script:Violations.Count -gt 0) { | ||
| Write-Error "ERROR: Found bare 'pip install' calls. Use 'uv pip install' instead." | ||
| Write-Host "The repo follows a uv-first Python convention.`n" -ForegroundColor Yellow | ||
| foreach ($v in ($script:Violations | Sort-Object -Unique)) { | ||
| Write-Host " - $v" -ForegroundColor Red | ||
| } | ||
| return $false | ||
| } else { | ||
| Write-Host "Success: No bare 'pip install' calls found." -ForegroundColor Green | ||
| return $true | ||
| } | ||
| } | ||
|
|
||
| if ($MyInvocation.InvocationName -ne '.') { | ||
| $success = script:Invoke-Lint -TargetDir $TestDirectory | ||
| if (-not $success) { exit 1 } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.