Skip to content

Commit 3deabb0

Browse files
Merge pull request #13 from DataDog/darcy.rayner/fix-python-handler-generation
Fix python templating errors
2 parents 5d9a4db + bc284c4 commit 3deabb0

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-plugin-datadog",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"description": "Serverless plugin to automatically instrument python and node functions with datadog tracing",
55
"main": "dist/index.js",
66
"repository": "https://github.com/DataDog/serverless-plugin-datadog",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { pythonTemplate } from "./python-template";
2+
3+
describe("pythonTemplate", () => {
4+
it("handles nested directories", () => {
5+
const result = pythonTemplate("my/file/path", "method");
6+
expect(result).toMatchInlineSnapshot(`
7+
"from datadog_lambda.wrapper import datadog_lambda_wrapper
8+
from my.file.path import method as method_impl
9+
method = datadog_lambda_wrapper(method_impl)"
10+
`);
11+
});
12+
it("handles windows directories", () => {
13+
const result = pythonTemplate(`my\\file\\path`, "method");
14+
expect(result).toMatchInlineSnapshot(`
15+
"from datadog_lambda.wrapper import datadog_lambda_wrapper
16+
from my.file.path import method as method_impl
17+
method = datadog_lambda_wrapper(method_impl)"
18+
`);
19+
});
20+
});

src/templates/python-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
export function pythonTemplate(filePath: string, method: string) {
10-
const newPath = filePath.replace("/", ".").replace("\\", ".");
10+
const newPath = filePath.split(/\/|\\/).join(".");
1111
return `from datadog_lambda.wrapper import datadog_lambda_wrapper
1212
from ${newPath} import ${method} as ${method}_impl
1313
${method} = datadog_lambda_wrapper(${method}_impl)`;

0 commit comments

Comments
 (0)