24
24
)
25
25
from pipenv .patched .pip ._internal .req .req_file import parse_requirements
26
26
from pipenv .patched .pip ._internal .utils .misc import split_auth_from_netloc
27
+ from pipenv .patched .pip ._vendor import rich
27
28
from pipenv .patched .pip ._vendor .packaging .utils import canonicalize_name
28
29
from pipenv .project import Project
29
30
from pipenv .utils .constants import MYPY_RUNNING
52
53
subprocess_run ,
53
54
system_which ,
54
55
)
55
- from pipenv .utils .spinner import create_spinner
56
56
from pipenv .vendor import click , plette , vistir
57
57
from pipenv .vendor .requirementslib .models .requirements import Requirement
58
58
94
94
STARTING_LABEL = " "
95
95
96
96
97
+ console = rich .console .Console ()
98
+ err = rich .console .Console (stderr = True )
99
+
100
+
97
101
def do_clear (project ):
98
102
from pipenv .patched .pip ._internal import locations
99
103
@@ -245,14 +249,16 @@ def ensure_pipfile(project, validate=True, skip_requirements=False, system=False
245
249
)
246
250
# Create a Pipfile...
247
251
project .create_pipfile (python = python )
248
- with create_spinner ("Importing requirements..." , project .s ) as sp :
252
+ with console .status (
253
+ "Importing requirements..." , spinner = project .s .PIPENV_SPINNER
254
+ ) as st :
249
255
# Import requirements.txt.
250
256
try :
251
257
import_requirements (project )
252
258
except Exception :
253
- sp . fail (environments .PIPENV_SPINNER_FAIL_TEXT .format ("Failed..." ))
259
+ err . print (environments .PIPENV_SPINNER_FAIL_TEXT .format ("Failed..." ))
254
260
else :
255
- sp . ok (environments .PIPENV_SPINNER_OK_TEXT .format ("Success!" ))
261
+ st . update (environments .PIPENV_SPINNER_OK_TEXT .format ("Success!" ))
256
262
# Warn the user of side-effects.
257
263
click .echo (
258
264
"{0}: Your {1} now contains pinned versions, if your {2} did. \n "
@@ -398,17 +404,18 @@ def abort(msg=""):
398
404
click .style ("..." , bold = True ),
399
405
)
400
406
)
401
- with create_spinner ("Installing python..." , project .s ) as sp :
407
+ # TOOD: pass project settings to console.status
408
+ with console .status ("Installing python..." ) as st :
402
409
try :
403
410
c = installer .install (version )
404
411
except InstallerError as e :
405
- sp . fail (
412
+ err . print (
406
413
environments .PIPENV_SPINNER_FAIL_TEXT .format ("Failed..." )
407
414
)
408
415
click .echo (fix_utf8 ("Something went wrong..." ), err = True )
409
416
click .secho (e .err , fg = "cyan" , err = True )
410
417
else :
411
- sp . ok (environments .PIPENV_SPINNER_OK_TEXT .format ("Success!" ))
418
+ st (environments .PIPENV_SPINNER_OK_TEXT .format ("Success!" ))
412
419
# Print the results, in a beautiful blue...
413
420
click .secho (c .stdout , fg = "cyan" , err = True )
414
421
# Clear the pythonfinder caches
@@ -1003,20 +1010,22 @@ def do_create_virtualenv(project, python=None, site_packages=None, pypi_mirror=N
1003
1010
1004
1011
# Actually create the virtualenv.
1005
1012
error = None
1006
- with create_spinner ("Creating virtual environment..." , project .s ) as sp :
1013
+ with console .status (
1014
+ "Creating virtual environment..." , spinner = project .s .PIPENV_SPINNER
1015
+ ):
1007
1016
c = subprocess_run (cmd , env = pip_config )
1008
1017
click .secho (f"{ c .stdout } " , fg = "cyan" , err = True )
1009
1018
if c .returncode != 0 :
1010
1019
error = (
1011
1020
c .stderr if project .s .is_verbose () else exceptions .prettify_exc (c .stderr )
1012
1021
)
1013
- sp . fail (
1022
+ err . print (
1014
1023
environments .PIPENV_SPINNER_FAIL_TEXT .format (
1015
1024
"Failed creating virtual environment"
1016
1025
)
1017
1026
)
1018
1027
else :
1019
- sp . green . ok (
1028
+ console . print (
1020
1029
environments .PIPENV_SPINNER_OK_TEXT .format (
1021
1030
"Successfully created virtual environment!"
1022
1031
)
@@ -2284,36 +2293,37 @@ def do_install(
2284
2293
extra_pip_args = extra_pip_args ,
2285
2294
categories = categories ,
2286
2295
)
2296
+
2287
2297
for pkg_line in pkg_list :
2288
2298
click .secho (
2289
2299
fix_utf8 (f"Installing { pkg_line } ..." ),
2290
2300
fg = "green" ,
2291
2301
bold = True ,
2292
2302
)
2293
2303
# pip install:
2294
- with vistir .contextmanagers .temp_environ (), create_spinner (
2295
- "Installing..." , project .s
2296
- ) as sp :
2304
+ with vistir .contextmanagers .temp_environ (), console . status (
2305
+ "Installing..." , spinner = project .s . PIPENV_SPINNER
2306
+ ) as st :
2297
2307
if not system :
2298
2308
os .environ ["PIP_USER" ] = "0"
2299
2309
if "PYTHONHOME" in os .environ :
2300
2310
del os .environ ["PYTHONHOME" ]
2301
- sp . text = f"Resolving { pkg_line } ..."
2311
+ st . update ( f"Resolving { pkg_line } ..." )
2302
2312
try :
2303
2313
pkg_requirement = Requirement .from_line (pkg_line )
2304
2314
except ValueError as e :
2305
- sp . write_err ("{}: {}" .format (click .style ("WARNING" , fg = "red" ), e ))
2306
- sp . red . fail (
2315
+ err . print ("{}: {}" .format (click .style ("WARNING" , fg = "red" ), e ))
2316
+ err . print (
2307
2317
environments .PIPENV_SPINNER_FAIL_TEXT .format (
2308
2318
"Installation Failed"
2309
2319
)
2310
2320
)
2311
2321
sys .exit (1 )
2312
- sp . text = "Installing..."
2322
+ st . update ( "Installing..." )
2313
2323
try :
2314
- sp . text = f"Installing { pkg_requirement .name } ..."
2324
+ st . update ( f"Installing { pkg_requirement .name } ..." )
2315
2325
if project .s .is_verbose ():
2316
- sp . hide_and_write (
2326
+ st . update (
2317
2327
f"Installing package: { pkg_requirement .as_line (include_hashes = False )} "
2318
2328
)
2319
2329
c = pip_install (
@@ -2332,34 +2342,32 @@ def do_install(
2332
2342
extra_pip_args = extra_pip_args ,
2333
2343
)
2334
2344
if c .returncode :
2335
- sp . write_err (
2345
+ err . print (
2336
2346
"{} An error occurred while installing {}!" .format (
2337
2347
click .style ("Error: " , fg = "red" , bold = True ),
2338
2348
click .style (pkg_line , fg = "green" ),
2339
2349
),
2340
2350
)
2341
- sp . write_err (f"Error text: { c .stdout } " )
2342
- sp . write_err (click .style (format_pip_error (c .stderr ), fg = "cyan" ))
2351
+ err . print (f"Error text: { c .stdout } " )
2352
+ err . print (click .style (format_pip_error (c .stderr ), fg = "cyan" ))
2343
2353
if project .s .is_verbose ():
2344
- sp .write_err (
2345
- click .style (format_pip_output (c .stdout ), fg = "cyan" )
2346
- )
2354
+ err .print (click .style (format_pip_output (c .stdout ), fg = "cyan" ))
2347
2355
if "setup.py egg_info" in c .stderr :
2348
- sp . write_err (
2356
+ err . print (
2349
2357
"This is likely caused by a bug in {}. "
2350
2358
"Report this to its maintainers." .format (
2351
2359
click .style (pkg_requirement .name , fg = "green" )
2352
2360
)
2353
2361
)
2354
- sp . red . fail (
2362
+ err . print (
2355
2363
environments .PIPENV_SPINNER_FAIL_TEXT .format (
2356
2364
"Installation Failed"
2357
2365
)
2358
2366
)
2359
2367
sys .exit (1 )
2360
2368
except (ValueError , RuntimeError ) as e :
2361
- sp . write_err ("{}: {}" .format (click .style ("WARNING" , fg = "red" ), e ))
2362
- sp . red . fail (
2369
+ err . print ("{}: {}" .format (click .style ("WARNING" , fg = "red" ), e ))
2370
+ err . print (
2363
2371
environments .PIPENV_SPINNER_FAIL_TEXT .format (
2364
2372
"Installation Failed" ,
2365
2373
)
@@ -2371,7 +2379,7 @@ def do_install(
2371
2379
and not pkg_requirement .editable
2372
2380
and not project .s .PIPENV_RESOLVE_VCS
2373
2381
):
2374
- sp . write_err (
2382
+ err . print (
2375
2383
"{}: You installed a VCS dependency in non-editable mode. "
2376
2384
"This will work fine, but sub-dependencies will not be resolved by {}."
2377
2385
"\n To enable this sub-dependency functionality, specify that this dependency is editable."
@@ -2388,7 +2396,7 @@ def do_install(
2388
2396
pipfile_sections = "[dev-packages]"
2389
2397
else :
2390
2398
pipfile_sections = "[packages]"
2391
- sp . write (
2399
+ st . update (
2392
2400
"{} {} {} {}{}" .format (
2393
2401
click .style ("Adding" , bold = True ),
2394
2402
click .style (f"{ pkg_requirement .name } " , fg = "green" , bold = True ),
@@ -2416,18 +2424,19 @@ def do_install(
2416
2424
except ValueError :
2417
2425
import traceback
2418
2426
2419
- sp . write_err (
2427
+ err . print (
2420
2428
"{} {}" .format (
2421
2429
click .style ("Error:" , fg = "red" , bold = True ),
2422
2430
traceback .format_exc (),
2423
2431
)
2424
2432
)
2425
- sp . fail (
2433
+ err . print (
2426
2434
environments .PIPENV_SPINNER_FAIL_TEXT .format (
2427
2435
"Failed adding package to Pipfile"
2428
2436
)
2429
2437
)
2430
- sp .ok (
2438
+ # ok has a nice v in front, should do something similir with rich
2439
+ st .update (
2431
2440
environments .PIPENV_SPINNER_OK_TEXT .format ("Installation Succeeded" )
2432
2441
)
2433
2442
# Update project settings with pre preference.
0 commit comments