From 288655f0ceebfdff49d4a2d5f1ddf57abbdca254 Mon Sep 17 00:00:00 2001 From: blakeNaccarato Date: Thu, 18 Jul 2024 15:07:56 -0700 Subject: [PATCH] Sync with template --- .copier-answers.yml | 2 +- .github/workflows/changerelease.yml | 1 - .github/workflows/ci.yml | 15 +++++------ .github/workflows/contrib.yml | 6 ++--- .github/workflows/high.yml | 18 +++++++------ .github/workflows/release.yml | 6 ++--- .pre-commit-config.yaml | 8 ------ .renovaterc.json | 17 ++++++++++++ .vscode/extensions.json | 5 ++++ .vscode/tasks.json | 4 +-- pyproject.toml | 18 +++---------- scripts/Initialize-Repo.ps1 | 3 ++- scripts/Initialize-Shell.ps1 | 40 ++++++++++++++++++----------- scripts/Sync-Py.ps1 | 28 ++++++++++---------- scripts/Sync-Template.ps1 | 2 +- scripts/boilerdata_tools/sync.py | 2 +- scripts/install.py | 6 +++-- 17 files changed, 98 insertions(+), 83 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index 8a639c8..46678b6 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier; NEVER EDIT MANUALLY -_commit: 2024.1.1-91-g2217ca3 +_commit: 2024.1.1-166-g3a37de1 _src_path: gh:blakeNaccarato/copier-python actions_runner: ubuntu-22.04 active: true diff --git a/.github/workflows/changerelease.yml b/.github/workflows/changerelease.yml index 035f17c..64aa6e7 100644 --- a/.github/workflows/changerelease.yml +++ b/.github/workflows/changerelease.yml @@ -15,7 +15,6 @@ jobs: strategy: matrix: runner: ["ubuntu-22.04"] - python: ["3.11"] permissions: contents: "write" runs-on: "${{ matrix.runner }}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29e8145..6389add 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ defaults: run: shell: "pwsh" env: - UV_CACHE_DIR: ".cache/uv-cache" + UV_CACHE_DIR: "../uv-cache" UV_SYSTEM_PYTHON: "true" jobs: sync: @@ -59,7 +59,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - run: ". scripts/Initialize-Shell.ps1; sphinx-build -EaT docs _site" + - run: "sphinx-build -EaT docs _site" - uses: "actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa" # v3.0.1 deploy-docs: if: github.event_name != 'pull_request' @@ -100,7 +100,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - run: ". scripts/Initialize-Shell.ps1; ruff check --no-fix --output-format github ." + - run: "ruff check --no-fix --output-format github ." fawltydeps: needs: "sync" strategy: @@ -123,7 +123,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - run: ". scripts/Initialize-Shell.ps1; fawltydeps" + - run: "fawltydeps" pyright: needs: "sync" strategy: @@ -146,9 +146,9 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - uses: "jakebailey/pyright-action@3bdde3b31d26f0f1f5de051b1fbd7a536a9a4e7f" # v4.1.7 + - uses: "jakebailey/pyright-action@3bdde3b31d26f0f1f5de051b1fbd7a536a9a4e7f" # v2.3.1 with: - pylance-version: "2024.6.1" + pylance-version: "${{ env.PYRIGHT_PYTHON_PYLANCE_VERSION }}" test: needs: "sync" strategy: @@ -176,8 +176,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1 -Version '${{ matrix.python }}'" - # ! https://github.com/pytest-dev/pytest-cov/issues/479#issuecomment-1247444988 - - run: ". scripts/Initialize-Shell.ps1; pytest --cov --cov-config pyproject.toml" + - run: "pytest" - if: startsWith(matrix.runner, 'ubuntu') && matrix.python == '3.11' uses: "codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673" # v4.5.0 env: diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 53e3b88..303229d 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -19,7 +19,7 @@ defaults: run: shell: "pwsh" env: - UV_CACHE_DIR: ".cache/uv-cache" + UV_CACHE_DIR: "../uv-cache" SYNC_PY_DISABLE_CI: True jobs: no-spaces-in-path: @@ -61,8 +61,8 @@ jobs: - uses: "actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9" # v4.0.2 with: path: "${{ env.UV_CACHE_DIR }}" - key: "uv-${{ matrix.runner }}-${{ matrix.python }}-${{ hashFiles('lock.json') }}" - - uses: "actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f" # v5.1.1 + key: "uv-${{ matrix.runner }}-${{ matrix.python }}-${{ hashFiles('repo path with spaces/lock.json') }}" + - uses: "actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d" # v5.1.0 with: python-version: "${{ matrix.python }}" - working-directory: "repo path with spaces" diff --git a/.github/workflows/high.yml b/.github/workflows/high.yml index 5cbb327..32bc525 100644 --- a/.github/workflows/high.yml +++ b/.github/workflows/high.yml @@ -8,7 +8,7 @@ defaults: run: shell: "pwsh" env: - UV_CACHE_DIR: ".cache/uv-cache" + UV_CACHE_DIR: "../uv-cache" UV_SYSTEM_PYTHON: "true" SYNC_PY_HIGH: "true" jobs: @@ -48,7 +48,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - run: ". scripts/Initialize-Shell.ps1; sphinx-build -EaT docs _site" + - run: "sphinx-build -EaT docs _site" - uses: "actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa" # v3.0.1 ruff: needs: "sync" @@ -68,7 +68,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - run: ". scripts/Initialize-Shell.ps1; ruff check --no-fix --output-format github ." + - run: "ruff check --no-fix --output-format github ." fawltydeps: needs: "sync" strategy: @@ -87,7 +87,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - run: ". scripts/Initialize-Shell.ps1; fawltydeps" + - run: "fawltydeps" pyright: needs: "sync" strategy: @@ -106,9 +106,9 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1" - - uses: "jakebailey/pyright-action@3bdde3b31d26f0f1f5de051b1fbd7a536a9a4e7f" # v4.1.7 + - uses: "jakebailey/pyright-action@3bdde3b31d26f0f1f5de051b1fbd7a536a9a4e7f" # v2.3.1 with: - pylance-version: "2024.6.1" + pylance-version: "${{ env.PYRIGHT_PYTHON_PYLANCE_VERSION }}" test: needs: "sync" strategy: @@ -132,7 +132,7 @@ jobs: with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1 -Version '${{ matrix.python }}'" - - run: ". scripts/Initialize-Shell.ps1; pytest" + - run: "pytest" lock: needs: - "ruff" @@ -148,7 +148,9 @@ jobs: runs-on: "${{ matrix.runner }}" steps: - uses: "actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332" # v4.1.7 - - uses: "actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16" # v4.1.8 + with: + submodules: True + - uses: "actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e" # v4.1.7 with: name: "lock" - uses: "stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842" # v5.0.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5691d8..34edeb4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,12 +25,12 @@ jobs: url: "https://pypi.org/p/boilerdata" steps: - uses: "actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332" # v4.1.7 - - uses: "actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f" # v5.1.1 + - uses: "actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d" # v5.1.0 with: python-version: "${{ matrix.python }}" - run: "scripts/Sync-Py.ps1 -Release" - - run: ". scripts/Initialize-Shell.ps1; python -m build --installer uv" - - uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3 + - run: "python -m build --installer uv" + - uses: actions/attest-build-provenance@bdd51370e0416ac948727f861e03c2f05d32d78e # v1.3.2 with: subject-path: "dist/**" - run: "gh release upload '${{ github.event.release.tag_name }}' dist/**" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 66d1f4a..602759e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,6 @@ ci: - "fawltydeps-docs" - "fawltydeps-scripts" - "fawltydeps-tests" - - "pyright" - "pytest-fast-only" - "synchronize-params" autoupdate_schedule: "quarterly" @@ -67,13 +66,6 @@ repos: files: "^tests/.*$" entry: | pwsh -Command ". scripts/Initialize-Shell.ps1; fawltydeps --config-file tests/pyproject.toml" - - id: "pyright" - name: "pyright" - pass_filenames: false - language: "system" - entry: | - pwsh -Command ". scripts/Initialize-Shell.ps1; pyright" - types_or: ["python", "pyi"] - id: "pytest-fast-only" name: "pytest-fast-only" pass_filenames: false diff --git a/.renovaterc.json b/.renovaterc.json index fae8970..93a4a21 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -9,6 +9,7 @@ "enabled": true }, "enabledManagers": [ + "custom.regex", "devcontainer", "git-submodules", "github-actions", @@ -16,6 +17,22 @@ "pip_requirements", "pre-commit" ], + "customManagers": [ + { + "description": "Pylance", + "customType": "regex", + "fileMatch": [ + "^scripts/Initialize-Shell\\.ps1$", + "^\\.devcontainer/devcontainer\\.json$" + ], + "matchStrings": [ + "PYRIGHT_PYTHON_PYLANCE_VERSION = '(?.+)'", + "ms-python\\.vscode-pylance@(?[^\"]+)" + ], + "datasourceTemplate": "github-releases", + "depNameTemplate": "microsoft/pylance-release" + } + ], "pip_requirements": { "description": "Additionally monitor these files", "fileMatch": ["(^|/)requirements/.+$"] diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2c44500..68d732b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,6 +2,7 @@ "recommendations": [ "aaron-bond.better-comments", "bierner.markdown-preview-github-styles", + "charliermarsh.ruff", "davidanson.vscode-markdownlint", "donjayamanne.githistory", "eamodio.gitlens", @@ -12,12 +13,16 @@ "github.vscode-github-actions", "github.vscode-pull-request-github", "ms-azuretools.vscode-docker", + "ms-python.debugpy", + "ms-python.python", "ms-toolsai.jupyter", "ms-vscode.powershell", "ms-vscode-remote.remote-containers", "njpwerner.autodocstring", + "njpwerner.autodocstring", "redhat.vscode-yaml", "rodolphebarbanneau.python-docstring-highlighter", + "rodolphebarbanneau.python-docstring-highlighter", "ryanluker.vscode-coverage-gutters", "sourcery.sourcery", "stkb.rewrap", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 076ac4f..6fd82f6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -190,14 +190,14 @@ { "label": "task: pre-commit", "type": "shell", - "command": ". scripts/Initialize-Shell.ps1; pre-commit", + "command": ". scripts/Initialize-Shell.ps1; pre-commit run --verbose", "icon": { "id": "git-commit" }, "problemMatcher": [] }, { "label": "task: pre-commit (all)", "type": "shell", - "command": ". scripts/Initialize-Shell.ps1; pre-commit run --all-files", + "command": ". scripts/Initialize-Shell.ps1; pre-commit run --all-files --verbose", "icon": { "id": "git-commit" }, "problemMatcher": [] }, diff --git a/pyproject.toml b/pyproject.toml index 2679f33..c2cd157 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,20 +100,8 @@ name = "Changes" showcontent = true [tool.pyright] -exclude = [ - "**/node_modules", - "**/__pycache__", - "**/.*", - "**/.*/**", - "**/.venv", - "**/.vscode/extensions", - "**/AppData", - "bin", - "submodules/template", - "submodules/**/docs", - "submodules/**/scripts", - "submodules/**/tests", -] +stubPath = "submodules/stubs/stubs" +ignore = ["bin", "submodules", "scripts/install.py"] typeCheckingMode = "strict" # Default "true" in strict analyzeUnannotatedFunctions = true @@ -212,7 +200,7 @@ reportUnusedCallResult = "none" [tool.ruff] cache-dir = ".cache/.ruff_cache" -extend-exclude = ["bin", "submodules", "**/axes_enum.py"] +extend-exclude = ["bin", "submodules", "scripts/install.py", "**/axes_enum.py"] extend-include = ["*.ipynb"] src = ["src", "docs", "scripts", "tests"] output-format = "grouped" diff --git a/scripts/Initialize-Repo.ps1 b/scripts/Initialize-Repo.ps1 index 5eab3ca..342ee35 100644 --- a/scripts/Initialize-Repo.ps1 +++ b/scripts/Initialize-Repo.ps1 @@ -9,7 +9,8 @@ catch [System.Management.Automation.NativeCommandExitException] { $fresh = $true git add . git commit --no-verify -m 'Prepare template using blakeNaccarato/copier-python' -git submodule add --force --name template 'https://github.com/blakeNaccarato/copier-python.git' submodules/template +git submodule add --force --name 'template' 'https://github.com/blakeNaccarato/copier-python.git' 'submodules/template' +git submodule add --force --name 'stubs' 'https://github.com/microsoft/python-type-stubs.git' 'submodules/stubs' git add . git commit --no-verify -m 'Add template and type stub submodules' scripts/Sync-Py.ps1 diff --git a/scripts/Initialize-Shell.ps1 b/scripts/Initialize-Shell.ps1 index d8712f9..874fa3c 100644 --- a/scripts/Initialize-Shell.ps1 +++ b/scripts/Initialize-Shell.ps1 @@ -4,8 +4,8 @@ Initialization commands for PowerShell shells in pre-commit and tasks.#> # ? Error-handling $ErrorActionPreference = 'Stop' -($PSNativeCommandUseErrorActionPreference = $true) | Out-Null -($ErrorView = 'NormalView') | Out-Null +$PSNativeCommandUseErrorActionPreference = $true +$ErrorView = 'NormalView' # ? Fix leaky UTF-8 encoding settings on Windows if ($IsWindows) { @@ -15,25 +15,35 @@ if ($IsWindows) { [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new() } -# ? Environment variables -$Env:PYRIGHT_PYTHON_PYLANCE_VERSION = '2024.6.1' -$Env:PYDEVD_DISABLE_FILE_VALIDATION = 1 -$Env:PYTHONIOENCODING = 'utf-8:strict' -$Env:PYTHONUTF8 = 1 -$Env:PYTHONWARNDEFAULTENCODING = 1 -# Ignore warnings until explicitly re-enabled in tests -$Env:PYTHONWARNINGS = 'ignore' - # ? Environment setup function Set-Env { <#.SYNOPSIS - Load `.env`, activate a virtual environment found here or in parent directories.#> + Activate virtual environment and set environment variables.#> + + # ? Set environment variables + $LocalBin = (Test-Path 'bin') ? (Get-Item 'bin') : (New-Item -ItemType Directory 'bin') + $Vars = $Env:GITHUB_ENV ? $(Get-Content $Env:GITHUB_ENV | + Select-String -Pattern '^(.+)=.+$' | + ForEach-Object { $_.Matches.Groups[1].value }) : @{} + foreach ($i in @{ + PATH = "$LocalBin$($IsWindows ? ';' : ':')$Env:PATH" + PYRIGHT_PYTHON_PYLANCE_VERSION = '2024.6.1' + PYDEVD_DISABLE_FILE_VALIDATION = '1' + PYTHONIOENCODING = 'utf-8:strict' + PYTHONWARNDEFAULTENCODING = '1' + PYTHONWARNINGS = 'ignore' + COVERAGE_CORE = 'sysmon' + }.GetEnumerator() ) { + Set-Item "Env:$($i.Key)" $($i.Value) + if ($Env:GITHUB_ENV -and ($i.Key -notin $Vars)) { + "$($i.Key)=$($i.Value)" >> $Env:GITHUB_ENV + } + } + # ? Activate virtual environment if one exists if (Test-Path '.venv') { if ($IsWindows) { .venv/scripts/activate.ps1 } else { .venv/bin/activate.ps1 } } - # ? Prepend local `bin` to PATH - $sep = $IsWindows ? ';' : ':' - $Env:PATH = "bin$sep$Env:PATH" + } Set-Env diff --git a/scripts/Sync-Py.ps1 b/scripts/Sync-Py.ps1 index 4fa4a51..28ae8f5 100644 --- a/scripts/Sync-Py.ps1 +++ b/scripts/Sync-Py.ps1 @@ -24,25 +24,25 @@ elseif ($Devcontainer) { $msg = 'devcontainer' } elseif ($Release) { $msg = 'release' } "Will run $msg steps" | Write-Progress -Info -if (!$CI -and - (Get-Command -Name 'code' -ErrorAction 'Ignore') -and - !(code --list-extensions | Select-String -Pattern 'charliermarsh.ruff', 'ms-python.vscode-pylance') -) { - 'INSTALLING LOCAL VSCODE WORKSPACE EXTENSIONS' | Write-Progress - if (Get-Command -Name 'code' -ErrorAction 'Ignore') { $py = 'py' } +if (!$CI -and !$Devcontainer -and (Get-Command -Name 'code' -ErrorAction 'Ignore')) { + 'INSTALLING PYLANCE LOCALLY' | Write-Progress + $LocalExtensions = '.vscode/extensions' + $Pylance = 'ms-python.vscode-pylance' $Install = @( - '--extensions-dir=.vscode/extensions', - '--install-extension=charliermarsh.ruff@2024.30.0', - '--install-extension=ms-python.vscode-pylance@2024.6.1' + "--extensions-dir=$LocalExtensions", + "--install-extension=$Pylance@$Env:PYRIGHT_PYTHON_PYLANCE_VERSION" ) code @Install + $PylanceExtension = Get-ChildItem -Path $LocalExtensions -Filter "$Pylance-*" + # Remove other files + Get-ChildItem -Path $LocalExtensions | + Where-Object { Compare-Object $_ $PylanceExtension } | + Remove-Item -Recurse # Remove local Pylance bundled stubs - Get-ChildItem -Path '.vscode/extensions' -Filter 'ms-python.vscode-pylance-*' | - ForEach-Object { - Get-ChildItem -Path "$($_.FullName)/dist/bundled" -Filter '*stubs' - } | + $PylanceExtension | + ForEach-Object { Get-ChildItem "$_/dist/bundled" -Filter '*stubs' } | Remove-Item -Recurse - 'INSTALLED LOCAL VSCODE WORKSPACE EXTENSIONS' | Write-Progress -Done + 'INSTALLED PYLANCE LOCALLY' | Write-Progress -Done } 'FINDING UV' | Write-Progress $uvVersionRe = Get-Content 'requirements/uv.txt' | Select-String -Pattern '^uv==(.+)$' diff --git a/scripts/Sync-Template.ps1 b/scripts/Sync-Template.ps1 index 0c52dbd..4a07a1a 100644 --- a/scripts/Sync-Template.ps1 +++ b/scripts/Sync-Template.ps1 @@ -20,7 +20,7 @@ begin { function Get-Ref { Param($Ref) $TemplateRev = $TemplateExists ? "HEAD:$Template" : 'origin/main' - return ($Ref -eq 'HEAD') ? $(git rev-parse $TemplateRev) : $Ref + return ($Ref -eq 'HEAD') ? (git rev-parse $TemplateRev) : $Ref } } process { diff --git a/scripts/boilerdata_tools/sync.py b/scripts/boilerdata_tools/sync.py index ef829b1..1d61687 100644 --- a/scripts/boilerdata_tools/sync.py +++ b/scripts/boilerdata_tools/sync.py @@ -253,7 +253,7 @@ def get_subs() -> dict[str, Dep]: op=" @ ", rev=f"git+{subs[path]}@{revs[path]}" ) for path in subs - if path != "submodules/template" + if path not in ["submodules/stubs", "submodules/template"] } diff --git a/scripts/install.py b/scripts/install.py index 1855d7f..3d03993 100644 --- a/scripts/install.py +++ b/scripts/install.py @@ -28,12 +28,14 @@ """Current platform.""" VER = argv[1] if len(argv) > 1 else "3.10" """Version to install.""" +TIMEOUT = 10.0 +"""Request timeout.""" # Retrieve Python versions and metadata from `astral/uv` tooling _source = "https://raw.githubusercontent.com/astral-sh/uv/b7fb0b445f3698dd1dfc90361b9bea0ab1edee52" -with Client() as client: +with Client(timeout=TIMEOUT) as client: response = client.get(f"{_source}/.python-versions") VERSIONS = response.text.splitlines() -with Client() as client: +with Client(timeout=TIMEOUT) as client: response = client.get(f"{_source}/crates/uv-toolchain/download-metadata.json") META = response.json()