@vercel/python 2.0.6-canary.4 → 2.1.1
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.d.ts +9 -0
- package/dist/index.js +56 -16
- package/dist/install.d.ts +21 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuildOptions, shouldServe } from '@vercel/build-utils';
|
|
2
|
+
import { installRequirement, installRequirementsFile } from './install';
|
|
3
|
+
export declare const version = 3;
|
|
4
|
+
export declare function downloadFilesInWorkPath({ entrypoint, workPath, files, meta, }: BuildOptions): Promise<string>;
|
|
5
|
+
export declare const build: ({ workPath, files: originalFiles, entrypoint, meta, config, }: BuildOptions) => Promise<{
|
|
6
|
+
output: import("@vercel/build-utils").Lambda;
|
|
7
|
+
}>;
|
|
8
|
+
export { shouldServe };
|
|
9
|
+
export { installRequirement, installRequirementsFile };
|
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,41 @@ 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
|
+
const version = (_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;
|
|
3605
|
+
if (!meta.isDev) {
|
|
3606
|
+
if (version === '3.6') {
|
|
3607
|
+
pipPath = 'pip3.6';
|
|
3608
|
+
pythonPath = 'python3.6';
|
|
3609
|
+
pythonRuntime = 'python3.6';
|
|
3610
|
+
console.warn(`Warning: Python version "${version}" detected in Pipfile.lock will reach End-Of-Life December 2021. Please upgrade. http://vercel.link/python-version`);
|
|
3611
|
+
}
|
|
3612
|
+
else if (version === '3.9') {
|
|
3613
|
+
pipPath = 'pip3.9';
|
|
3614
|
+
pythonPath = 'python3.9';
|
|
3615
|
+
pythonRuntime = 'python3.9';
|
|
3616
|
+
}
|
|
3617
|
+
else {
|
|
3618
|
+
console.warn(`Warning: Invalid Python version "${version}" detected in Pipfile.lock will be ignored. http://vercel.link/python-version`);
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
catch (err) {
|
|
3623
|
+
throw new build_utils_1.NowBuildError({
|
|
3624
|
+
code: 'INVALID_PIPFILE_LOCK',
|
|
3625
|
+
message: 'Unable to parse Pipfile.lock',
|
|
3626
|
+
});
|
|
3627
|
+
}
|
|
3594
3628
|
// Convert Pipenv.Lock to requirements.txt.
|
|
3595
3629
|
// We use a different`workPath` here because we want `pipfile-requirements` and it's dependencies
|
|
3596
3630
|
// to not be part of the lambda environment. By using pip's `--target` directive we can isolate
|
|
3597
3631
|
// it into a separate folder.
|
|
3598
3632
|
const tempDir = await build_utils_1.getWriteableDirectory();
|
|
3599
3633
|
await install_1.installRequirement({
|
|
3634
|
+
pythonPath,
|
|
3635
|
+
pipPath,
|
|
3600
3636
|
dependency: 'pipfile-requirements',
|
|
3601
3637
|
version: '0.3.0',
|
|
3602
3638
|
workPath: tempDir,
|
|
@@ -3615,6 +3651,8 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3615
3651
|
build_utils_1.debug('Found local "requirements.txt"');
|
|
3616
3652
|
const requirementsTxtPath = fsFiles[requirementsTxt].fsPath;
|
|
3617
3653
|
await install_1.installRequirementsFile({
|
|
3654
|
+
pythonPath,
|
|
3655
|
+
pipPath,
|
|
3618
3656
|
filePath: requirementsTxtPath,
|
|
3619
3657
|
workPath,
|
|
3620
3658
|
meta,
|
|
@@ -3624,6 +3662,8 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3624
3662
|
build_utils_1.debug('Found global "requirements.txt"');
|
|
3625
3663
|
const requirementsTxtPath = fsFiles['requirements.txt'].fsPath;
|
|
3626
3664
|
await install_1.installRequirementsFile({
|
|
3665
|
+
pythonPath,
|
|
3666
|
+
pipPath,
|
|
3627
3667
|
filePath: requirementsTxtPath,
|
|
3628
3668
|
workPath,
|
|
3629
3669
|
meta,
|
|
@@ -3645,7 +3685,7 @@ const build = async ({ workPath, files: originalFiles, entrypoint, meta = {}, co
|
|
|
3645
3685
|
const handlerPyFilename = 'vc__handler__python';
|
|
3646
3686
|
await writeFile(path_1.join(workPath, `${handlerPyFilename}.py`), handlerPyContents);
|
|
3647
3687
|
// Use the system-installed version of `python3` when running via `vercel dev`
|
|
3648
|
-
const runtime = meta.isDev ? 'python3' :
|
|
3688
|
+
const runtime = meta.isDev ? 'python3' : pythonRuntime;
|
|
3649
3689
|
const globOptions = {
|
|
3650
3690
|
cwd: workPath,
|
|
3651
3691
|
ignore: config && typeof config.excludeFiles === 'string'
|
|
@@ -3677,16 +3717,15 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
3677
3717
|
exports.installRequirementsFile = exports.installRequirement = void 0;
|
|
3678
3718
|
const execa_1 = __importDefault(__webpack_require__(580));
|
|
3679
3719
|
const build_utils_1 = __webpack_require__(445);
|
|
3680
|
-
const pipPath = 'pip3';
|
|
3681
3720
|
const makeDependencyCheckCode = (dependency) => `
|
|
3682
3721
|
from importlib import util
|
|
3683
3722
|
dep = '${dependency}'.replace('-', '_')
|
|
3684
3723
|
spec = util.find_spec(dep)
|
|
3685
3724
|
print(spec.origin)
|
|
3686
3725
|
`;
|
|
3687
|
-
async function isInstalled(dependency, cwd) {
|
|
3726
|
+
async function isInstalled(pythonPath, dependency, cwd) {
|
|
3688
3727
|
try {
|
|
3689
|
-
const { stdout } = await execa_1.default(
|
|
3728
|
+
const { stdout } = await execa_1.default(pythonPath, ['-c', makeDependencyCheckCode(dependency)], {
|
|
3690
3729
|
stdio: 'pipe',
|
|
3691
3730
|
cwd,
|
|
3692
3731
|
});
|
|
@@ -3703,9 +3742,9 @@ from pkg_resources import DistributionNotFound, VersionConflict
|
|
|
3703
3742
|
dependencies = distutils.text_file.TextFile(filename='${requirementsPath}').readlines()
|
|
3704
3743
|
pkg_resources.require(dependencies)
|
|
3705
3744
|
`;
|
|
3706
|
-
async function areRequirementsInstalled(requirementsPath, cwd) {
|
|
3745
|
+
async function areRequirementsInstalled(pythonPath, requirementsPath, cwd) {
|
|
3707
3746
|
try {
|
|
3708
|
-
await execa_1.default(
|
|
3747
|
+
await execa_1.default(pythonPath, ['-c', makeRequirementsCheckCode(requirementsPath)], {
|
|
3709
3748
|
stdio: 'pipe',
|
|
3710
3749
|
cwd,
|
|
3711
3750
|
});
|
|
@@ -3715,7 +3754,7 @@ async function areRequirementsInstalled(requirementsPath, cwd) {
|
|
|
3715
3754
|
return false;
|
|
3716
3755
|
}
|
|
3717
3756
|
}
|
|
3718
|
-
async function pipInstall(workPath, args) {
|
|
3757
|
+
async function pipInstall(pipPath, workPath, args) {
|
|
3719
3758
|
const target = '.';
|
|
3720
3759
|
// See: https://github.com/pypa/pip/issues/4222#issuecomment-417646535
|
|
3721
3760
|
//
|
|
@@ -3732,15 +3771,15 @@ async function pipInstall(workPath, args) {
|
|
|
3732
3771
|
target,
|
|
3733
3772
|
...args,
|
|
3734
3773
|
];
|
|
3735
|
-
|
|
3774
|
+
const pretty = `${pipPath} ${cmdArgs.join(' ')}`;
|
|
3775
|
+
build_utils_1.debug(`Running "${pretty}"...`);
|
|
3736
3776
|
try {
|
|
3737
3777
|
await execa_1.default(pipPath, cmdArgs, {
|
|
3738
3778
|
cwd: workPath,
|
|
3739
|
-
stdio: 'pipe',
|
|
3740
3779
|
});
|
|
3741
3780
|
}
|
|
3742
3781
|
catch (err) {
|
|
3743
|
-
console.log(`Failed to run "
|
|
3782
|
+
console.log(`Failed to run "${pretty}"`);
|
|
3744
3783
|
throw err;
|
|
3745
3784
|
}
|
|
3746
3785
|
}
|
|
@@ -3748,21 +3787,22 @@ async function pipInstall(workPath, args) {
|
|
|
3748
3787
|
// with this function can get overriden by a newer version from requirements.txt,
|
|
3749
3788
|
// so vc_init should do runtime version checks to be compatible with any recent
|
|
3750
3789
|
// version of its dependencies
|
|
3751
|
-
async function installRequirement({ dependency, version, workPath, meta, args = [], }) {
|
|
3752
|
-
if (meta.isDev && (await isInstalled(dependency, workPath))) {
|
|
3790
|
+
async function installRequirement({ pythonPath, pipPath, dependency, version, workPath, meta, args = [], }) {
|
|
3791
|
+
if (meta.isDev && (await isInstalled(pythonPath, dependency, workPath))) {
|
|
3753
3792
|
build_utils_1.debug(`Skipping ${dependency} dependency installation, already installed in ${workPath}`);
|
|
3754
3793
|
return;
|
|
3755
3794
|
}
|
|
3756
3795
|
const exact = `${dependency}==${version}`;
|
|
3757
|
-
await pipInstall(workPath, [exact, ...args]);
|
|
3796
|
+
await pipInstall(pipPath, workPath, [exact, ...args]);
|
|
3758
3797
|
}
|
|
3759
3798
|
exports.installRequirement = installRequirement;
|
|
3760
|
-
async function installRequirementsFile({ filePath, workPath, meta, args = [], }) {
|
|
3761
|
-
if (meta.isDev &&
|
|
3799
|
+
async function installRequirementsFile({ pythonPath, pipPath, filePath, workPath, meta, args = [], }) {
|
|
3800
|
+
if (meta.isDev &&
|
|
3801
|
+
(await areRequirementsInstalled(pythonPath, filePath, workPath))) {
|
|
3762
3802
|
build_utils_1.debug(`Skipping requirements file installation, already installed`);
|
|
3763
3803
|
return;
|
|
3764
3804
|
}
|
|
3765
|
-
await pipInstall(workPath, ['--upgrade', '-r', filePath, ...args]);
|
|
3805
|
+
await pipInstall(pipPath, workPath, ['--upgrade', '-r', filePath, ...args]);
|
|
3766
3806
|
}
|
|
3767
3807
|
exports.installRequirementsFile = installRequirementsFile;
|
|
3768
3808
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Meta } from '@vercel/build-utils';
|
|
2
|
+
interface InstallRequirementArg {
|
|
3
|
+
pythonPath: string;
|
|
4
|
+
pipPath: string;
|
|
5
|
+
dependency: string;
|
|
6
|
+
version: string;
|
|
7
|
+
workPath: string;
|
|
8
|
+
meta: Meta;
|
|
9
|
+
args?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function installRequirement({ pythonPath, pipPath, dependency, version, workPath, meta, args, }: InstallRequirementArg): Promise<void>;
|
|
12
|
+
interface InstallRequirementsFileArg {
|
|
13
|
+
pythonPath: string;
|
|
14
|
+
pipPath: string;
|
|
15
|
+
filePath: string;
|
|
16
|
+
workPath: string;
|
|
17
|
+
meta: Meta;
|
|
18
|
+
args?: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function installRequirementsFile({ pythonPath, pipPath, filePath, workPath, meta, args, }: InstallRequirementsFileArg): Promise<void>;
|
|
21
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/python",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
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": "7d7f3df9805fc92a8f2ef33fafc2b113775b491c"
|
|
28
28
|
}
|