Skip to content

Commit

Permalink
Merge pull request #234 from regro/no-color-reset
Browse files Browse the repository at this point in the history
NO_COLOR -> RESET fix
  • Loading branch information
CJ-Wright committed Oct 8, 2020
2 parents 266b6e9 + d7c06e2 commit a076bf7
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 55 deletions.
23 changes: 23 additions & 0 deletions news/no-color-reset.rst
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Switched from NO_COLOR to RESET for xonsh v0.9.23+

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
12 changes: 6 additions & 6 deletions rever/activities/authors.xsh
Expand Up @@ -125,7 +125,7 @@ class Authors(Activity):
md = self._update_authors(filename, template, format, metadata, sortby,
include_orgs)
files = [filename, metadata]
print_color('{YELLOW}wrote authors to {INTENSE_CYAN}' + filename + '{NO_COLOR}', file=sys.stderr)
print_color('{YELLOW}wrote authors to {INTENSE_CYAN}' + filename + '{RESET}', file=sys.stderr)
# write latest authors
prev_version = vcsutils.latest_tag()
commits_since_last = vcsutils.commits_per_email(since=prev_version)
Expand All @@ -140,13 +140,13 @@ class Authors(Activity):
if not latest.startswith($REVER_DIR):
# commit the latest file
files.append(latest)
print_color('{YELLOW}wrote authors since ' + prev_version + ' to {INTENSE_CYAN}' + latest + '{NO_COLOR}', file=sys.stderr)
print_color('{YELLOW}wrote authors since ' + prev_version + ' to {INTENSE_CYAN}' + latest + '{RESET}', file=sys.stderr)
# write mailmap
if mailmap and isinstance(mailmap, str):
mailmap = eval_version(mailmap)
write_mailmap(md, mailmap)
files.append(mailmap)
print_color('{YELLOW}wrote mailmap file to {INTENSE_CYAN}' + mailmap + '{NO_COLOR}', file=sys.stderr)
print_color('{YELLOW}wrote mailmap file to {INTENSE_CYAN}' + mailmap + '{RESET}', file=sys.stderr)
# Commit changes
vcsutils.track(files)
vcsutils.commit('Updated authorship for ' + $VERSION)
Expand All @@ -172,14 +172,14 @@ class Authors(Activity):
if mailmap_exists:
msgs.append('Mailmap file {0!r} exists'.format(mailmap))
if len(msgs) > 0:
print_color('{RED}' + ' AND '.join(msgs) + '{NO_COLOR}',
print_color('{RED}' + ' AND '.join(msgs) + '{RESET}',
file=sys.stderr)
if $REVER_FORCED:
print_color('{RED}rever forced, overwriting files!{NO_COLOR}',
print_color('{RED}rever forced, overwriting files!{RESET}',
file=sys.stderr)
else:
print_color('{RED}Use the --force option to force the creation '
'of the changelog files.{NO_COLOR}',
'of the changelog files.{RESET}',
file=sys.stderr)
return False
# actually create files
Expand Down
6 changes: 3 additions & 3 deletions rever/activities/changelog.xsh
Expand Up @@ -184,14 +184,14 @@ class Changelog(Activity):
if changelog_exists:
msgs.append('Changelog file {0!r} exists'.format(changelog_file))
if len(msgs) > 0:
print_color('{RED}' + ' AND '.join(msgs) + '{NO_COLOR}',
print_color('{RED}' + ' AND '.join(msgs) + '{RESET}',
file=sys.stderr)
if $REVER_FORCED:
print_color('{RED}rever forced, overwriting files!{NO_COLOR}',
print_color('{RED}rever forced, overwriting files!{RESET}',
file=sys.stderr)
else:
print_color('{RED}Use the --force option to force the creation '
'of the changelog files.{NO_COLOR}',
'of the changelog files.{RESET}',
file=sys.stderr)
return False
# actually create files
Expand Down
2 changes: 1 addition & 1 deletion rever/activities/docker.xsh
Expand Up @@ -121,7 +121,7 @@ class DockerPush(Activity):
try:
![docker push @(tag)]
except Exception:
print_color("{RED}Check failure!{NO_COLOR} Cannot push to docker " +
print_color("{RED}Check failure!{RESET} Cannot push to docker " +
tag.rpartition(":")[0], file=sys.stderr)
return False
return True
6 changes: 3 additions & 3 deletions rever/activities/forge.xsh
Expand Up @@ -275,7 +275,7 @@ class Forge(Activity):
# Regenerate the feedstock if required
if rerender:
with indir(feedstock_dir), ${...}.swap(RAISE_SUBPROC_ERROR=True):
print_color('{YELLOW}Rerendering the feedstock{NO_COLOR}',
print_color('{YELLOW}Rerendering the feedstock{RESET}',
file=sys.stderr)
conda smithy regenerate -c auto

Expand Down Expand Up @@ -303,9 +303,9 @@ class Forge(Activity):
pr = repo.create_pull(title, 'master', head, body=body)

if pr is None:
print_color('{RED}Failed to create pull request!{NO_COLOR}')
print_color('{RED}Failed to create pull request!{RESET}')
else:
print_color('{GREEN}Pull request created at ' + pr.html_url + '{NO_COLOR}')
print_color('{GREEN}Pull request created at ' + pr.html_url + '{RESET}')

def check_func(self):
"""Checks that we can rerender and login"""
Expand Down
2 changes: 1 addition & 1 deletion rever/activities/gcloud.xsh
Expand Up @@ -9,7 +9,7 @@ from rever.activity import Activity
def _ensure_default_credentials():
credfile = os.path.join($XDG_CONFIG_HOME, 'gcloud', 'application_default_credentials.json')
if os.path.isfile(credfile):
print_color('{YELLOW}Found ' + credfile + ' ...{NO_COLOR}')
print_color('{YELLOW}Found ' + credfile + ' ...{RESET}')
else:
![gcloud auth application-default login]
$CLOUDSDK_CONTAINER_USE_APPLICATION_DEFAULT_CREDENTIALS = 'true'
Expand Down
4 changes: 2 additions & 2 deletions rever/activities/ghpages.xsh
Expand Up @@ -84,7 +84,7 @@ class GHPages(Activity):
git checkout @(branch)
git pull @(repo) @(branch)
for src, dst in copy:
msg = '{CYAN}Copying{NO_COLOR} from ' + src + ' {GREEN}->{NO_COLOR} ' + dst
msg = '{CYAN}Copying{RESET} from ' + src + ' {GREEN}->{RESET} ' + dst
print_color(msg)
if os.path.isdir(src):
copy_tree(src, dst, preserve_symlinks=1, verbose=1)
Expand All @@ -98,7 +98,7 @@ class GHPages(Activity):
q = !(git diff --cached --exit-code --quiet).rtn
if p == 0 and q == 0:
msg = ('{YELLOW}no changes made to GitHub pages repo, already '
'up-to-date.{NO_COLOR}')
'up-to-date.{RESET}')
print_color(msg)
return
# now update the repo and push the changes
Expand Down
4 changes: 2 additions & 2 deletions rever/activities/ghrelease.xsh
Expand Up @@ -39,7 +39,7 @@ def git_archive_asset():
tag = eval_version(template)
folder_name = $GITHUB_REPO + '-' + tag
fname = os.path.join($REVER_DIR, folder_name + '.tar.gz')
print_color('Archiving repository as {INTENSE_CYAN}' + fname + '{NO_COLOR}')
print_color('Archiving repository as {INTENSE_CYAN}' + fname + '{RESET}')
![git archive -9 --format=tar.gz --prefix=@(folder_name)/ -o @(fname) @(tag)]
return fname

Expand Down Expand Up @@ -118,7 +118,7 @@ class GHRelease(Activity):
def _upload_asset(self, release, filename):
"""Uploads an asset from a filename"""
print_color("Uploading {INTENSE_CYAN}" + filename +
"{NO_COLOR} to GitHub release")
"{RESET} to GitHub release")
with open(filename, 'rb') as f:
asset = f.read()
name = os.path.basename(filename)
Expand Down
8 changes: 4 additions & 4 deletions rever/activities/pypi.xsh
Expand Up @@ -93,7 +93,7 @@ class PyPI(Activity):
rc = expand_path(rc)
if not os.path.isfile(rc):
print_color('{YELLOW}WARNING: PyPI run control file ' + rc + \
' does not exist.{NO_COLOR}', file=sys.stderr)
' does not exist.{RESET}', file=sys.stderr)
create_rc(rc)
valid, msg = validate_rc(rc)
if not valid:
Expand Down Expand Up @@ -132,7 +132,7 @@ class PyPI(Activity):
if gpg_flag:
upload_args.append("--sign")
else:
msg = "{YELLOW}Package cannot be signed: " + gpg_msg + "{NO_COLOR}"
msg = "{YELLOW}Package cannot be signed: " + gpg_msg + "{RESET}"
print_color(msg, file=sys.stderr)
p = ![twine @(upload_args) $dist_dir/*]
if p.rtn != 0:
Expand Down Expand Up @@ -160,7 +160,7 @@ class PyPI(Activity):
if username not in maintainers:
sys.stdout.flush()
sys.stderr.flush()
msg = "{RED}Check failure!{NO_COLOR} " + repr(username)
msg = "{RED}Check failure!{RESET} " + repr(username)
msg += " is not in the maintainers list! Valid maintainers are:\n\n* "
msg += "\n* ".join(sorted(maintainers))
print_color(msg, file=sys.stderr)
Expand All @@ -173,7 +173,7 @@ class PyPI(Activity):
elif sign is None or sign:
gpg_flag, gpg_msg = check_gpg()
msg = "{GREEN}" if gpg_flag else "{RED}"
msg += gpg_msg + "{NO_COLOR}"
msg += gpg_msg + "{RESET}"
print_color(msg, file=sys.stderr)
if sign and not gpg_flag:
return False
Expand Down
26 changes: 13 additions & 13 deletions rever/activity.xsh
Expand Up @@ -119,7 +119,7 @@ class Activity:
def setup(self):
"""Calls this activity's setup() initialization function."""
if self._setup is None:
print_color('{PURPLE}No setup needed for ' + self.name + ' activity{NO_COLOR}')
print_color('{PURPLE}No setup needed for ' + self.name + ' activity{RESET}')
return True
status = self._setup()
if not status:
Expand All @@ -136,7 +136,7 @@ class Activity:
def check(self):
"""Calls this activity's check() function."""
if self._check is None and not self.requires:
print_color('{PURPLE}No checks needed for ' + self.name + ' activity{NO_COLOR}')
print_color('{PURPLE}No checks needed for ' + self.name + ' activity{RESET}')
return True
status = self.check_requirements() and (self._check is None or self._check())
if not status:
Expand All @@ -160,17 +160,17 @@ class Activity:
if $REVER_VCS is None or $REVER_VCS == "None":
pass
elif not p:
msgs.append('{RED}ERROR:{NO_COLOR} the command line utility '
'{YELLOW}' + $REVER_VCS + '{NO_COLOR} cannot be found. '
'Please make sure that the {INTENSE_CYAN}' + $REVER_VCS + '{NO_COLOR} '
msgs.append('{RED}ERROR:{RESET} the command line utility '
'{YELLOW}' + $REVER_VCS + '{RESET} cannot be found. '
'Please make sure that the {INTENSE_CYAN}' + $REVER_VCS + '{RESET} '
'package is installed in your environment.')
# now check CLI availability
for cmd, pkg in self.requires.get("commands", {}).items():
if !(which @(cmd)):
continue
msgs.append('{RED}ERROR:{NO_COLOR} the command line utility '
'{YELLOW}' + cmd + '{NO_COLOR} cannot be found. '
'Please make sure that the {INTENSE_CYAN}' + pkg + '{NO_COLOR} '
msgs.append('{RED}ERROR:{RESET} the command line utility '
'{YELLOW}' + cmd + '{RESET} cannot be found. '
'Please make sure that the {INTENSE_CYAN}' + pkg + '{RESET} '
'package is installed in your environment.')
# now check package imports
for mod, pkg in self.requires.get("imports", {}).items():
Expand All @@ -179,17 +179,17 @@ class Activity:
continue
except ImportError:
pass
msgs.append('{RED}ERROR:{NO_COLOR} the module '
'{YELLOW}' + mod + '{NO_COLOR} cannot be imported. '
'Please make sure that the {INTENSE_CYAN}' + pkg + '{NO_COLOR} '
msgs.append('{RED}ERROR:{RESET} the module '
'{YELLOW}' + mod + '{RESET} cannot be imported. '
'Please make sure that the {INTENSE_CYAN}' + pkg + '{RESET} '
'package is installed in your environment.')
# print mesages and return
if len(msgs) == 0:
msg = ('{PURPLE}All CLI and import requirements met for ' +
self.name + ' activity{NO_COLOR}')
self.name + ' activity{RESET}')
status = True
else:
msg = "\n{INTENSE_WHITE}----------{NO_COLOR}\n".join(msgs)
msg = "\n{INTENSE_WHITE}----------{RESET}\n".join(msgs)
status = False
print_color(msg)
$RAISE_SUBPROC_ERROR = orig
Expand Down
4 changes: 2 additions & 2 deletions rever/docker.xsh
Expand Up @@ -257,8 +257,8 @@ def build_image(dockerfile, image, maker, **kwargs):
s = maker(**kwargs)
with open(dockerfile, 'w') as f:
f.write(s)
print_color('{PURPLE}Wrote ' + dockerfile + '{NO_COLOR}')
print_color('{CYAN}Building docker image ' + image + ' ...{NO_COLOR}')
print_color('{PURPLE}Wrote ' + dockerfile + '{RESET}')
print_color('{CYAN}Building docker image ' + image + ' ...{RESET}')
![docker build -t @(image) -f @(dockerfile) --no-cache .]


Expand Down
10 changes: 5 additions & 5 deletions rever/github.xsh
Expand Up @@ -91,7 +91,7 @@ def write_credfile(credfile=None, username='', password=''):
two_factor_callback=two_factor)
except github3.exceptions.UnprocessableEntity:
print_color('{YELLOW}Token for "' + note + ' "may already exist! '
'Attempting to delete and regenerate...{NO_COLOR}', file=sys.stderr)
'Attempting to delete and regenerate...{RESET}', file=sys.stderr)
gh = github3.login(username, password=password, two_factor_callback=two_factor)
for auth in authorizations(gh):
if note == auth.note:
Expand All @@ -100,10 +100,10 @@ def write_credfile(credfile=None, username='', password=''):
msg = 'Could not find GitHub authentication token to delete it!'
raise RuntimeError(msg)
auth.delete()
print_color('{YELLOW}Deleted previous token.{NO_COLOR}')
print_color('{YELLOW}Deleted previous token.{RESET}')
auth = github3.authorize(username, password, scopes, note, note_url,
two_factor_callback=two_factor)
print_color('{YELLOW}Regenerated token.{NO_COLOR}')
print_color('{YELLOW}Regenerated token.{RESET}')
credfile = credfilename(credfile)
with open(credfile, 'w') as f:
f.write(username + '\n')
Expand Down Expand Up @@ -142,10 +142,10 @@ def can_login():
try:
gh, username = login(return_username=True)
except Exception as e:
print_color("{RED}Unable to login to GitHub{NO_COLOR}", file=sys.stderr)
print_color("{RED}Unable to login to GitHub{RESET}", file=sys.stderr)
print(str(e), file=sys.stderr)
return False
print_color("GitHub login as {GREEN}" + username + "{NO_COLOR} works!",
print_color("GitHub login as {GREEN}" + username + "{RESET} works!",
file=sys.stderr)
return True

Expand Down
2 changes: 1 addition & 1 deletion rever/logger.xsh
Expand Up @@ -48,7 +48,7 @@ class Logger:
msg = '{INTENSE_CYAN}' + category + '{PURPLE}:'
if activity is not None:
msg += '{RED}' + activity + '{PURPLE}:'
msg += '{INTENSE_WHITE}' + message + '{NO_COLOR}'
msg += '{INTENSE_WHITE}' + message + '{RESET}'
print_color(msg)

def load(self):
Expand Down
12 changes: 6 additions & 6 deletions rever/main.xsh
Expand Up @@ -136,10 +136,10 @@ def run_activities(ns):
for name in done:
if ns.force:
msg = ("{YELLOW}Re-doing activity '" + name + "' which has already been "
"completed!{NO_COLOR}")
"completed!{RESET}")
else:
msg = ("{GREEN}Activity '" + name + "' has already been "
"completed!{NO_COLOR}")
"completed!{RESET}")
print_color(msg)
for name in need:
act = $DAG[name]
Expand Down Expand Up @@ -174,10 +174,10 @@ def setup_activities(ns):
if name in done:
if ns.force:
print_color("{YELLOW}Re-doing acctivity '" + name + "' which has "
"already been setup!{NO_COLOR}")
"already been setup!{RESET}")
else:
print_color("{GREEN}Activity '" + name + "' has already been "
"setup!{NO_COLOR}")
"setup!{RESET}")
continue
act = $DAG[name]
act.ns = ns
Expand Down Expand Up @@ -231,8 +231,8 @@ def env_main(args=None):
if os.path.exists(ns.rc):
source @(ns.rc)
else:
print_color('{RED}WARNING{NO_COLOR} the run control file {GREEN}' +
ns.rc + '{NO_COLOR} does not exist!', file=sys.stderr)
print_color('{RED}WARNING{RESET} the run control file {GREEN}' +
ns.rc + '{RESET} does not exist!', file=sys.stderr)
running_activities(ns)
# run the command
if ns.undo:
Expand Down
12 changes: 6 additions & 6 deletions rever/tools.xsh
Expand Up @@ -135,7 +135,7 @@ def progress(count, total=None, prefix='', suffix='', width=60, file=None,
if total is None:
bar = PONG[_NPONG]
_NPONG = (_NPONG + 1)%len(PONG)
fmt = ('{prefix}{{{color}}}{bar}{{NO_COLOR}} '
fmt = ('{prefix}{{{color}}}{bar}{{RESET}} '
'{frac} bytes{suffix}\r')
frac = count
else:
Expand All @@ -145,8 +145,8 @@ def progress(count, total=None, prefix='', suffix='', width=60, file=None,
if color is None:
color = 'YELLOW' if count < total else 'GREEN'
frac = count / float(total)
fmt = ('{prefix}[{{{color}}}{bar}{{NO_COLOR}}] '
'{{{color}}}{frac:.1%}{{NO_COLOR}}{suffix}\r')
fmt = ('{prefix}[{{{color}}}{bar}{{RESET}}] '
'{{{color}}}{frac:.1%}{{RESET}}{suffix}\r')
s = fmt.format(prefix=prefix, color=color, bar=bar, frac=frac,
suffix=suffix)
print_color(s, end='', file=file)
Expand Down Expand Up @@ -191,13 +191,13 @@ def stream_url_progress(url, verb='downloading', chunksize=1024, width=60,
totalbytes = getattr(f, 'length', None)
if totalbytes is None:
color = 'GREEN'
suffix = '{GREEN} TOTAL{NO_COLOR}\n'
suffix = '{GREEN} TOTAL{RESET}\n'
elif nbytes < totalbytes:
color = 'RED'
suffix = '{RED} FAILED{{NO_COLOR}\n'
suffix = '{RED} FAILED{{RESET}\n'
else:
color = 'GREEN'
suffix = '{GREEN} SUCCESS{NO_COLOR}\n'
suffix = '{GREEN} SUCCESS{RESET}\n'
progress(nbytes, totalbytes, color=color, suffix=suffix)


Expand Down

0 comments on commit a076bf7

Please sign in to comment.