in packages/infrastructure/src/projects/python/infrastructure-py-project.ts [66:182]
constructor(options: InfrastructurePyProjectOptions) {
const moduleName = options.moduleName ?? "infra";
super({
...options,
cdkVersion: options.cdkVersion ?? "2.1.0",
sample: false,
poetry: true,
moduleName,
appEntrypoint: "main.py",
pytest: options.pytest ?? false,
version: options.version ?? "0.0.0",
authorName: options.authorName ?? "pdkuser",
authorEmail: options.authorEmail ?? "user@pdk.com",
name: options.name,
readme: {
contents: fs
.readFileSync(
path.resolve(
__dirname,
"../../../samples/infrastructure/python/README.md"
)
)
.toString(),
},
});
InfrastructureCommands.ensure(this);
["pytest@^7", "syrupy@^4"].forEach((devDep) =>
this.addDevDependency(devDep)
);
["aws_pdk@^0", "cdk_nag@^2", "python@^3.9"].forEach((dep) =>
this.addDependency(dep)
);
const srcDir = path.resolve(
__dirname,
"../../../samples/infrastructure/python/src"
);
const testDir = path.resolve(
__dirname,
"../../../samples/infrastructure/python/test"
);
const typeSafeApis = [
...(options.typeSafeApis || []),
...(options.typeSafeApi ? [options.typeSafeApi] : []),
];
const cloudscapeReactTsWebsites = [
...(options.cloudscapeReactTsWebsites || []),
...(options.cloudscapeReactTsWebsite
? [options.cloudscapeReactTsWebsite]
: []),
];
typeSafeApis.forEach((tsApi) => {
if (!tsApi.infrastructure.python) {
throw new Error(
"Cannot pass in a Type Safe Api without Python Infrastructure configured!"
);
}
NxProject.ensure(this).addPythonPoetryDependency(
tsApi.infrastructure.python
);
// Ensure handlers are built before infra
tsApi.all.handlers?.forEach((handler) => {
NxProject.ensure(this).addImplicitDependency(handler);
});
});
cloudscapeReactTsWebsites.forEach((csWebsite) => {
// Ensure website is built before infra
NxProject.ensure(this).addImplicitDependency(csWebsite);
});
const mustacheConfig = {
stackName: options.stackName || DEFAULT_STACK_NAME,
allowSignup: options.allowSignup ?? false,
moduleName,
typeSafeApis: this.generateTypeSafeMustacheConfig(
moduleName,
typeSafeApis
),
stages: options.stages || [],
cloudscapeReactTsWebsites: cloudscapeReactTsWebsites.map((csWebsite) => {
const websiteName = this.capitalize(
csWebsite.package.packageName
.replace(/[^a-z0-9_]+/gi, "")
.replace(/^[0-9]+/gi, "")
);
return {
websiteName,
websiteNameLowercase: websiteName.toLowerCase(),
websiteDistRelativePath: path.relative(
this.outdir,
`${csWebsite.outdir}/build`
),
typeSafeApis: this.generateTypeSafeMustacheConfig(
moduleName,
csWebsite.typeSafeApis
),
};
}),
};
const tstDir = "tests";
options.sample !== false &&
this.emitSampleFiles(srcDir, [this.moduleName], mustacheConfig);
options.sample !== false &&
this.emitSampleFiles(testDir, [tstDir], mustacheConfig);
this.testTask.reset(
`poetry run pytest ${tstDir}/ \${CI:-'--snapshot-update'}`
);
}