Skip to content

Commit

Permalink
Merge pull request #270 from jsteinich/win_python
Browse files Browse the repository at this point in the history
Windows Python fixes
  • Loading branch information
skorfmann authored Aug 24, 2020
2 parents d62599d + 8073738 commit 8b17ea7
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- name: create bundle
run: yarn package
- name: Upload dist
if: ${{ matrix.terraform == '0.12.29' }}
uses: actions/upload-artifact@v2
with:
name: dist
Expand Down Expand Up @@ -76,6 +77,8 @@ jobs:
with:
terraform_wrapper: false
terraform_version: ${{ matrix.terraform }}
- name: Install pipenv
run: pip install pipenv
- name: Download dist
uses: actions/download-artifact@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion examples/python/aws-eks/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": [
"aws@~> 2.55"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/python/aws/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": ["aws@~> 2.0"],
"terraformModules": ["terraform-aws-modules/vpc/aws"],
"codeMakerOutput": "imports"
Expand Down
2 changes: 1 addition & 1 deletion examples/python/docker/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": [
"terraform-providers/docker@~> 2.0"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/python/kubernetes/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": ["kubernetes@~> 1.11.3"],
"codeMakerOutput": "imports"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"build": "lerna run --scope cdktf* build",
"package": "lerna run package && tools/collect-dist.sh",
"package-windows": "lerna run package && tools\\collect-dist.bat",
"examples:reinstall": "lerna run --parallel --scope @examples/* reinstall",
"examples:build": "lerna run --parallel --scope @examples/* build",
"examples:synth": "lerna run --parallel --scope @examples/* synth",
Expand All @@ -13,7 +14,7 @@
"watch": "lerna run --parallel --stream --scope cdktf* watch-preserve-output",
"link-packages": "lerna exec --scope cdktf* yarn link",
"integration": "test/run-against-dist test/test-all.sh",
"integration-windows": "test\\run-against-dist.bat \"node test\\test-typescript-deploy\\test.js\"",
"integration-windows": "test\\run-against-dist.bat test\\test-all.bat",
"release-github": "tools/release-github.sh",
"build-docker-jsii": "docker build -t hashicorp/jsii-terraform .",
"push-docker-jsii": "docker push hashicorp/jsii-terraform"
Expand Down
12 changes: 9 additions & 3 deletions packages/cdktf-cli/templates/python/.hooks.sscaff.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const { execSync } = require('child_process');
const { chmodSync } = require('fs');
const { readFileSync, writeFileSync } = require('fs');
const os = require('os');

const cli = require.resolve('../../bin/cdktf');

exports.pre = () => {
try {
execSync('which pipenv')
if (os.platform() === 'win32') {
execSync('where pipenv')
}
else {
execSync('which pipenv')
}
} catch {
console.error(`Unable to find "pipenv". Install from https://pipenv.kennethreitz.org`)
process.exit(1);
Expand All @@ -29,8 +35,8 @@ exports.post = options => {
execSync(`pipenv install ${pypi_cdktf}`, { stdio: 'inherit' });
chmodSync('main.py', '700');

execSync(`${cli} get`, { stdio: 'inherit' });
execSync(`pipenv run ./main.py`);
execSync(`\"${process.execPath}\" ${cli} get`, { stdio: 'inherit' });
execSync(`pipenv run python main.py`);

console.log(readFileSync('./help', 'utf-8'));
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cdktf-cli/templates/python/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ url = "https://pypi.org/simple"
verify_ssl = true

[requires]
python_version = "3.7"
python_version = "3"
2 changes: 1 addition & 1 deletion packages/cdktf-cli/templates/python/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": ["aws@~> 2.0"],
"codeMakerOutput": "imports"
}
17 changes: 17 additions & 0 deletions test/test-all.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion

cd /D %~dp0

for /d %%d in ("test-*") do (
if exist "%%d\" (
if exist "%%d\test.js" (
echo --------------------------------------------------------------------
echo %%d
echo --------------------------------------------------------------------
call node "%%d\test.js"
IF !ERRORLEVEL! NEQ 0 exit /B 1
)
)
)
2 changes: 1 addition & 1 deletion test/test-python-app/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": ["aws@~> 2.0"],
"terraformModules": ["terraform-aws-modules/vpc/[email protected]"],
"codeMakerOutput": "imports"
Expand Down
42 changes: 42 additions & 0 deletions test/test-python-app/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { execSync } = require('child_process');
const os = require('os');
const path = require('path');
const fs = require('fs');

const env = Object.assign({}, process.env);
// Disable spinner even when we have a TTY
env['CI'] = '1';

const scriptdir = __dirname;

const projectPath = path.join(os.tmpdir(), 'test');
const folder = fs.mkdtempSync(projectPath);
process.chdir(folder);

// initialize an empty project
execSync(`cdktf init --template python --project-name="python-test" --project-description="python test app" --local`, { stdio: 'inherit', env });

// put some code in it
fs.copyFileSync(path.join(scriptdir, 'main.py'), 'main.py');
fs.copyFileSync(path.join(scriptdir, 'cdktf.json'), 'cdktf.json');

fs.rmdirSync('cdktf.out', { recursive: true });

// regenerate with module
execSync(`cdktf get`, { stdio: 'inherit', env });

// build
execSync('pipenv run python main.py', { stdio: 'inherit', env })

// get rid of downloaded Terraform providers, no point in diffing them
fs.rmdirSync('cdktf.out/.terraform', { recursive: true });

// show output
if (os.platform() === 'win32') {
execSync(`fc cdktf.out\\* ${scriptdir}\\expected\\*`, { stdio: 'inherit', env });
}
else {
execSync(`diff cdktf.out ${scriptdir}/expected`, { stdio: 'inherit', env });
}

console.log('PASS');
2 changes: 1 addition & 1 deletion test/test-python-third-party-provider/cdktf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"language": "python",
"app": "pipenv run ./main.py",
"app": "pipenv run python main.py",
"terraformProviders": [
"terraform-providers/docker@~> 2.0"
],
Expand Down
15 changes: 15 additions & 0 deletions tools/collect-dist.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion

cd /D %~dp0\..

rmdir /Q /S dist
mkdir dist

for /f %%f in ('yarn lerna ls -p') do (
if exist "%%f\dist\" (
echo "collecting from %%f\dist
xcopy /E %%f\dist\ dist\
)
)

0 comments on commit 8b17ea7

Please sign in to comment.