Skip to content

Commit 47fec42

Browse files
authored
feat(onboarding): add poetry as an option to python install snippets (#90365)
1 parent 84addea commit 47fec42

File tree

14 files changed

+62
-29
lines changed

14 files changed

+62
-29
lines changed

static/app/gettingStartedDocs/python/bottle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const onboarding: OnboardingConfig = {
7272
code: <code />,
7373
}
7474
),
75-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[bottle]'"}),
75+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[bottle]'}),
7676
},
7777
],
7878
configure: (params: Params) => [

static/app/gettingStartedDocs/python/celery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const onboarding: OnboardingConfig = {
7272
code: <code />,
7373
}
7474
),
75-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[celery]'"}),
75+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[celery]'}),
7676
},
7777
],
7878
configure: (params: Params) => [

static/app/gettingStartedDocs/python/chalice.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const onboarding: OnboardingConfig = {
7777
code: <code />,
7878
}
7979
),
80-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[chalice]'"}),
80+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[chalice]'}),
8181
},
8282
],
8383
configure: (params: Params) => [

static/app/gettingStartedDocs/python/django.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const onboarding: OnboardingConfig = {
6868
code: <code />,
6969
}
7070
),
71-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[django]'"}),
71+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[django]'}),
7272
},
7373
],
7474
configure: (params: Params) => [

static/app/gettingStartedDocs/python/falcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const onboarding: OnboardingConfig = {
7373
code: <code />,
7474
}
7575
),
76-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[falcon]'"}),
76+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[falcon]'}),
7777
},
7878
],
7979
configure: (params: Params) => [

static/app/gettingStartedDocs/python/fastapi.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const onboarding: OnboardingConfig = {
7575
code: <code />,
7676
}
7777
),
78-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[fastapi]'"}),
78+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[fastapi]'}),
7979
},
8080
],
8181
configure: (params: Params) => [

static/app/gettingStartedDocs/python/flask.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const onboarding: OnboardingConfig = {
7474
code: <code />,
7575
}
7676
),
77-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[flask]'"}),
77+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[flask]'}),
7878
},
7979
],
8080
configure: (params: Params) => [

static/app/gettingStartedDocs/python/mongo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const onboarding: OnboardingConfig = {
4747
code: <code />,
4848
}
4949
),
50-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[pymongo]'"}),
50+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[pymongo]'}),
5151
},
5252
],
5353
configure: (params: Params) => [

static/app/gettingStartedDocs/python/quart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const onboarding: OnboardingConfig = {
7575
code: <code />,
7676
}
7777
),
78-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[quart]'"}),
78+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[quart]'}),
7979
},
8080
],
8181
configure: (params: Params) => [

static/app/gettingStartedDocs/python/rq.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const onboarding: OnboardingConfig = {
101101
description: tct('Install [code:sentry-sdk] from PyPI with the [code:rq] extra:', {
102102
code: <code />,
103103
}),
104-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[rq]'"}),
104+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[rq]'}),
105105
},
106106
],
107107
configure: (params: Params) => [

static/app/gettingStartedDocs/python/sanic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const onboarding: OnboardingConfig = {
4848
}
4949
),
5050
configurations: [
51-
...getPythonInstallConfig({packageName: "'sentry-sdk[sanic]'"}),
51+
...getPythonInstallConfig({packageName: 'sentry-sdk[sanic]'}),
5252
...getPythonAiocontextvarsConfig(),
5353
],
5454
},

static/app/gettingStartedDocs/python/starlette.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const onboarding: OnboardingConfig = {
7373
code: <code />,
7474
}
7575
),
76-
configurations: getPythonInstallConfig({packageName: "'sentry-sdk[starlette]'"}),
76+
configurations: getPythonInstallConfig({packageName: 'sentry-sdk[starlette]'}),
7777
},
7878
],
7979
configure: (params: Params) => [
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Mock the modules that cause circular dependencies
2+
jest.mock('sentry/utils/gettingStartedDocs/python', () => {
3+
const original = jest.requireActual('sentry/utils/gettingStartedDocs/python');
4+
return {
5+
...original,
6+
// Mock any functions causing circular dependencies
7+
getPythonProfilingOnboarding: jest.fn(),
8+
};
9+
});
10+
11+
import {getPythonInstallSnippet} from 'sentry/utils/gettingStartedDocs/python';
12+
13+
describe('getPythonInstallSnippet', () => {
14+
it('generates install commands with default parameters', () => {
15+
const result = getPythonInstallSnippet({
16+
packageName: 'sentry-sdk',
17+
});
18+
19+
expect(result.pip).toBe(`pip install "sentry-sdk"`);
20+
expect(result.uv).toBe(`uv add "sentry-sdk"`);
21+
expect(result.poetry).toBe(`poetry add "sentry-sdk"`);
22+
});
23+
24+
it('generates pip install command with minimum version and extras', () => {
25+
const result = getPythonInstallSnippet({
26+
packageName: 'sentry-sdk[with-extras]',
27+
minimumVersion: '2.3.4',
28+
});
29+
expect(result.pip).toBe(`pip install --upgrade "sentry-sdk[with-extras]>=2.3.4"`);
30+
expect(result.uv).toBe(`uv add --upgrade "sentry-sdk[with-extras]>=2.3.4"`);
31+
expect(result.poetry).toBe(`poetry add "sentry-sdk[with-extras]>=2.3.4"`);
32+
});
33+
});

static/app/utils/gettingStartedDocs/python.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,38 @@ import {t, tct} from 'sentry/locale';
1212

1313
export function getPythonInstallSnippet({
1414
packageName,
15-
packageManager = 'pip',
1615
minimumVersion,
1716
}: {
1817
packageName: string;
1918
minimumVersion?: string;
20-
packageManager?: 'pip' | 'uv';
2119
}) {
20+
// We are using consistent double quotes here for all package managers after aligning with the Python SDK team.
21+
// Not using quotes may lead to some shells interpreting the square brackets, and using double quotes over single quotes is a convention.
2222
const versionedPackage = minimumVersion
23-
? `${packageName}>=${minimumVersion}`
24-
: packageName;
23+
? `"${packageName}>=${minimumVersion}"`
24+
: `"${packageName}"`;
2525

2626
const upgradeFlag = minimumVersion ? '--upgrade ' : '';
2727

2828
const packageManagerCommands = {
2929
uv: `uv add ${upgradeFlag}${versionedPackage}`,
3030
pip: `pip install ${upgradeFlag}${versionedPackage}`,
31+
poetry: `poetry add ${versionedPackage}`,
3132
};
3233

33-
return packageManagerCommands[packageManager].trim();
34+
return packageManagerCommands;
3435
}
3536

3637
export function getPythonInstallConfig({
37-
packageName = "'sentry-sdk'",
38+
packageName = 'sentry-sdk',
3839
description,
3940
minimumVersion,
4041
}: {
4142
description?: React.ReactNode;
4243
minimumVersion?: string;
4344
packageName?: string;
4445
} = {}): Configuration[] {
46+
const packageManagerCommands = getPythonInstallSnippet({packageName, minimumVersion});
4547
return [
4648
{
4749
description,
@@ -51,21 +53,19 @@ export function getPythonInstallConfig({
5153
label: 'pip',
5254
value: 'pip',
5355
language: 'bash',
54-
code: getPythonInstallSnippet({
55-
packageName,
56-
packageManager: 'pip',
57-
minimumVersion,
58-
}),
56+
code: packageManagerCommands.pip,
5957
},
6058
{
6159
label: 'uv',
6260
value: 'uv',
6361
language: 'bash',
64-
code: getPythonInstallSnippet({
65-
packageName,
66-
packageManager: 'uv',
67-
minimumVersion,
68-
}),
62+
code: packageManagerCommands.uv,
63+
},
64+
{
65+
label: 'poetry',
66+
value: 'poetry',
67+
language: 'bash',
68+
code: packageManagerCommands.poetry,
6969
},
7070
],
7171
},
@@ -93,7 +93,7 @@ export function getPythonAiocontextvarsConfig({
9393
);
9494

9595
return getPythonInstallConfig({
96-
packageName: "'aiocontextvars'",
96+
packageName: 'aiocontextvars',
9797
description: description ?? defaultDescription,
9898
});
9999
}

0 commit comments

Comments
 (0)