From fa9dec177539542ac5de17cc8ac5b1477f92bd40 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sun, 25 Apr 2021 18:06:43 +0800 Subject: [PATCH 1/2] Enable PEP582 by default --- .github/workflows/ci.yml | 2 +- action.yml | 11 +++++++++- dist/setup-pdm.js | 11 ++++++++++ package.json | 6 ++--- src/setup-pdm.ts | 47 +++++++++++++++++++++++++--------------- 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c8e0eb..feada79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,6 @@ jobs: LD_PRELOAD: /lib/x86_64-linux-gnu/libgcc_s.so.1 - name: Verify python version - run: pdm run python test.py + run: python test.py env: PYTHON_VERSION: ${{ matrix.python-version }} diff --git a/action.yml b/action.yml index 4c0dc78..8fa3175 100644 --- a/action.yml +++ b/action.yml @@ -6,16 +6,25 @@ inputs: python-version: description: "Version range or exact version of a Python version to use, using SemVer's version range syntax." default: "3.x" + required: true architecture: description: "The target architecture (x86, x64) of the Python interpreter." + required: false token: description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user. default: ${{ github.token }} + required: false version: description: The version of PDM to install. + required: false prerelease: description: Allow prerelease versions to be installed - default: false + default: 'false' + required: false + enable-pep582: + description: "Enable PEP 582 package loading globally." + default: 'true' + required: false runs: using: "node12" main: "dist/setup-pdm.js" diff --git a/dist/setup-pdm.js b/dist/setup-pdm.js index f2f34e3..d4e9ae7 100644 --- a/dist/setup-pdm.js +++ b/dist/setup-pdm.js @@ -6168,6 +6168,14 @@ var os2 = __toModule(require("os")); var import_child_process = __toModule(require("child_process")); var import_path = __toModule(require("path")); var INSTALL_VERSION = "3.8"; +function getPep582Path() { + const installDir = process.env.pythonLocation || ""; + if (IS_WINDOWS) { + return import_path.default.resolve(installDir, "Lib/site-packages/pdm/pep582"); + } else { + return import_path.default.resolve(installDir, "lib", `python${INSTALL_VERSION}`, "site-packages/pdm/pep582"); + } +} async function run() { const arch2 = core3.getInput("architecture") || os2.arch(); const pdmVersion = core3.getInput("version"); @@ -6179,6 +6187,9 @@ async function run() { try { let installedPython = await findPythonVersion(INSTALL_VERSION, arch2); await exec3.exec("python", cmdArgs); + if (core3.getInput("enable-pep582") === "true") { + core3.exportVariable("PYTHONPATH", getPep582Path()); + } if (core3.getInput("python-version") !== INSTALL_VERSION) { installedPython = await findPythonVersion(core3.getInput("python-version"), arch2); } diff --git a/package.json b/package.json index 6e0b688..9617ab6 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "pdm-action", + "name": "setup-pdm", "version": "1.0.0", "description": "The GitHub Action for using pdm as the package manager", - "main": "src/index.js", + "main": "dist/setup-pdm.js", "scripts": { "build": "esbuild src/setup-pdm.ts --bundle --platform=node --outfile=dist/setup-pdm.js" }, "repository": { "type": "git", - "url": "git+https://github.com/pdm-project/pdm-action.git" + "url": "git+https://github.com/pdm-project/setup-pdm.git" }, "dependencies": { "@actions/core": "^1.2.6", diff --git a/src/setup-pdm.ts b/src/setup-pdm.ts index 335e0cb..83357f7 100644 --- a/src/setup-pdm.ts +++ b/src/setup-pdm.ts @@ -1,31 +1,44 @@ -import * as core from "@actions/core"; -import * as exec from "@actions/exec"; -import * as setupPython from "setup-python/src/find-python"; -import * as os from "os"; -import { exec as execChild } from "child_process"; -import path from "path"; +import * as core from '@actions/core'; +import * as exec from '@actions/exec'; +import * as setupPython from 'setup-python/src/find-python'; +import {IS_WINDOWS} from 'setup-python/src/utils' +import * as os from 'os'; +import { exec as execChild } from 'child_process'; +import path from 'path'; -const INSTALL_VERSION = "3.8"; +const INSTALL_VERSION = '3.8'; + +function getPep582Path(): string { + const installDir = process.env.pythonLocation || ''; + if (IS_WINDOWS) { + return path.resolve(installDir, 'Lib/site-packages/pdm/pep582'); + } else { + return path.resolve(installDir, 'lib', `python${INSTALL_VERSION}`, 'site-packages/pdm/pep582'); + } +} async function run(): Promise { - const arch = core.getInput("architecture") || os.arch(); - const pdmVersion = core.getInput("version"); - const pdmPackage = pdmVersion ? `pdm==${pdmVersion}` : "pdm"; - const cmdArgs = ["-m", "pip", "install", "-U", pdmPackage]; - if (core.getInput("prerelease") === 'true') { - cmdArgs.push("--pre"); + const arch = core.getInput('architecture') || os.arch(); + const pdmVersion = core.getInput('version'); + const pdmPackage = pdmVersion ? `pdm==${pdmVersion}` : 'pdm'; + const cmdArgs = ['-m', 'pip', 'install', '-U', pdmPackage]; + if (core.getInput('prerelease') === 'true') { + cmdArgs.push('--pre'); } try { let installedPython = await setupPython.findPythonVersion(INSTALL_VERSION, arch); - await exec.exec("python", cmdArgs); + await exec.exec('python', cmdArgs); + if (core.getInput('enable-pep582') === 'true') { + core.exportVariable('PYTHONPATH', getPep582Path()); + } if (core.getInput('python-version') !== INSTALL_VERSION) { installedPython = await setupPython.findPythonVersion( - core.getInput("python-version"), + core.getInput('python-version'), arch ); } - await exec.exec("pdm", ["use", "-f", installedPython.version]); - const pdmVersionOutput = (await execChild("pdm --version")).stdout; + await exec.exec('pdm', ['use', '-f', installedPython.version]); + const pdmVersionOutput = (await execChild('pdm --version')).stdout; if (process.platform === 'linux') { // See https://github.com/actions/virtual-environments/issues/2803 core.exportVariable('LD_PRELOAD', '/lib/x86_64-linux-gnu/libgcc_s.so.1'); From 82a98a79c0e75a3d0b0826ca3b5988cb414af3e3 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sun, 25 Apr 2021 18:11:39 +0800 Subject: [PATCH 2/2] Update README.md --- .github/workflows/ci.yml | 4 +--- README.md | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feada79..142722a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies - run: pdm install -d -v - env: - LD_PRELOAD: /lib/x86_64-linux-gnu/libgcc_s.so.1 + run: pdm install -v - name: Verify python version run: python test.py diff --git a/README.md b/README.md index b27398a..040741e 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,9 @@ steps: architecture: x64 # The target architecture (x86, x64) of the Python interpreter. the same as actions/setup-python version: 1.4.0 # The version of PDM to install. Leave it as empty to use the latest version from PyPI prerelease: true # Allow prerelease versions to be installed + enable-pep582: true # Enable PEP 582 package loading globally - name: Install dependencies - run: pdm install -d # Then you can use pdm in the following steps. + run: pdm install # Then you can use pdm in the following steps. ... ```