File tree 2 files changed +45
-0
lines changed
poetry/core/masonry/builders
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 6
6
import time
7
7
8
8
from collections import defaultdict
9
+ from contextlib import contextmanager
9
10
from copy import copy
10
11
from gzip import GzipFile
11
12
from io import BytesIO
12
13
from posixpath import join as pjoin
13
14
from pprint import pformat
15
+ from typing import Iterator
14
16
15
17
from poetry .core .utils ._compat import Path
18
+ from poetry .core .utils ._compat import decode
16
19
from poetry .core .utils ._compat import encode
17
20
from poetry .core .utils ._compat import to_str
18
21
@@ -198,6 +201,24 @@ def build_setup(self): # type: () -> bytes
198
201
)
199
202
)
200
203
204
+ @contextmanager
205
+ def setup_py (self ): # type: () -> Iterator[Path]
206
+ setup = self ._path / "setup.py"
207
+ has_setup = setup .exists ()
208
+
209
+ if has_setup :
210
+ logger .info (
211
+ " - <warning>A setup.py file already exists. Using it.</warning>"
212
+ )
213
+ else :
214
+ with setup .open ("w" , encoding = "utf-8" ) as f :
215
+ f .write (decode (self .build_setup ()))
216
+
217
+ yield setup
218
+
219
+ if not has_setup :
220
+ setup .unlink ()
221
+
201
222
def build_pkg_info (self ):
202
223
return encode (self .get_metadata_content ())
203
224
Original file line number Diff line number Diff line change 14
14
from poetry .core .packages .dependency import Dependency
15
15
from poetry .core .packages .vcs_dependency import VCSDependency
16
16
from poetry .core .utils ._compat import Path
17
+ from poetry .core .utils ._compat import encode
17
18
from poetry .core .utils ._compat import to_str
18
19
19
20
@@ -247,6 +248,29 @@ def test_package():
247
248
assert "my-package-1.2.3/LICENSE" in tar .getnames ()
248
249
249
250
251
+ def test_setup_py_context ():
252
+ poetry = Factory ().create_poetry (project ("complete" ))
253
+
254
+ builder = SdistBuilder (poetry )
255
+
256
+ project_setup_py = poetry .file .parent / "setup.py"
257
+
258
+ assert not project_setup_py .exists ()
259
+
260
+ try :
261
+ with builder .setup_py () as setup :
262
+ assert setup .exists ()
263
+ assert project_setup_py == setup
264
+
265
+ with open (str (setup ), "r" , encoding = "utf-8" ) as f :
266
+ assert encode (f .read ()) == builder .build_setup ()
267
+
268
+ assert not project_setup_py .exists ()
269
+ finally :
270
+ if project_setup_py .exists ():
271
+ project_setup_py .unlink ()
272
+
273
+
250
274
def test_module ():
251
275
poetry = Factory ().create_poetry (project ("module1" ))
252
276
You can’t perform that action at this time.
0 commit comments