21
21
upgrade_options ,
22
22
verbose_option ,
23
23
)
24
+ from pipenv .utils import console , err
24
25
from pipenv .utils .environment import load_dot_env
25
26
from pipenv .utils .processes import subprocess_run
26
- from pipenv .vendor import click
27
27
from pipenv .vendor .click import (
28
28
Choice ,
29
29
argument ,
30
- echo ,
31
30
edit ,
32
31
group ,
33
32
option ,
34
33
pass_context ,
35
- secho ,
36
- style ,
37
34
version_option ,
38
35
)
39
36
37
+ with console .capture () as capture :
38
+ console .print ("[bold]pipenv[/bold]" )
39
+
40
+ prog_name = capture .get ()
41
+
40
42
subcommand_context = CONTEXT_SETTINGS .copy ()
41
43
subcommand_context .update ({"ignore_unknown_options" : True , "allow_extra_args" : True })
42
44
subcommand_context_no_interspersion = subcommand_context .copy ()
61
63
help = "Output diagnostic information for use in GitHub issues." ,
62
64
)
63
65
@general_options
64
- @version_option (prog_name = style ( "pipenv" , bold = True ) , version = __version__ )
66
+ @version_option (prog_name = prog_name , version = __version__ )
65
67
@pass_state
66
68
@pass_context
67
69
def cli (
@@ -79,7 +81,6 @@ def cli(
79
81
site_packages = None ,
80
82
** kwargs ,
81
83
):
82
- from pipenv .patched .pip ._vendor import rich
83
84
from pipenv .utils .shell import system_which
84
85
85
86
load_dot_env (state .project , quiet = state .quiet )
@@ -90,10 +91,9 @@ def cli(
90
91
from pipenv .utils .virtualenv import cleanup_virtualenv , do_where , warn_in_virtualenv
91
92
92
93
if "PIPENV_COLORBLIND" in os .environ :
93
- echo (
94
+ err . print (
94
95
"PIPENV_COLORBLIND is deprecated, use NO_COLOR"
95
96
" per https://no-color.org/ instead" ,
96
- err = True ,
97
97
)
98
98
99
99
if man :
@@ -102,25 +102,20 @@ def cli(
102
102
os .execle (system_which ("man" ), "man" , path , os .environ )
103
103
return 0
104
104
else :
105
- secho (
106
- "man does not appear to be available on your system." ,
107
- fg = "yellow" ,
108
- bold = True ,
109
- err = True ,
105
+ err .print (
106
+ "man does not appear to be available on your system." , style = "bold yellow"
110
107
)
111
108
return 1
112
109
if envs :
113
- echo ("The following environment variables can be set, to do various things:\n " )
110
+ console .print (
111
+ "The following environment variables can be set, to do various things:\n "
112
+ )
114
113
for key in state .project .__dict__ :
115
114
if key .startswith ("PIPENV" ):
116
- echo (f" - { style (key , bold = True )} " )
117
- echo (
118
- "\n You can learn more at:\n {}" .format (
119
- style (
120
- "https://pipenv.pypa.io/en/latest/advanced/#configuration-with-environment-variables" ,
121
- fg = "green" ,
122
- )
123
- )
115
+ console .print (f" - { key } " , style = "bold" )
116
+ console .print (
117
+ "\n You can learn more at:\n "
118
+ "[green]https://pipenv.pypa.io/en/latest/advanced/#configuration-with-environment-variables[/green]" ,
124
119
)
125
120
return 0
126
121
warn_in_virtualenv (state .project )
@@ -146,57 +141,39 @@ def cli(
146
141
elif venv :
147
142
# There is no virtualenv yet.
148
143
if not state .project .virtualenv_exists :
149
- echo (
150
- "{}({}){}" .format (
151
- style (
152
- "No virtualenv has been created for this project" , fg = "red"
153
- ),
154
- style (state .project .project_directory , bold = True ),
155
- style (" yet!" , fg = "red" ),
156
- ),
157
- err = True ,
144
+ err .print (
145
+ "[red]No virtualenv has been created for this project[/red]"
146
+ f"[bold]{ state .project .project_directory } [/bold]"
147
+ " [red]yet![/red]"
158
148
)
159
149
ctx .abort ()
160
150
else :
161
- echo (state .project .virtualenv_location )
151
+ print (state .project .virtualenv_location )
162
152
return 0
163
153
# --rm was passed...
164
154
elif rm :
165
155
# Abort if --system (or running in a virtualenv).
166
156
if state .project .s .PIPENV_USE_SYSTEM or environments .is_in_virtualenv ():
167
- echo (
168
- style (
169
- "You are attempting to remove a virtualenv that "
170
- "Pipenv did not create. Aborting." ,
171
- fg = "red" ,
172
- )
157
+ console .print (
158
+ "You are attempting to remove a virtualenv that "
159
+ "Pipenv did not create. Aborting." ,
160
+ style = "red" ,
173
161
)
174
162
ctx .abort ()
175
163
if state .project .virtualenv_exists :
176
164
loc = state .project .virtualenv_location
177
- echo (
178
- style (
179
- "{} ({})..." .format (
180
- style ("Removing virtualenv" , bold = True ),
181
- style (loc , fg = "green" ),
182
- )
183
- )
165
+ console .print (
166
+ f"[bold]Removing virtualenv[/bold] ([green]{ loc } [green])..."
184
167
)
185
168
186
- console = rich .console .Console ()
187
- # TODO: add state.project.s to spinner status
188
169
with console .status ("Running..." ):
189
170
# Remove the virtualenv.
190
171
cleanup_virtualenv (state .project , bare = True )
191
172
return 0
192
173
else :
193
- echo (
194
- style (
195
- "No virtualenv has been created for this project yet!" ,
196
- fg = "red" ,
197
- bold = True ,
198
- ),
199
- err = True ,
174
+ err .print (
175
+ "No virtualenv has been created for this project yet!" ,
176
+ style = "red bold" ,
200
177
)
201
178
ctx .abort ()
202
179
# --python was passed...
@@ -212,7 +189,7 @@ def cli(
212
189
# Check this again before exiting for empty ``pipenv`` command.
213
190
elif ctx .invoked_subcommand is None :
214
191
# Display help to user, if no commands were passed.
215
- echo (format_help (ctx .get_help ()))
192
+ console . print (format_help (ctx .get_help ()))
216
193
217
194
218
195
@cli .command (
@@ -225,7 +202,8 @@ def cli(
225
202
@install_options
226
203
@pass_state
227
204
def install (state , ** kwargs ):
228
- """Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile."""
205
+ """Installs provided packages and adds them to Pipfile,
206
+ or (if no packages are given), installs all packages from Pipfile."""
229
207
from pipenv .routines .install import do_install
230
208
231
209
do_install (
@@ -403,13 +381,10 @@ def shell(
403
381
# If PIPENV_ACTIVE is set, VIRTUAL_ENV should always be set too.
404
382
venv_name = os .environ .get ("VIRTUAL_ENV" , "UNKNOWN_VIRTUAL_ENVIRONMENT" )
405
383
if not anyway :
406
- echo (
407
- "{} {} {}\n New shell not activated to avoid nested environments." .format (
408
- style ("Shell for" ),
409
- style (venv_name , fg = "green" , bold = True ),
410
- style ("already activated." , bold = True ),
411
- ),
412
- err = True ,
384
+ err .print (
385
+ f"Shell for [green bold]{ venv_name } [/green bold] "
386
+ "[bold]already activated[/bold].\n "
387
+ "New shell not activated to avoid nested environments."
413
388
)
414
389
sys .exit (1 )
415
390
# Load .env file.
@@ -639,13 +614,13 @@ def run_open(state, module, *args, **kwargs):
639
614
]
640
615
)
641
616
if c .returncode :
642
- echo ( style ( "Module not found!" , fg = "red" ) )
617
+ console . print ( "Module not found!" , style = "red" )
643
618
sys .exit (1 )
644
619
if "__init__.py" in c .stdout :
645
620
p = os .path .dirname (c .stdout .strip ().rstrip ("cdo" ))
646
621
else :
647
622
p = c .stdout .strip ().rstrip ("cdo" )
648
- echo ( style ( f"Opening { p !r} in your EDITOR." , bold = True ) )
623
+ console . print ( f"Opening { p !r} in your EDITOR." , style = "bold" )
649
624
inline_activate_virtual_environment (state .project )
650
625
edit (filename = p )
651
626
return 0
@@ -713,7 +688,7 @@ def clean(state, dry_run=False, bare=False, user=False):
713
688
def scripts (state ):
714
689
"""Lists scripts in current environment config."""
715
690
if not state .project .pipfile_exists :
716
- echo ("No Pipfile present at project home." , err = True )
691
+ err . print ("No Pipfile present at project home." )
717
692
sys .exit (1 )
718
693
scripts = state .project .parsed_pipfile .get ("scripts" , {})
719
694
first_column_width = max (len (word ) for word in ["Command" ] + list (scripts ))
@@ -724,7 +699,7 @@ def scripts(state):
724
699
"{0:<{width}} {1}" .format (name , script , width = first_column_width )
725
700
for name , script in scripts .items ()
726
701
)
727
- echo ("\n " .join (line for line in lines ))
702
+ console . print ("\n " .join (line for line in lines ))
728
703
729
704
730
705
@cli .command (
@@ -735,17 +710,14 @@ def scripts(state):
735
710
def verify (state ):
736
711
"""Verify the hash in Pipfile.lock is up-to-date."""
737
712
if not state .project .pipfile_exists :
738
- echo ("No Pipfile present at project home." , err = True )
713
+ err . print ("No Pipfile present at project home." )
739
714
sys .exit (1 )
740
715
if state .project .get_lockfile_hash () != state .project .calculate_pipfile_hash ():
741
- echo (
742
- "Pipfile.lock is out-of-date. Run {} to update." .format (
743
- style ("$ pipenv lock" , fg = "yellow" , bold = True )
744
- ),
745
- err = True ,
716
+ err .print (
717
+ "Pipfile.lock is out-of-date. Run [yellow bold]$ pipenv lock[/yellow bold] to update."
746
718
)
747
719
sys .exit (1 )
748
- echo ( style ( "Pipfile.lock is up-to-date." , fg = "green" ) )
720
+ console . print ( "Pipfile.lock is up-to-date." , style = "green" )
749
721
sys .exit (0 )
750
722
751
723
@@ -787,17 +759,14 @@ def requirements(
787
759
788
760
def do_py (project , ctx = None , system = False ):
789
761
if not project .virtualenv_exists :
790
- click .echo (
791
- "{}({}){}" .format (
792
- click .style ("No virtualenv has been created for this project " , fg = "red" ),
793
- click .style (project .project_directory , fg = "yellow" , bold = True ),
794
- click .style (" yet!" , fg = "red" ),
795
- ),
796
- err = True ,
762
+ err .print (
763
+ "[red]No virtualenv has been created for this project[/red] "
764
+ f"[yellow bold]{ project .project_directory } [/yellow bold] "
765
+ "[red] yet![/red]"
797
766
)
798
767
ctx .abort ()
799
768
800
769
try :
801
- click . echo (project ._which ("python" , allow_global = system ))
770
+ console . print (project ._which ("python" , allow_global = system ))
802
771
except AttributeError :
803
- click . echo ( click . style ( "No project found!" , fg = "red" ) )
772
+ console . print ( "No project found!" , style = "red" )
0 commit comments