Skip to content

Commit 878156f

Browse files
Inject LD_LIBRARY_PATH library path into Python manifest install and setup (#144)
* Adding LD_LIBRARY_PATH env var to both setup and install tasks * Rebuild dist/index.js * Fixed some typos in contributors.md Markdown
1 parent c181ffa commit 878156f

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

dist/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -6422,6 +6422,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
64226422
return result;
64236423
};
64246424
Object.defineProperty(exports, "__esModule", { value: true });
6425+
const path = __importStar(__webpack_require__(622));
64256426
const core = __importStar(__webpack_require__(470));
64266427
const tc = __importStar(__webpack_require__(533));
64276428
const exec = __importStar(__webpack_require__(986));
@@ -6432,6 +6433,7 @@ const MANIFEST_REPO_NAME = 'python-versions';
64326433
const MANIFEST_REPO_BRANCH = 'main';
64336434
exports.MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
64346435
const IS_WINDOWS = process.platform === 'win32';
6436+
const IS_LINUX = process.platform === 'linux';
64356437
function findReleaseFromManifest(semanticVersionSpec, architecture) {
64366438
return __awaiter(this, void 0, void 0, function* () {
64376439
const manifest = yield tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
@@ -6443,6 +6445,7 @@ function installPython(workingDirectory) {
64436445
return __awaiter(this, void 0, void 0, function* () {
64446446
const options = {
64456447
cwd: workingDirectory,
6448+
env: Object.assign(Object.assign({}, process.env), IS_LINUX && { 'LD_LIBRARY_PATH': path.join(workingDirectory, 'lib') }),
64466449
silent: true,
64476450
listeners: {
64486451
stdout: (data) => {
@@ -6688,6 +6691,7 @@ const installer = __importStar(__webpack_require__(824));
66886691
const core = __importStar(__webpack_require__(470));
66896692
const tc = __importStar(__webpack_require__(533));
66906693
const IS_WINDOWS = process.platform === 'win32';
6694+
const IS_LINUX = process.platform === 'linux';
66916695
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
66926696
// This is where pip is, along with anything that pip installs.
66936697
// There is a seperate directory for `pip install --user`.
@@ -6760,6 +6764,13 @@ function useCpythonVersion(version, architecture) {
67606764
].join(os.EOL));
67616765
}
67626766
core.exportVariable('pythonLocation', installDir);
6767+
if (IS_LINUX) {
6768+
const libPath = (process.env.LD_LIBRARY_PATH) ? `:${process.env.LD_LIBRARY_PATH}` : '';
6769+
const pyLibPath = path.join(installDir, 'lib');
6770+
if (!libPath.split(':').includes(pyLibPath)) {
6771+
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
6772+
}
6773+
}
67636774
core.addPath(installDir);
67646775
core.addPath(binDir(installDir));
67656776
if (IS_WINDOWS) {

docs/contributors.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ In order to avoid uploading `node_modules/` to the repository, we use [vercel/nc
1313
### Developing
1414

1515
If you're developing locally, you can run
16-
```
16+
17+
```sh
1718
npm install
1819
tsc
1920
ncc build src/setup-python.ts
2021
```
21-
Any files generated using `tsc` will be added to `lib/`, however those files also are not uploaded to the repository and are exluded using `.gitignore`.
22+
23+
Any files generated using `tsc` will be added to `lib/`, however those files also are not uploaded to the repository and are excluded using `.gitignore`.
2224

2325
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) (to run manually, use `npm run format`).
2426

src/find-python.ts

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as core from '@actions/core';
99
import * as tc from '@actions/tool-cache';
1010

1111
const IS_WINDOWS = process.platform === 'win32';
12+
const IS_LINUX = process.platform === 'linux';
1213

1314
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
1415
// This is where pip is, along with anything that pip installs.
@@ -109,6 +110,18 @@ async function useCpythonVersion(
109110
}
110111

111112
core.exportVariable('pythonLocation', installDir);
113+
114+
if (IS_LINUX) {
115+
const libPath = process.env.LD_LIBRARY_PATH
116+
? `:${process.env.LD_LIBRARY_PATH}`
117+
: '';
118+
const pyLibPath = path.join(installDir, 'lib');
119+
120+
if (!libPath.split(':').includes(pyLibPath)) {
121+
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
122+
}
123+
}
124+
112125
core.addPath(installDir);
113126
core.addPath(binDir(installDir));
114127

src/install-python.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const MANIFEST_REPO_BRANCH = 'main';
1313
export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
1414

1515
const IS_WINDOWS = process.platform === 'win32';
16+
const IS_LINUX = process.platform === 'linux';
1617

1718
export async function findReleaseFromManifest(
1819
semanticVersionSpec: string,
@@ -35,6 +36,10 @@ export async function findReleaseFromManifest(
3536
async function installPython(workingDirectory: string) {
3637
const options: ExecOptions = {
3738
cwd: workingDirectory,
39+
env: {
40+
...process.env,
41+
...(IS_LINUX && {LD_LIBRARY_PATH: path.join(workingDirectory, 'lib')})
42+
},
3843
silent: true,
3944
listeners: {
4045
stdout: (data: Buffer) => {

0 commit comments

Comments
 (0)