From 4740605f75c357cd4d094b38fab6234579e07d1c Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 26 Sep 2023 22:41:00 -0500 Subject: [PATCH] WIP --- .github/workflows/test.yaml | 64 +++++++++++++++++++++++++++++++++++++ finder.ps1 | 17 ++++++++++ finder.sh | 23 +++++++++++++ identify.py | 34 ++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 .github/workflows/test.yaml create mode 100644 finder.ps1 create mode 100644 finder.sh create mode 100644 identify.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..9d07d68 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,64 @@ +name: "Test" + +on: + push: + branches: + - "main" + +jobs: + test: + name: "Test on ${{ matrix.config.os-name }}" + runs-on: "${{ matrix.config.runner }}" + strategy: + matrix: + config: + - os-name: "Linux" + runner: "ubuntu-latest" + test-label: "ci-test-linux" + - os-name: "macOS" + runner: "macos-latest" + test-label: "ci-test-macos" + - os-name: "Windows" + runner: "windows-latest" + test-label: "ci-test-windows" + fail-fast: false + + steps: + - name: "Show environment (pre)" + shell: "bash" + run: env | sort + + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Setup Python" + id: "setup-python" + uses: "actions/setup-python@v4" + with: + python-version: | + 3.9 + 3.10 + 3.11 + pypy-3.9 + allow-prereleases: true + + - name: "Show environment (post)" + shell: "bash" + run: env | sort + + - name: "Linux / macOS" + id: linux + if: "runner.os != 'windows'" + shell: "bash" + run: 'bash ./finder.sh > "$GITHUB_OUTPUT"' + + - name: "Windows" + id: "windows" + if: "runner.os == 'windows'" + shell: "powershell" + run: '& .\finder.ps1 > "$env:GITHUB_OUTPUT"' + + - name: "Show results" + shell: "bash" + run: | + echo "${{ steps.linux.outputs.python-versions }}${{ steps.windows.outputs.python-versions }}" diff --git a/finder.ps1 b/finder.ps1 new file mode 100644 index 0000000..d9e9de2 --- /dev/null +++ b/finder.ps1 @@ -0,0 +1,17 @@ +$all_paths = Get-ChildItem ` + -Path ` + "$env:RUNNER_TOOL_CACHE\Python\*\*", ` + "$env:RUNNER_TOOL_CACHE\PyPy\*\*" ` + -Filter "x??" ` + -Directory ` + | Sort-Object -Property FullName + +$paths = @() +foreach ($path in $all_paths) { + if (Test-Path "$path\python.exe") { + $paths += $path.FullName + } +} + +$output = $paths -join ";" +Write-Output "python-versions=$output" diff --git a/finder.sh b/finder.sh new file mode 100644 index 0000000..7a95a4f --- /dev/null +++ b/finder.sh @@ -0,0 +1,23 @@ +all_paths=( + "$( + find \ + "$RUNNER_TOOL_CACHE/Python" \ + "$RUNNER_TOOL_CACHE/PyPy" \ + -mindepth 2 \ + -maxdepth 2 \ + -name 'x86' \ + -o \ + -name 'x64' \ + | sort + )" +) + +paths=() +for path in "${all_paths[@]}"; do + if [[ -x "${path}/bin/python" ]]; then + paths+=("${path}/bin") + fi +done + +output=$(echo "${paths[*]}" | tr ' ' ':') +echo "python-versions=${output}" diff --git a/identify.py b/identify.py new file mode 100644 index 0000000..8012db6 --- /dev/null +++ b/identify.py @@ -0,0 +1,34 @@ +from __future__ import print_function + +import sys + + +def main(): + python_version, _, _ = sys.version.partition(" ") + architecture = "x86" + if sys.maxsize > 2 ** 32: + architecture = "x64" + + # PyPy + if hasattr(sys, "pypy_version_info"): + implementation = "PyPy" + implementation_version = ".".join(str(v) for v in sys.pypy_version_info[:3]) + + print( + "Python {0} ({1}) [{2} {3}]".format( + python_version, + architecture, + implementation, + implementation_version, + ) + ) + + # CPython + else: + print("CPython {0} ({1})".format(python_version, architecture)) + + return 0 + + +if __name__ == "__main__": + sys.exit(main())