Merge pull request #3 from pdm-project/pep582-path

This commit is contained in:
Frost Ming 2021-04-25 18:13:02 +08:00 committed by GitHub
commit 494e36b1c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 26 deletions

View File

@ -17,11 +17,9 @@ 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: pdm run python test.py
run: python test.py
env:
PYTHON_VERSION: ${{ matrix.python-version }}

View File

@ -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.
...
```

View File

@ -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"

11
dist/setup-pdm.js vendored
View File

@ -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);
}

View File

@ -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",

View File

@ -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<void> {
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');