4
4
runNxCommandAsync ,
5
5
updateFile ,
6
6
checkFilesExist ,
7
+ readFile ,
7
8
} from '@nx/plugin/testing' ;
8
9
describe ( 'nx-python e2e' , ( ) => {
9
10
it ( 'should create nx-python project' , async ( ) => {
@@ -17,11 +18,45 @@ describe('nx-python e2e', () => {
17
18
updateFile ( 'nx.json' , JSON . stringify ( nxJson , null , 4 ) ) ;
18
19
19
20
await runNxCommandAsync (
20
- `generate @nxlv/python:project ${ app1 } --type "application" --packageName ${ app1 } --description ${ app1 } `
21
+ `generate @nxlv/python:poetry- project ${ app1 } --projectType "application" --packageName ${ app1 } --description ${ app1 } `
21
22
) ;
22
23
23
24
await runNxCommandAsync (
24
- `generate @nxlv/python:project ${ lib1 } --type "library" --packageName ${ lib1 } --description ${ lib1 } `
25
+ `generate @nxlv/python:poetry-project ${ lib1 } --projectType "library" --packageName ${ lib1 } --description ${ lib1 } `
26
+ ) ;
27
+
28
+ await runNxCommandAsync ( `run ${ app1 } :add --name ${ lib1 } --local` ) ;
29
+
30
+ await runNxCommandAsync ( `run ${ lib1 } :add --name pendulum` ) ;
31
+
32
+ await runNxCommandAsync ( `run ${ app1 } :lint` ) ;
33
+
34
+ await runNxCommandAsync ( `run ${ app1 } :build` ) ;
35
+
36
+ expect ( ( ) =>
37
+ checkFilesExist (
38
+ `apps/${ app1 } /dist/${ app1 . replace ( '-' , '_' ) } -1.0.0-py3-none-any.whl` ,
39
+ `apps/${ app1 } /dist/${ app1 } -1.0.0.tar.gz`
40
+ )
41
+ ) . not . toThrow ( ) ;
42
+ } , 3000000 ) ;
43
+
44
+ it ( 'should create nx-python project with ruff' , async ( ) => {
45
+ const app1 = 'app1' ;
46
+ const lib1 = 'lib1' ;
47
+ ensureNxProject ( '@nxlv/python' , 'dist/packages/nx-python' ) ;
48
+
49
+ const nxJson = readJson ( 'nx.json' ) ;
50
+ nxJson . plugins = [ '@nxlv/python' ] ;
51
+
52
+ updateFile ( 'nx.json' , JSON . stringify ( nxJson , null , 4 ) ) ;
53
+
54
+ await runNxCommandAsync (
55
+ `generate @nxlv/python:poetry-project ${ app1 } --projectType "application" --packageName ${ app1 } --description ${ app1 } --linter ruff`
56
+ ) ;
57
+
58
+ await runNxCommandAsync (
59
+ `generate @nxlv/python:poetry-project ${ lib1 } --projectType "library" --packageName ${ lib1 } --description ${ lib1 } --linter ruff`
25
60
) ;
26
61
27
62
await runNxCommandAsync ( `run ${ app1 } :add --name ${ lib1 } --local` ) ;
@@ -53,15 +88,15 @@ describe('nx-python e2e', () => {
53
88
updateFile ( 'nx.json' , JSON . stringify ( nxJson , null , 4 ) ) ;
54
89
55
90
await runNxCommandAsync (
56
- `generate @nxlv/python:project ${ app1 } --type "application" --packageName ${ app1 } --description ${ app1 } `
91
+ `generate @nxlv/python:poetry- project ${ app1 } --projectType "application" --packageName ${ app1 } --description ${ app1 } `
57
92
) ;
58
93
59
94
await runNxCommandAsync (
60
- `generate @nxlv/python:project ${ lib1 } --type "library" --packageName ${ lib1 } --description ${ lib1 } `
95
+ `generate @nxlv/python:poetry- project ${ lib1 } --projectType "library" --packageName ${ lib1 } --description ${ lib1 } `
61
96
) ;
62
97
63
98
await runNxCommandAsync (
64
- `generate @nxlv/python:project ${ lib2 } --type "library" --packageName ${ lib2 } --description ${ lib2 } `
99
+ `generate @nxlv/python:poetry- project ${ lib2 } --projectType "library" --packageName ${ lib2 } --description ${ lib2 } `
65
100
) ;
66
101
67
102
await runNxCommandAsync ( `run ${ lib1 } :add --name ${ lib2 } --local` ) ;
@@ -79,4 +114,98 @@ describe('nx-python e2e', () => {
79
114
)
80
115
) . not . toThrow ( ) ;
81
116
} , 3000000 ) ;
117
+
118
+ describe ( 'shared virtual environment' , ( ) => {
119
+ it ( 'should create nx-python project with 3 levels with shared virtual environment' , async ( ) => {
120
+ const app1 = 'app1' ;
121
+ const lib1 = 'lib1' ;
122
+ const lib2 = 'lib2' ;
123
+
124
+ ensureNxProject ( '@nxlv/python' , 'dist/packages/nx-python' ) ;
125
+
126
+ const nxJson = readJson ( 'nx.json' ) ;
127
+ nxJson . plugins = [ '@nxlv/python' ] ;
128
+
129
+ updateFile ( 'nx.json' , JSON . stringify ( nxJson , null , 4 ) ) ;
130
+
131
+ await runNxCommandAsync (
132
+ `generate @nxlv/python:poetry-project ${ app1 } --projectType "application" --packageName ${ app1 } --description ${ app1 } `
133
+ ) ;
134
+
135
+ await runNxCommandAsync (
136
+ `generate @nxlv/python:poetry-project ${ lib1 } --projectType "library" --packageName ${ lib1 } --description ${ lib1 } `
137
+ ) ;
138
+
139
+ await runNxCommandAsync (
140
+ `generate @nxlv/python:poetry-project ${ lib2 } --projectType "library" --packageName ${ lib2 } --description ${ lib2 } `
141
+ ) ;
142
+
143
+ await runNxCommandAsync ( `generate @nxlv/python:migrate-to-shared-venv` ) ;
144
+
145
+ await runNxCommandAsync ( `run ${ lib1 } :add --name ${ lib2 } --local` ) ;
146
+
147
+ await runNxCommandAsync ( `run ${ app1 } :add --name ${ lib1 } --local` ) ;
148
+
149
+ await runNxCommandAsync ( `run ${ lib2 } :add --name numpy` ) ;
150
+
151
+ await runNxCommandAsync ( `run ${ app1 } :build` ) ;
152
+
153
+ expect ( ( ) =>
154
+ checkFilesExist (
155
+ `apps/${ app1 } /dist/${ app1 . replace ( '-' , '_' ) } -1.0.0-py3-none-any.whl` ,
156
+ `apps/${ app1 } /dist/${ app1 } -1.0.0.tar.gz`
157
+ )
158
+ ) . not . toThrow ( ) ;
159
+
160
+ expect ( ( ) => checkFilesExist ( `.venv` , 'pyproject.toml' ) ) . not . toThrow ( ) ;
161
+
162
+ expect ( readFile ( 'pyproject.toml' ) ) . toMatchSnapshot ( ) ;
163
+ } , 3000000 ) ;
164
+
165
+ it ( 'should create one nx-python project, migrate to shared venv and add 3 levels' , async ( ) => {
166
+ const app1 = 'app1' ;
167
+ const lib1 = 'lib1' ;
168
+ const lib2 = 'lib2' ;
169
+
170
+ ensureNxProject ( '@nxlv/python' , 'dist/packages/nx-python' ) ;
171
+
172
+ const nxJson = readJson ( 'nx.json' ) ;
173
+ nxJson . plugins = [ '@nxlv/python' ] ;
174
+
175
+ updateFile ( 'nx.json' , JSON . stringify ( nxJson , null , 4 ) ) ;
176
+
177
+ await runNxCommandAsync (
178
+ `generate @nxlv/python:poetry-project ${ app1 } --projectType "application" --packageName ${ app1 } --description ${ app1 } `
179
+ ) ;
180
+
181
+ await runNxCommandAsync ( `generate @nxlv/python:migrate-to-shared-venv` ) ;
182
+
183
+ await runNxCommandAsync (
184
+ `generate @nxlv/python:poetry-project ${ lib1 } --projectType "library" --packageName ${ lib1 } --description ${ lib1 } `
185
+ ) ;
186
+
187
+ await runNxCommandAsync (
188
+ `generate @nxlv/python:poetry-project ${ lib2 } --projectType "library" --packageName ${ lib2 } --description ${ lib2 } `
189
+ ) ;
190
+
191
+ await runNxCommandAsync ( `run ${ lib1 } :add --name ${ lib2 } --local` ) ;
192
+
193
+ await runNxCommandAsync ( `run ${ app1 } :add --name ${ lib1 } --local` ) ;
194
+
195
+ await runNxCommandAsync ( `run ${ lib2 } :add --name numpy` ) ;
196
+
197
+ await runNxCommandAsync ( `run ${ app1 } :build` ) ;
198
+
199
+ expect ( ( ) =>
200
+ checkFilesExist (
201
+ `apps/${ app1 } /dist/${ app1 . replace ( '-' , '_' ) } -1.0.0-py3-none-any.whl` ,
202
+ `apps/${ app1 } /dist/${ app1 } -1.0.0.tar.gz`
203
+ )
204
+ ) . not . toThrow ( ) ;
205
+
206
+ expect ( ( ) => checkFilesExist ( `.venv` , 'pyproject.toml' ) ) . not . toThrow ( ) ;
207
+
208
+ expect ( readFile ( 'pyproject.toml' ) ) . toMatchSnapshot ( ) ;
209
+ } , 3000000 ) ;
210
+ } ) ;
82
211
} ) ;
0 commit comments