diff --git a/.projenrc.ts b/.projenrc.ts index df53fff1..6830a4f6 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -214,6 +214,7 @@ new JsonFile(project, '.vscode/settings.json', { '[svg]': { 'editor.defaultFormatter': 'jock.svg', }, + 'python.formatting.provider': 'black', }, }); diff --git a/.vscode/settings.json b/.vscode/settings.json index 8fbe6612..20de4780 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,6 @@ "svg.preview.background": "dark-transparent", "[svg]": { "editor.defaultFormatter": "jock.svg" - } + }, + "python.formatting.provider": "black" } diff --git a/examples/python-app/README.md b/examples/python-app/README.md index 8e59166a..10e7bd31 100644 --- a/examples/python-app/README.md +++ b/examples/python-app/README.md @@ -9,20 +9,20 @@ All interfaces are available, but the esbuild binary must be available in path, To set up a new virtualenv, run -``` -$ python3 -m venv .venv +```bash +python3 -m venv .venv ``` Then activate the venv and install all dependencies: -``` -$ source .venv/bin/activate -$ pip install -r requirements.txt -$ npm install --location=global esbuild +```bash +source .venv/bin/activate +pip install -r requirements.txt -r requirements-dev.txt +npm install -g esbuild ``` -Finally run the CDK app: +Run the CDK app providing the `CDK_ESBUILD_MODULE_PATH`: +```bash +CDK_ESBUILD_MODULE_PATH="$(npm prefix -g)/lib/node_modules/esbuild" cdk synth ``` -$ cdk synth -``` \ No newline at end of file diff --git a/examples/python-app/python_app/python_app_stack.py b/examples/python-app/python_app/python_app_stack.py index 15003420..2b481039 100644 --- a/examples/python-app/python_app/python_app_stack.py +++ b/examples/python-app/python_app/python_app_stack.py @@ -1,3 +1,4 @@ +import os from aws_cdk import Stack import aws_cdk.aws_lambda as lambda_ import aws_cdk.aws_s3 as s3 @@ -19,7 +20,10 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: self, "Website", sources=[ - TypeScriptSource("lambda-handler/index.ts", copy_dir="lambda-handler") + TypeScriptSource( + "lambda-handler/index.ts", + copy_dir="lambda-handler", + ) ], destination_bucket=s3.Bucket( self, @@ -37,6 +41,9 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: build_options=BuildOptions( format="esm", outfile="index.mjs", external=["aws-sdk"] ), + # Override the global setting with a specific path per Construct + # This can be useful if a Construct requires a different version of esbuild + esbuild_module_path="/project/node_modules/esbuild@13", ), ) diff --git a/examples/python-app/requirements-dev.txt b/examples/python-app/requirements-dev.txt index 92709451..a11b8845 100644 --- a/examples/python-app/requirements-dev.txt +++ b/examples/python-app/requirements-dev.txt @@ -1 +1,2 @@ pytest==6.2.5 +black>=22.6.0 diff --git a/examples/python-app/requirements.txt b/examples/python-app/requirements.txt index 639c72f7..ffdc1220 100644 --- a/examples/python-app/requirements.txt +++ b/examples/python-app/requirements.txt @@ -1,3 +1,3 @@ -aws-cdk-lib==2.27.0 +aws-cdk-lib==2.37.1 constructs>=10.0.0,<11.0.0 -mrgrain.cdk-esbuild>=4.0.0 \ No newline at end of file +mrgrain.cdk-esbuild>=3.10.0 \ No newline at end of file