7
7
8
8
from pipenv import environments , exceptions
9
9
from pipenv .patched .pip ._internal .exceptions import PipError
10
- from pipenv .patched .pip ._vendor import rich
11
10
from pipenv .routines .lock import do_lock
12
- from pipenv .utils import fileutils
11
+ from pipenv .utils import console , err , fileutils
13
12
from pipenv .utils .dependencies import (
14
13
expansive_install_req_from_line ,
15
14
get_lockfile_section_using_pipfile_category ,
25
24
from pipenv .utils .requirements import add_index_to_pipfile , import_requirements
26
25
from pipenv .utils .shell import temp_environ
27
26
from pipenv .utils .virtualenv import cleanup_virtualenv , do_create_virtualenv
28
- from pipenv .vendor import click
29
-
30
- console = rich .console .Console ()
31
- err = rich .console .Console (stderr = True )
32
27
33
28
34
29
def do_install (
@@ -100,10 +95,9 @@ def do_install(
100
95
os .environ ["PIPENV_USE_SYSTEM" ] = "1"
101
96
# Check if the file is remote or not
102
97
if remote :
103
- click . secho (
98
+ err . print (
104
99
"Remote requirements file provided! Downloading..." ,
105
- bold = True ,
106
- err = True ,
100
+ style = "bold" ,
107
101
)
108
102
fd = NamedTemporaryFile (
109
103
prefix = "pipenv-" , suffix = "-requirement.txt" , dir = requirements_directory
@@ -116,10 +110,9 @@ def do_install(
116
110
except OSError :
117
111
fd .close ()
118
112
os .unlink (temp_reqs )
119
- click . secho (
113
+ err . print (
120
114
f"Unable to find requirements file at { requirements_url } ." ,
121
- fg = "red" ,
122
- err = True ,
115
+ style = "red" ,
123
116
)
124
117
sys .exit (1 )
125
118
finally :
@@ -128,10 +121,9 @@ def do_install(
128
121
requirementstxt = temp_reqs
129
122
if requirementstxt :
130
123
error , traceback = None , None
131
- click . secho (
124
+ err . print (
132
125
"Requirements file provided! Importing into Pipfile..." ,
133
- bold = True ,
134
- err = True ,
126
+ style = "bold" ,
135
127
)
136
128
try :
137
129
import_requirements (
@@ -143,10 +135,7 @@ def do_install(
143
135
except (UnicodeDecodeError , PipError ) as e :
144
136
# Don't print the temp file path if remote since it will be deleted.
145
137
req_path = project .path_to (requirementstxt )
146
- error = (
147
- "Unexpected syntax in {}. Are you sure this is a "
148
- "requirements.txt style file?" .format (req_path )
149
- )
138
+ error = f"Unexpected syntax in { req_path } . Are you sure this is a requirements.txt style file?"
150
139
traceback = e
151
140
except AssertionError as e :
152
141
error = (
@@ -156,8 +145,8 @@ def do_install(
156
145
traceback = e
157
146
finally :
158
147
if error and traceback :
159
- click . secho (error , fg = "red" )
160
- click . secho (str (traceback ), fg = "yellow" , err = True )
148
+ console . print (error , sytle = "red" )
149
+ err . print (str (traceback ), style = "yellow" )
161
150
sys .exit (1 )
162
151
163
152
# Allow more than one package to be provided.
@@ -202,10 +191,9 @@ def do_install(
202
191
)
203
192
204
193
for pkg_line in pkg_list :
205
- click . secho (
194
+ console . print (
206
195
f"Installing { pkg_line } ..." ,
207
- fg = "green" ,
208
- bold = True ,
196
+ style = "bold green" ,
209
197
)
210
198
# pip install:
211
199
with temp_environ (), console .status (
@@ -221,30 +209,14 @@ def do_install(
221
209
pkg_line , expand_env = True
222
210
)
223
211
except ValueError as e :
224
- err .print ("{} : {}" . format ( click . style ( "WARNING" , fg = "red" ), e ) )
212
+ err .print (f"[red]WARNING[/red] : { e } " )
225
213
err .print (
226
214
environments .PIPENV_SPINNER_FAIL_TEXT .format (
227
215
"Installation Failed"
228
216
)
229
217
)
230
218
sys .exit (1 )
231
219
st .update (f"Installing { pkg_requirement .name } ..." )
232
- # Warn if --editable wasn't passed.
233
- if (
234
- pkg_requirement .link
235
- and pkg_requirement .link .is_vcs
236
- and not pkg_requirement .editable
237
- and not project .s .PIPENV_RESOLVE_VCS
238
- ):
239
- err .print (
240
- "{}: You installed a VCS dependency in non-editable mode. "
241
- "This will work fine, but sub-dependencies will not be resolved by {}."
242
- "\n To enable this sub-dependency functionality, specify that this dependency is editable."
243
- "" .format (
244
- click .style ("Warning" , fg = "red" , bold = True ),
245
- click .style ("$ pipenv lock" , fg = "yellow" ),
246
- )
247
- )
248
220
if categories :
249
221
pipfile_sections = ""
250
222
for c in categories :
@@ -288,12 +260,7 @@ def do_install(
288
260
except ValueError :
289
261
import traceback
290
262
291
- err .print (
292
- "{} {}" .format (
293
- click .style ("Error:" , fg = "red" , bold = True ),
294
- traceback .format_exc (),
295
- )
296
- )
263
+ err .print (f"[bold][red]Error:[/red][/bold] { traceback .format_exc ()} " )
297
264
err .print (
298
265
environments .PIPENV_SPINNER_FAIL_TEXT .format (
299
266
"Failed adding package to Pipfile"
@@ -377,7 +344,7 @@ def do_sync(
377
344
categories = categories ,
378
345
)
379
346
if not bare :
380
- click . echo ( click . style ( " All dependencies are now up-to-date!" , fg = " green" ) )
347
+ console . print ( "[green] All dependencies are now up-to-date![/ green]" )
381
348
382
349
383
350
def do_install_dependencies (
@@ -408,11 +375,10 @@ def do_install_dependencies(
408
375
for category in categories :
409
376
lockfile = project .get_or_create_lockfile (categories = categories )
410
377
if not bare :
411
- click .secho (
412
- "Installing dependencies from Pipfile.lock ({})..." .format (
413
- lockfile ["_meta" ].get ("hash" , {}).get ("sha256" )[- 6 :]
414
- ),
415
- bold = True ,
378
+ console .print (
379
+ f"Installing dependencies from Pipfile.lock "
380
+ f"({ lockfile ['_meta' ].get ('hash' , {}).get ('sha256' )[- 6 :]} )..." ,
381
+ style = "bold" ,
416
382
)
417
383
dev = dev or dev_only
418
384
deps_list = list (
@@ -552,10 +518,9 @@ def batch_install(
552
518
extra_pip_args = extra_pip_args ,
553
519
)
554
520
except StopIteration :
555
- click . secho (
521
+ console . print (
556
522
f"Unable to find { index_name } in sources, please check dependencies: { dependencies } " ,
557
- fg = "red" ,
558
- bold = True ,
523
+ style = "bold red" ,
559
524
)
560
525
sys .exit (1 )
561
526
@@ -569,7 +534,7 @@ def _cleanup_procs(project, procs):
569
534
out , err = c .stdout , c .stderr
570
535
failed = c .returncode != 0
571
536
if project .s .is_verbose ():
572
- click . secho (out .strip () or err .strip (), fg = "yellow" )
537
+ console . print (out .strip () or err .strip (), style = "yellow" )
573
538
# The Installation failed...
574
539
if failed :
575
540
# The Installation failed...
@@ -625,31 +590,26 @@ def do_init(
625
590
new_hash = project .calculate_pipfile_hash ()
626
591
if new_hash != old_hash :
627
592
if deploy :
628
- click .secho (
629
- "Your Pipfile.lock (old_hash[-6:]) is out of date."
630
- " Expected: ({new_hash[-6:]})." ,
631
- fg = "red" ,
593
+ console .print (
594
+ f"Your Pipfile.lock ({ old_hash [- 6 :]} ) is out of date. Expected: ({ new_hash [- 6 :]} )." ,
595
+ style = "red" ,
632
596
)
633
597
raise exceptions .DeployException
634
598
if (system or allow_global ) and not (project .s .PIPENV_VIRTUALENV ):
635
- click .secho (
636
- "Pipfile.lock ({}) out of date, but installation "
637
- "uses {} re-building lockfile must happen in "
638
- "isolation. Please rebuild lockfile in a virtualenv. "
639
- "Continuing anyway..." .format (old_hash [- 6 :], "--system" ),
640
- fg = "yellow" ,
641
- err = True ,
599
+ err .print (
600
+ f"Pipfile.lock ({ old_hash [- 6 :]} ) out of date, but installation uses --system so"
601
+ f"re-building lockfile must happen in isolation."
602
+ f" Please rebuild lockfile in a virtualenv. Continuing anyway..." ,
603
+ style = "yellow" ,
642
604
)
643
605
else :
644
606
if old_hash :
645
607
msg = "Pipfile.lock ({0}) out of date, updating to ({1})..."
646
608
else :
647
609
msg = "Pipfile.lock is corrupt, replaced with ({1})..."
648
- click . secho (
610
+ err . print (
649
611
msg .format (old_hash [- 6 :], new_hash [- 6 :]),
650
- fg = "yellow" ,
651
- bold = True ,
652
- err = True ,
612
+ style = "bold yellow" ,
653
613
)
654
614
do_lock (
655
615
project ,
@@ -671,10 +631,9 @@ def do_init(
671
631
"See also: --deploy flag." ,
672
632
)
673
633
else :
674
- click . secho (
634
+ err . print (
675
635
"Pipfile.lock not found, creating..." ,
676
- bold = True ,
677
- err = True ,
636
+ style = "bold" ,
678
637
)
679
638
do_lock (
680
639
project ,
@@ -697,11 +656,7 @@ def do_init(
697
656
698
657
# Hint the user what to do to activate the virtualenv.
699
658
if not allow_global and not deploy and "PIPENV_ACTIVE" not in os .environ :
700
- click .echo (
701
- "To activate this project's virtualenv, run {}.\n "
702
- "Alternatively, run a command "
703
- "inside the virtualenv with {}." .format (
704
- click .style ("pipenv shell" , fg = "yellow" ),
705
- click .style ("pipenv run" , fg = "yellow" ),
706
- )
659
+ console .print (
660
+ "To activate this project's virtualenv, run [yellow]pipenv shell[/yellow].\n "
661
+ "Alternatively, run a command inside the virtualenv with [yellow]pipenv run[/yellow]."
707
662
)
0 commit comments