@vercel/python 2.0.6-canary.5 → 2.0.6-canary.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +44 -16
- package/dist/install.d.ts +6 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3528,6 +3528,7 @@ async function pipenvConvert(cmd, srcDir) {
|
|
|
3528
3528
|
const out = await execa_1.default.stdout(cmd, [], {
|
|
3529
3529
|
cwd: srcDir,
|
|
3530
3530
|
});
|
|
3531
|
+
build_utils_1.debug('Contents of requirements.txt is: ' + out);
|
|
3531
3532
|
fs_1.default.writeFileSync(path_1.join(srcDir, 'requirements.txt'), out);
|
|
3532
3533
|
}
|
|
3533
3534
|
catch (err) {
|
|
@@ -3551,6 +3552,10 @@ async function downloadFilesInWorkPath({ entrypoint, workPath, files, meta = {},
|
|
|
3551
3552
|
}
|
|
3552
3553
|
exports.downloadFilesInWorkPath = downloadFilesInWorkPath;
|
|
3553
3554
|
const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, config, }) => {
|
|
3555
|
+
var _a, _b;
|
|
3556
|
+
let pipPath = meta.isDev ? 'pip3' : 'pip3.9';
|
|
3557
|
+
let pythonPath = meta.isDev ? 'python3' : 'python3.9';
|
|
3558
|
+
let pythonRuntime = meta.isDev ? 'python3' : 'python3.9';
|
|
3554
3559
|
workPath = await downloadFilesInWorkPath({
|
|
3555
3560
|
workPath,
|
|
3556
3561
|
files: originalFiles,
|
|
@@ -3577,6 +3582,8 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3577
3582
|
}
|
|
3578
3583
|
console.log('Installing required dependencies...');
|
|
3579
3584
|
await install_1.installRequirement({
|
|
3585
|
+
pythonPath,
|
|
3586
|
+
pipPath,
|
|
3580
3587
|
dependency: 'werkzeug',
|
|
3581
3588
|
version: '1.0.1',
|
|
3582
3589
|
workPath,
|
|
@@ -3591,12 +3598,29 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3591
3598
|
: null;
|
|
3592
3599
|
if (pipfileLockDir) {
|
|
3593
3600
|
build_utils_1.debug('Found "Pipfile.lock"');
|
|
3601
|
+
try {
|
|
3602
|
+
const json = await readFile(path_1.join(pipfileLockDir, 'Pipfile.lock'), 'utf8');
|
|
3603
|
+
const obj = JSON.parse(json);
|
|
3604
|
+
if (!meta.isDev && ((_b = (_a = obj === null || obj === void 0 ? void 0 : obj._meta) === null || _a === void 0 ? void 0 : _a.requires) === null || _b === void 0 ? void 0 : _b.python_version) === '3.6') {
|
|
3605
|
+
pipPath = 'pip3.6';
|
|
3606
|
+
pythonPath = 'python3.6';
|
|
3607
|
+
pythonRuntime = 'python3.6';
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
catch (err) {
|
|
3611
|
+
throw new build_utils_1.NowBuildError({
|
|
3612
|
+
code: 'INVALID_PIPFILE_LOCK',
|
|
3613
|
+
message: 'Unable to parse Pipfile.lock',
|
|
3614
|
+
});
|
|
3615
|
+
}
|
|
3594
3616
|
// Convert Pipenv.Lock to requirements.txt.
|
|
3595
3617
|
// We use a different`workPath` here because we want `pipfile-requirements` and it's dependencies
|
|
3596
3618
|
// to not be part of the lambda environment. By using pip's `--target` directive we can isolate
|
|
3597
3619
|
// it into a separate folder.
|
|
3598
3620
|
const tempDir = await build_utils_1.getWriteableDirectory();
|
|
3599
3621
|
await install_1.installRequirement({
|
|
3622
|
+
pythonPath,
|
|
3623
|
+
pipPath,
|
|
3600
3624
|
dependency: 'pipfile-requirements',
|
|
3601
3625
|
version: '0.3.0',
|
|
3602
3626
|
workPath: tempDir,
|
|
@@ -3615,6 +3639,8 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3615
3639
|
build_utils_1.debug('Found local "requirements.txt"');
|
|
3616
3640
|
const requirementsTxtPath = fsFiles[requirementsTxt].fsPath;
|
|
3617
3641
|
await install_1.installRequirementsFile({
|
|
3642
|
+
pythonPath,
|
|
3643
|
+
pipPath,
|
|
3618
3644
|
filePath: requirementsTxtPath,
|
|
3619
3645
|
workPath,
|
|
3620
3646
|
meta,
|
|
@@ -3624,6 +3650,8 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3624
3650
|
build_utils_1.debug('Found global "requirements.txt"');
|
|
3625
3651
|
const requirementsTxtPath = fsFiles['requirements.txt'].fsPath;
|
|
3626
3652
|
await install_1.installRequirementsFile({
|
|
3653
|
+
pythonPath,
|
|
3654
|
+
pipPath,
|
|
3627
3655
|
filePath: requirementsTxtPath,
|
|
3628
3656
|
workPath,
|
|
3629
3657
|
meta,
|
|
@@ -3645,7 +3673,7 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3645
3673
|
const handlerPyFilename = 'vc__handler__python';
|
|
3646
3674
|
await writeFile(path_1.join(workPath, `${handlerPyFilename}.py`), handlerPyContents);
|
|
3647
3675
|
// Use the system-installed version of `python3` when running via `vercel dev`
|
|
3648
|
-
const runtime = meta.isDev ? 'python3' :
|
|
3676
|
+
const runtime = meta.isDev ? 'python3' : pythonRuntime;
|
|
3649
3677
|
const globOptions = {
|
|
3650
3678
|
cwd: workPath,
|
|
3651
3679
|
ignore: config && typeof config.excludeFiles === 'string'
|
|
@@ -3677,16 +3705,15 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
3677
3705
|
exports.installRequirementsFile = exports.installRequirement = void 0;
|
|
3678
3706
|
const execa_1 = __importDefault(__webpack_require__(580));
|
|
3679
3707
|
const build_utils_1 = __webpack_require__(445);
|
|
3680
|
-
const pipPath = 'pip3';
|
|
3681
3708
|
const makeDependencyCheckCode = (dependency) => `
|
|
3682
3709
|
from importlib import util
|
|
3683
3710
|
dep = '${dependency}'.replace('-', '_')
|
|
3684
3711
|
spec = util.find_spec(dep)
|
|
3685
3712
|
print(spec.origin)
|
|
3686
3713
|
`;
|
|
3687
|
-
async function isInstalled(dependency, cwd) {
|
|
3714
|
+
async function isInstalled(pythonPath, dependency, cwd) {
|
|
3688
3715
|
try {
|
|
3689
|
-
const { stdout } = await execa_1.default(
|
|
3716
|
+
const { stdout } = await execa_1.default(pythonPath, ['-c', makeDependencyCheckCode(dependency)], {
|
|
3690
3717
|
stdio: 'pipe',
|
|
3691
3718
|
cwd,
|
|
3692
3719
|
});
|
|
@@ -3703,9 +3730,9 @@ from pkg_resources import DistributionNotFound, VersionConflict
|
|
|
3703
3730
|
dependencies = distutils.text_file.TextFile(filename='${requirementsPath}').readlines()
|
|
3704
3731
|
pkg_resources.require(dependencies)
|
|
3705
3732
|
`;
|
|
3706
|
-
async function areRequirementsInstalled(requirementsPath, cwd) {
|
|
3733
|
+
async function areRequirementsInstalled(pythonPath, requirementsPath, cwd) {
|
|
3707
3734
|
try {
|
|
3708
|
-
await execa_1.default(
|
|
3735
|
+
await execa_1.default(pythonPath, ['-c', makeRequirementsCheckCode(requirementsPath)], {
|
|
3709
3736
|
stdio: 'pipe',
|
|
3710
3737
|
cwd,
|
|
3711
3738
|
});
|
|
@@ -3715,7 +3742,7 @@ async function areRequirementsInstalled(requirementsPath, cwd) {
|
|
|
3715
3742
|
return false;
|
|
3716
3743
|
}
|
|
3717
3744
|
}
|
|
3718
|
-
async function pipInstall(workPath, args) {
|
|
3745
|
+
async function pipInstall(pipPath, workPath, args) {
|
|
3719
3746
|
const target = '.';
|
|
3720
3747
|
// See: https://github.com/pypa/pip/issues/4222#issuecomment-417646535
|
|
3721
3748
|
//
|
|
@@ -3732,15 +3759,15 @@ async function pipInstall(workPath, args) {
|
|
|
3732
3759
|
target,
|
|
3733
3760
|
...args,
|
|
3734
3761
|
];
|
|
3735
|
-
|
|
3762
|
+
const pretty = `${pipPath} ${cmdArgs.join(' ')}`;
|
|
3763
|
+
build_utils_1.debug(`Running "${pretty}"...`);
|
|
3736
3764
|
try {
|
|
3737
3765
|
await execa_1.default(pipPath, cmdArgs, {
|
|
3738
3766
|
cwd: workPath,
|
|
3739
|
-
stdio: 'pipe',
|
|
3740
3767
|
});
|
|
3741
3768
|
}
|
|
3742
3769
|
catch (err) {
|
|
3743
|
-
console.log(`Failed to run "
|
|
3770
|
+
console.log(`Failed to run "${pretty}"`);
|
|
3744
3771
|
throw err;
|
|
3745
3772
|
}
|
|
3746
3773
|
}
|
|
@@ -3748,21 +3775,22 @@ async function pipInstall(workPath, args) {
|
|
|
3748
3775
|
// with this function can get overriden by a newer version from requirements.txt,
|
|
3749
3776
|
// so vc_init should do runtime version checks to be compatible with any recent
|
|
3750
3777
|
// version of its dependencies
|
|
3751
|
-
async function installRequirement({ dependency, version, workPath, meta, args = [], }) {
|
|
3752
|
-
if (meta.isDev && (await isInstalled(dependency, workPath))) {
|
|
3778
|
+
async function installRequirement({ pythonPath, pipPath, dependency, version, workPath, meta, args = [], }) {
|
|
3779
|
+
if (meta.isDev && (await isInstalled(pythonPath, dependency, workPath))) {
|
|
3753
3780
|
build_utils_1.debug(`Skipping ${dependency} dependency installation, already installed in ${workPath}`);
|
|
3754
3781
|
return;
|
|
3755
3782
|
}
|
|
3756
3783
|
const exact = `${dependency}==${version}`;
|
|
3757
|
-
await pipInstall(workPath, [exact, ...args]);
|
|
3784
|
+
await pipInstall(pipPath, workPath, [exact, ...args]);
|
|
3758
3785
|
}
|
|
3759
3786
|
exports.installRequirement = installRequirement;
|
|
3760
|
-
async function installRequirementsFile({ filePath, workPath, meta, args = [], }) {
|
|
3761
|
-
if (meta.isDev &&
|
|
3787
|
+
async function installRequirementsFile({ pythonPath, pipPath, filePath, workPath, meta, args = [], }) {
|
|
3788
|
+
if (meta.isDev &&
|
|
3789
|
+
(await areRequirementsInstalled(pythonPath, filePath, workPath))) {
|
|
3762
3790
|
build_utils_1.debug(`Skipping requirements file installation, already installed`);
|
|
3763
3791
|
return;
|
|
3764
3792
|
}
|
|
3765
|
-
await pipInstall(workPath, ['--upgrade', '-r', filePath, ...args]);
|
|
3793
|
+
await pipInstall(pipPath, workPath, ['--upgrade', '-r', filePath, ...args]);
|
|
3766
3794
|
}
|
|
3767
3795
|
exports.installRequirementsFile = installRequirementsFile;
|
|
3768
3796
|
|
package/dist/install.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Meta } from '@vercel/build-utils';
|
|
2
2
|
interface InstallRequirementArg {
|
|
3
|
+
pythonPath: string;
|
|
4
|
+
pipPath: string;
|
|
3
5
|
dependency: string;
|
|
4
6
|
version: string;
|
|
5
7
|
workPath: string;
|
|
6
8
|
meta: Meta;
|
|
7
9
|
args?: string[];
|
|
8
10
|
}
|
|
9
|
-
export declare function installRequirement({ dependency, version, workPath, meta, args, }: InstallRequirementArg): Promise<void>;
|
|
11
|
+
export declare function installRequirement({ pythonPath, pipPath, dependency, version, workPath, meta, args, }: InstallRequirementArg): Promise<void>;
|
|
10
12
|
interface InstallRequirementsFileArg {
|
|
13
|
+
pythonPath: string;
|
|
14
|
+
pipPath: string;
|
|
11
15
|
filePath: string;
|
|
12
16
|
workPath: string;
|
|
13
17
|
meta: Meta;
|
|
14
18
|
args?: string[];
|
|
15
19
|
}
|
|
16
|
-
export declare function installRequirementsFile({ filePath, workPath, meta, args, }: InstallRequirementsFileArg): Promise<void>;
|
|
20
|
+
export declare function installRequirementsFile({ pythonPath, pipPath, filePath, workPath, meta, args, }: InstallRequirementsFileArg): Promise<void>;
|
|
17
21
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/python",
|
|
3
|
-
"version": "2.0.6-canary.
|
|
3
|
+
"version": "2.0.6-canary.6",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"execa": "^1.0.0",
|
|
25
25
|
"typescript": "4.3.4"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "4aa6a139127e4e57469d4b6785546ccb49ca188b"
|
|
28
28
|
}
|