Skip to content

Commit 516d961

Browse files
committed
remove clint dependency
The package is not maintained anymore and we were barely using it
1 parent 0ce14aa commit 516d961

File tree

6 files changed

+83
-59
lines changed

6 files changed

+83
-59
lines changed

gitless/cli/gl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
else:
1919
from pbs import ErrorReturnCode
2020

21-
from clint.textui import colored
22-
2321
from gitless import core
2422

2523
from . import (
@@ -44,9 +42,9 @@
4442
try:
4543
repo = core.Repository()
4644
try:
47-
colored.DISABLE_COLOR = not repo.config.get_bool('color.ui')
45+
pprint.DISABLE_COLOR = not repo.config.get_bool('color.ui')
4846
except pygit2.GitError:
49-
colored.DISABLE_COLOR = (
47+
prrint.DISABLE_COLOR = (
5048
repo.config['color.ui'] in ['no', 'never'])
5149
except (core.NotInRepoError, KeyError):
5250
pass

gitless/cli/gl_branch.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
from __future__ import unicode_literals
99

10-
from clint.textui import colored
11-
1210
from gitless import core
1311

1412
from . import helpers, pprint
@@ -110,7 +108,7 @@ def _do_list(repo, list_remote, v=False):
110108
for b in (repo.lookup_branch(n) for n in sorted(repo.listall_branches())):
111109
current_str = '*' if b.is_current else ' '
112110
upstream_str = '(upstream is {0})'.format(b.upstream) if b.upstream else ''
113-
color = colored.green if b.is_current else colored.yellow
111+
color = pprint.green if b.is_current else pprint.yellow
114112
pprint.item(
115113
'{0} {1} {2}'.format(current_str, color(b.branch_name), upstream_str))
116114
if v:
@@ -121,7 +119,7 @@ def _do_list(repo, list_remote, v=False):
121119
branches = r.lookupall_branches() if v else r.listall_branches()
122120
b_remote = '' if v else r.name + '/'
123121
for b in branches:
124-
pprint.item(' {0}'.format(colored.yellow(b_remote + str(b))))
122+
pprint.item(' {0}'.format(pprint.yellow(b_remote + str(b))))
125123
if v:
126124
pprint.item(' ➜ head is {0}'.format(pprint.commit_str(b.head)))
127125

gitless/cli/gl_status.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import os
1111

12-
from clint.textui import colored
13-
1412
from gitless import core
1513

1614
from . import helpers, pprint
@@ -30,7 +28,7 @@ def parser(subparsers, repo):
3028
def main(args, repo):
3129
curr_b = repo.current_branch
3230
pprint.msg('On branch {0}, repo-directory {1}'.format(
33-
colored.green(curr_b.branch_name), colored.green('//' + repo.cwd)))
31+
pprint.green(curr_b.branch_name), pprint.green('//' + repo.cwd)))
3432

3533
if curr_b.merge_in_progress:
3634
pprint.blank()
@@ -83,16 +81,16 @@ def _print_tracked_mod_files(tracked_mod_list, relative_paths, repo):
8381
root = repo.root
8482
for f in tracked_mod_list:
8583
exp = ''
86-
color = colored.yellow
84+
color = pprint.yellow
8785
if not f.exists_at_head:
8886
exp = ' (new file)'
89-
color = colored.green
87+
color = pprint.green
9088
elif not f.exists_in_wd:
9189
exp = ' (deleted)'
92-
color = colored.red
90+
color = pprint.red
9391
elif f.in_conflict:
9492
exp = ' (with conflicts)'
95-
color = colored.cyan
93+
color = pprint.cyan
9694

9795
fp = os.path.relpath(os.path.join(root, f.fp)) if relative_paths else f.fp
9896
if fp == '.':
@@ -114,12 +112,12 @@ def _print_untracked_files(untracked_list, relative_paths, repo):
114112
root = repo.root
115113
for f in untracked_list:
116114
exp = ''
117-
color = colored.blue
115+
color = pprint.blue
118116
if f.in_conflict:
119117
exp = ' (with conflicts)'
120-
color = colored.cyan
118+
color = pprint.cyan
121119
elif f.exists_at_head:
122-
color = colored.magenta
120+
color = pprint.magenta
123121
if f.exists_in_wd:
124122
exp = ' (exists at head)'
125123
else:

gitless/cli/pprint.py

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
import re
1818
import sys
1919

20-
from clint.textui import colored, indent
21-
from clint.textui import puts as clint_puts
20+
DISABLE_COLOR = False
2221

2322
from gitless import core
2423

@@ -33,37 +32,74 @@
3332

3433

3534
def puts(s='', newline=True, stream=sys.stdout.write):
36-
assert not IS_PY2 or (
37-
isinstance(s, unicode) or isinstance(s, colored.ColoredString))
35+
assert not IS_PY2 or isinstance(s, unicode)
3836

3937
if IS_PY2:
4038
s = s.encode(ENCODING, errors='ignore')
41-
clint_puts(s, newline=newline, stream=stream)
39+
if newline:
40+
s = s + '\n'
41+
stream(s)
42+
43+
44+
# Colored strings
45+
RED = '\033[31m'
46+
RED_BOLD = '\033[1;31m'
47+
GREEN = '\033[32m'
48+
GREEN_BOLD = '\033[1;32m'
49+
YELLOW = '\033[33m'
50+
BLUE = '\033[34m'
51+
MAGENTA = '\033[35m'
52+
CYAN = '\033[36m'
53+
CLEAR = '\033[0m'
54+
55+
def _color(color_code, text):
56+
return '{0}{1}{2}'.format(color_code, text, CLEAR) if should_color() else text
57+
58+
def should_color():
59+
# We only output colored lines if the coloring is enabled and we are not being
60+
# piped or redirected
61+
return not DISABLE_COLOR and sys.stdout.isatty()
62+
63+
def red(text):
64+
return _color(RED, text)
65+
66+
def green(text):
67+
return _color(GREEN, text)
68+
69+
def yellow(text):
70+
return _color(YELLOW, text)
71+
72+
def blue(text):
73+
return _color(BLUE, text)
74+
75+
def magenta(text):
76+
return _color(MAGENTA, text)
77+
78+
def cyan(text):
79+
return _color(CYAN, text)
4280

4381

4482
# Stdout
4583

4684

4785
def ok(text):
48-
puts(colored.green('✔ {0}'.format(text)))
86+
puts(green('✔ {0}'.format(text)))
4987

5088

5189
def warn(text):
52-
puts(colored.yellow('! {0}'.format(text)))
90+
puts(yellow('! {0}'.format(text)))
5391

5492

5593
def msg(text, stream=sys.stdout.write):
5694
puts(text, stream=stream)
5795

5896

5997
def exp(text, stream=sys.stdout.write):
60-
with indent(2):
61-
puts('➜ {0}'.format(text), stream=stream)
98+
puts(' ➜ {0}'.format(text), stream=stream)
6299

63100

64101
def item(i, opt_text='', stream=sys.stdout.write):
65-
with indent(4):
66-
puts('{0}{1}'.format(i, opt_text), stream=stream)
102+
puts(' {0}{1}'.format(i, opt_text), stream=stream)
67103

68104

69105
def blank(stream=sys.stdout.write):
@@ -77,7 +113,7 @@ def sep(stream=sys.stdout.write):
77113
# Err
78114

79115
def err(text):
80-
puts(colored.red('✘ {0}'.format(text)), stream=sys.stderr.write)
116+
puts(red('✘ {0}'.format(text)), stream=sys.stderr.write)
81117

82118

83119
def err_msg(text):
@@ -137,7 +173,7 @@ def commit_str(ci):
137173

138174
def commit(ci, compact=False, stream=sys.stdout.write, line_additions=0, line_deletions=0):
139175
merge_commit = len(ci.parent_ids) > 1
140-
color = colored.magenta if merge_commit else colored.yellow
176+
color = magenta if merge_commit else yellow
141177
if compact:
142178
title = ci.message.splitlines()[0]
143179
puts('{0} {1}'.format(color(str(ci.id)[:7]), title), stream=stream)
@@ -154,11 +190,10 @@ def commit(ci, compact=False, stream=sys.stdout.write, line_additions=0, line_de
154190
puts(color('Date: {0:%c %z}'.format(ci_author_dt)), stream=stream)
155191
put_s = lambda num: '' if num == 1 else 's'
156192
puts(color('Stats: {0} line{1} added, {2} line{3} removed'
157-
.format(line_additions, put_s(line_additions),
193+
.format(line_additions, put_s(line_additions),
158194
line_deletions, put_s(line_deletions))), stream=stream)
159195
puts(stream=stream)
160-
with indent(4):
161-
puts(ci.message, stream=stream)
196+
puts(' {0}'.format(ci.message), stream=stream)
162197

163198
# Op Callbacks
164199

@@ -203,7 +238,7 @@ def diff(patch, stream=sys.stdout.write):
203238
new_fp = patch.delta.new_file.path
204239
puts('Diff of file "{0}"'.format(old_fp), stream=stream)
205240
if old_fp != new_fp:
206-
puts(colored.cyan(' (renamed to {0})'.format(new_fp)), stream=stream)
241+
puts(cyan(' (renamed to {0})'.format(new_fp)), stream=stream)
207242
puts(stream=stream)
208243

209244
if patch.delta.is_binary:
@@ -242,7 +277,7 @@ def diff_totals(total_additions, total_deletions, stream=sys.stdout.write):
242277

243278

244279
def _hunk(hunk, stream=sys.stdout.write):
245-
puts(colored.cyan('@@ -{0},{1} +{2},{3} @@'.format(
280+
puts(cyan('@@ -{0},{1} +{2},{3} @@'.format(
246281
hunk.old_start, hunk.old_lines, hunk.new_start, hunk.new_lines)),
247282
stream=stream)
248283
padding = _padding(hunk)
@@ -305,21 +340,18 @@ def _format_line(diff_line, padding, bold_delim=None):
305340
Returns:
306341
a padded and colored version of the diff line with line numbers
307342
"""
308-
# Color constants
309-
# We only output colored lines if the coloring is enabled and we are not being
310-
# piped or redirected
311-
if colored.DISABLE_COLOR or not sys.stdout.isatty():
312-
GREEN = ''
313-
GREEN_BOLD = ''
314-
RED = ''
315-
RED_BOLD = ''
316-
CLEAR = ''
343+
if should_color():
344+
green = GREEN
345+
green_bold = GREEN_BOLD
346+
red = RED
347+
red_bold = RED_BOLD
348+
clear = CLEAR
317349
else:
318-
GREEN = '\033[32m'
319-
GREEN_BOLD = '\033[1;32m'
320-
RED = '\033[31m'
321-
RED_BOLD = '\033[1;31m'
322-
CLEAR = '\033[0m'
350+
green = ''
351+
green_bold = ''
352+
red = ''
353+
red_bold = ''
354+
clear = ''
323355

324356
formatted = ''
325357
st = diff_line.origin
@@ -331,25 +363,25 @@ def _format_line(diff_line, padding, bold_delim=None):
331363
formatted = (
332364
str(old_lineno).ljust(padding) + str(new_lineno).ljust(padding) + line)
333365
elif st == '+':
334-
formatted = ' ' * padding + GREEN + str(new_lineno).ljust(padding)
366+
formatted = ' ' * padding + green + str(new_lineno).ljust(padding)
335367
if not bold_delim:
336368
formatted += line
337369
else:
338370
bold_start, bold_end = bold_delim
339371
formatted += (
340-
line[:bold_start] + GREEN_BOLD + line[bold_start:bold_end] + CLEAR +
341-
GREEN + line[bold_end:])
372+
line[:bold_start] + green_bold + line[bold_start:bold_end] + clear +
373+
green + line[bold_end:])
342374
elif st == '-':
343-
formatted = RED + str(old_lineno).ljust(padding) + ' ' * padding
375+
formatted = red + str(old_lineno).ljust(padding) + ' ' * padding
344376
if not bold_delim:
345377
formatted += line
346378
else:
347379
bold_start, bold_end = bold_delim
348380
formatted += (
349-
line[:bold_start] + RED_BOLD + line[bold_start:bold_end] + CLEAR +
350-
RED + line[bold_end:])
381+
line[:bold_start] + red_bold + line[bold_start:bold_end] + clear +
382+
red + line[bold_end:])
351383

352-
return formatted + CLEAR
384+
return formatted + clear
353385

354386

355387
def _highlight(line1, line2):

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
argcomplete>=1.11.1
44
pygit2==1.1.1 # requires libgit2 0.99 or 1.0
5-
clint==0.5.1
65
sh==1.12.14;sys_platform!='win32'
76
pbs==0.110;sys_platform=='win32'

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
install_requires=[
7070
# make sure it matches requirements.txt
7171
'pygit2==1.1.1', # requires libgit2 0.99 or 1.0
72-
'clint>=0.3.6',
7372
'sh>=1.11' if sys.platform != 'win32' else 'pbs>=0.11',
7473
'argcomplete>=1.11.1'
7574
],

0 commit comments

Comments
 (0)