-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
packages/aws-cdk/lib/init-templates/app/python/cdk.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "%python-executable% app.py" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/aws-cdk/lib/init-templates/sample-app/python/cdk.json
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
packages/aws-cdk/lib/init-templates/sample-app/python/cdk.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "%python-executable% app.py" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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()); | ||
} | ||
} | ||
|
||
|
@@ -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(); | ||
} | ||
} | ||
|
||
|
@@ -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')}!`); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace
"python3"
withpython