From 17ba29ad715498268ee29e36a62fba0a671c91f4 Mon Sep 17 00:00:00 2001 From: Mitch Garnaat Date: Sun, 7 Apr 2019 08:09:02 -0700 Subject: [PATCH] Fixing issues #2180 and #2183 related to Python init templates (#2189) * Fixing issues #2180 and #2183 related to Python init templates * Add some instructions for manually creating a virtualenv --- .../%name.PythonModule%_stack.template.py} | 0 .../__init__.py | 0 .../lib/init-templates/app/python/README.md | 31 +++++++++++++++++-- .../init-templates/app/python/app.template.py | 4 +-- .../app/python/setup.template.py | 6 ++-- .../sample-app/python/README.md | 31 +++++++++++++++++-- packages/aws-cdk/lib/init.ts | 3 +- 7 files changed, 65 insertions(+), 10 deletions(-) rename packages/aws-cdk/lib/init-templates/app/python/{%name%/%name%_stack.template.py => %name.PythonModule%/%name.PythonModule%_stack.template.py} (100%) rename packages/aws-cdk/lib/init-templates/app/python/{%name% => %name.PythonModule%}/__init__.py (100%) diff --git a/packages/aws-cdk/lib/init-templates/app/python/%name%/%name%_stack.template.py b/packages/aws-cdk/lib/init-templates/app/python/%name.PythonModule%/%name.PythonModule%_stack.template.py similarity index 100% rename from packages/aws-cdk/lib/init-templates/app/python/%name%/%name%_stack.template.py rename to packages/aws-cdk/lib/init-templates/app/python/%name.PythonModule%/%name.PythonModule%_stack.template.py diff --git a/packages/aws-cdk/lib/init-templates/app/python/%name%/__init__.py b/packages/aws-cdk/lib/init-templates/app/python/%name.PythonModule%/__init__.py similarity index 100% rename from packages/aws-cdk/lib/init-templates/app/python/%name%/__init__.py rename to packages/aws-cdk/lib/init-templates/app/python/%name.PythonModule%/__init__.py diff --git a/packages/aws-cdk/lib/init-templates/app/python/README.md b/packages/aws-cdk/lib/init-templates/app/python/README.md index f033c0c7602ff..b6059e6d85872 100644 --- a/packages/aws-cdk/lib/init-templates/app/python/README.md +++ b/packages/aws-cdk/lib/init-templates/app/python/README.md @@ -6,12 +6,39 @@ This is a blank project for Python development with CDK. The `cdk.json` file tells the CDK Toolkit how to execute your app. This project is set up like a standard Python project. The initialization process also creates -a virtualenv within this project, stored under the .env directory. +a virtualenv within this project, stored under the .env directory. To create the virtualenv +it assumes that there is a `python3` executable in your path with access to the `venv` package. +If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv +manually once the init process completes. -After the init process completes, you can use the following steps to get your project set up. +To manually create a virtualenv on MacOS and Linux: + +``` +$ python3 -m venv .env +``` + +For Windows, use: + +``` +% python -m venv .env +``` + +After the init process completes and the virtualenv is created, you can use the following +step to activate your virtualenv. ``` $ source .env/bin/activate +``` + +If you are a Windows platform, you would activate the virtualenv like this: + +``` +% .env\Scripts\activate.bat +``` + +Once the virtualenv is activated, you can install the required dependencies. + +``` $ pip install -r requirements.txt ``` diff --git a/packages/aws-cdk/lib/init-templates/app/python/app.template.py b/packages/aws-cdk/lib/init-templates/app/python/app.template.py index 0a194f9bd131b..809e0f20b9208 100644 --- a/packages/aws-cdk/lib/init-templates/app/python/app.template.py +++ b/packages/aws-cdk/lib/init-templates/app/python/app.template.py @@ -2,10 +2,10 @@ from aws_cdk import cdk -from %name%.%name%_stack import PyStack +from %name.PythonModule%.%name.PythonModule%_stack import %name.PascalCased%Stack app = cdk.App() -PyStack(app, "%name%-cdk-1") +%name.PascalCased%Stack(app, "%name%-cdk-1") app.run() diff --git a/packages/aws-cdk/lib/init-templates/app/python/setup.template.py b/packages/aws-cdk/lib/init-templates/app/python/setup.template.py index 0c0c8dc267231..d43176bdf3b08 100644 --- a/packages/aws-cdk/lib/init-templates/app/python/setup.template.py +++ b/packages/aws-cdk/lib/init-templates/app/python/setup.template.py @@ -6,7 +6,7 @@ setuptools.setup( - name="%name%", + name="%name.PythonModule%", version="0.0.1", description="An empty CDK Python app", @@ -15,8 +15,8 @@ author="author", - package_dir={"": "%name%"}, - packages=setuptools.find_packages(where="%name%"), + package_dir={"": "%name.PythonModule%"}, + packages=setuptools.find_packages(where="%name.PythonModule%"), install_requires=[ "aws-cdk.cdk", diff --git a/packages/aws-cdk/lib/init-templates/sample-app/python/README.md b/packages/aws-cdk/lib/init-templates/sample-app/python/README.md index a475424f8bbff..05d3afbd3ef95 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/python/README.md +++ b/packages/aws-cdk/lib/init-templates/sample-app/python/README.md @@ -7,12 +7,39 @@ a stack (`HelloStack`) which also uses a user-defined construct (`HelloConstruct The `cdk.json` file tells the CDK Toolkit how to execute your app. This project is set up like a standard Python project. The initialization process also creates -a virtualenv within this project, stored under the .env directory. +a virtualenv within this project, stored under the .env directory. To create the virtualenv +it assumes that there is a `python3` executable in your path with access to the `venv` package. +If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv +manually once the init process completes. -After the init process completes, you can use the following steps to get your project set up. +To manually create a virtualenv on MacOS and Linux: + +``` +$ python3 -m venv .env +``` + +For Windows, use: + +``` +% python -m venv .env +``` + +After the init process completes and the virtualenv is created, you can use the following +step to activate your virtualenv. ``` $ source .env/bin/activate +``` + +If you are a Windows platform, you would activate the virtualenv like this: + +``` +% .env\Scripts\activate.bat +``` + +Once the virtualenv is activated, you can install the required dependencies. + +``` $ pip install -r requirements.txt ``` diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index c869ee55eaa3e..e469467ca1c68 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -142,7 +142,8 @@ export class InitTemplate { .replace(/%name\.camelCased%/g, camelCase(project.name)) .replace(/%name\.PascalCased%/g, camelCase(project.name, { pascalCase: true })) .replace(/%cdk-version%/g, cdkVersion) - .replace(/%cdk-home%/g, CDK_HOME); + .replace(/%cdk-home%/g, CDK_HOME) + .replace(/%name\.PythonModule%/g, project.name.replace(/-/g, '_')); } }