Skip to content

Commit

Permalink
[python] Fix error message for discontinued Python 3.6 (#8300)
Browse files Browse the repository at this point in the history
This fixes the error message when a discontinued version of python (for example, Python 3.6) is detected.

https://vercel.com/changelog/python-3-6-is-being-deprecated
  • Loading branch information
styfle committed Aug 3, 2022
1 parent 21ff4a5 commit 73446e5
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/python/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,28 @@ export const build = async ({
if (pipfileLockDir) {
debug('Found "Pipfile.lock"');

let lock: {
_meta?: {
requires?: {
python_version?: string;
};
};
} = {};
try {
const json = await readFile(join(pipfileLockDir, 'Pipfile.lock'), 'utf8');
const obj = JSON.parse(json);
pythonVersion = getSupportedPythonVersion({
isDev: meta.isDev,
pipLockPythonVersion: obj?._meta?.requires?.python_version,
});
lock = JSON.parse(json);
} catch (err) {
throw new NowBuildError({
code: 'INVALID_PIPFILE_LOCK',
message: 'Unable to parse Pipfile.lock',
});
}

pythonVersion = getSupportedPythonVersion({
isDev: meta.isDev,
pipLockPythonVersion: lock?._meta?.requires?.python_version,
});

// Convert Pipenv.Lock to requirements.txt.
// We use a different`workPath` here because we want `pipfile-requirements` and it's dependencies
// to not be part of the lambda environment. By using pip's `--target` directive we can isolate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blarg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from http.server import BaseHTTPRequestHandler, HTTPServer

class handler(BaseHTTPRequestHandler):

def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/plain')
self.end_headers()
self.wfile.write(self.path.encode())
return
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
cowpy = "*"

[requires]
python_version = "3.6"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from http.server import BaseHTTPRequestHandler
from cowpy import cow


class handler(BaseHTTPRequestHandler):

def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
message = cow.Cowacter().milk('pip:RANDOMNESS_PLACEHOLDER')
self.wfile.write(message.encode())
return
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
22 changes: 22 additions & 0 deletions packages/python/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,30 @@ it('should match the probes against Python dev servers', async () => {
}
});

const testsThatFailToBuild = new Map([
['30-fail-build-invalid-pipfile', 'Unable to parse Pipfile.lock'],
[
'31-fail-build-invalid-python36',
'Python version "3.6" detected in Pipfile.lock is discontinued and must be upgraded.',
],
]);

// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
const errMsg = testsThatFailToBuild.get(fixture);
if (errMsg) {
// eslint-disable-next-line no-loop-func
it(`should fail to build ${fixture}`, async () => {
try {
await testDeployment(path.join(fixturesPath, fixture));
} catch (err) {
expect(err).toBeTruthy();
expect(err.deployment).toBeTruthy();
expect(err.deployment.errorMessage).toBe(errMsg);
}
});
continue; //eslint-disable-line
}
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
Expand Down

0 comments on commit 73446e5

Please sign in to comment.