Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple heuristics to determine python executable name across platforms #2247

Merged
merged 3 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ manually once the init process completes.
To manually create a virtualenv on MacOS and Linux:

```
$ python3 -m venv .env
```

For Windows, use:

```
% python -m venv .env
$ %python-executable% -m venv .env
```

After the init process completes and the virtualenv is created, you can use the following
Expand Down
3 changes: 0 additions & 3 deletions packages/aws-cdk/lib/init-templates/app/python/cdk.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "%python-executable% app.py"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ manually once the init process completes.
To manually create a virtualenv on MacOS and Linux:

```
$ python3 -m venv .env
```

For Windows, use:

```
% python -m venv .env
$ %python-executable% -m venv .env
```

After the init process completes and the virtualenv is created, you can use the following
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "%python-executable% app.py"
}
33 changes: 21 additions & 12 deletions packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export async function cliInit(type?: string, language?: string, canUseNetwork?:
await initializeProject(template, language, canUseNetwork !== undefined ? canUseNetwork : true);
}

/**
*
* @returns the name of the Python executable for this OS
*/
function pythonExecutable() {
let python = 'python3';
if (process.platform == 'win32') {
python = 'python';
}
return python;
}
const INFO_DOT_JSON = 'info.json';

export class InitTemplate {
Expand Down Expand Up @@ -143,7 +154,8 @@ export class InitTemplate {
.replace(/%name\.PascalCased%/g, camelCase(project.name, { pascalCase: true }))
.replace(/%cdk-version%/g, cdkVersion)
.replace(/%cdk-home%/g, CDK_HOME)
.replace(/%name\.PythonModule%/g, project.name.replace(/-/g, '_'));
.replace(/%name\.PythonModule%/g, project.name.replace(/-/g, '_'))
.replace(/%python-executable%/g, pythonExecutable());
}
}

Expand Down Expand Up @@ -233,7 +245,7 @@ async function postInstall(language: string, canUseNetwork: boolean) {
case 'java':
return await postInstallJava(canUseNetwork);
case 'python':
return await postInstallPython(canUseNetwork);
return await postInstallPython();
}
}

Expand Down Expand Up @@ -263,18 +275,15 @@ async function postInstallJava(canUseNetwork: boolean) {
await execute('mvn', 'package');
}

async function postInstallPython(canUseNetwork: boolean) {
if (!canUseNetwork) {
print(`Please run ${colors.green('python -m venv .env')}!`);
return;
}

print(`Executing ${colors.green('python -m venv .env')}`);
async function postInstallPython() {
const python = pythonExecutable();
print(`Executing ${colors.green('Creating virtualenv')}`);
try {
await execute('python3', '-m venv', '.env');
await execute(python, '-m venv', '.env');
} catch (e) {
throw new Error(`${colors.green('python3 -m venv .env')} failed: ` + e.message);
}
print('Unable to create virtualenv automatically');
print(`Please run ${colors.green('python3 -m venv .env')}!`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace "python3" with python

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

}

/**
Expand Down