Skip to content

Commit

Permalink
Ran black on master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Griatch committed Dec 16, 2019
1 parent 9879d3a commit 064bf30
Show file tree
Hide file tree
Showing 225 changed files with 6,896 additions and 2,168 deletions.
34 changes: 17 additions & 17 deletions .travis/mysql_settings.py
Expand Up @@ -39,25 +39,25 @@
# Testing database types # Testing database types


DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.mysql', "ENGINE": "django.db.backends.mysql",
'NAME': 'evennia', "NAME": "evennia",
'USER': 'evennia', "USER": "evennia",
'PASSWORD': 'password', "PASSWORD": "password",
'HOST': 'localhost', "HOST": "localhost",
'PORT': '', # use default port "PORT": "", # use default port
'OPTIONS': { "OPTIONS": {
'charset': 'utf8mb4', "charset": "utf8mb4",
'init_command': 'set collation_connection=utf8mb4_unicode_ci' "init_command": "set collation_connection=utf8mb4_unicode_ci",
}, },
'TEST': { "TEST": {
'NAME': 'default', "NAME": "default",
'OPTIONS': { "OPTIONS": {
'charset': 'utf8mb4', "charset": "utf8mb4",
# 'init_command': 'set collation_connection=utf8mb4_unicode_ci' # 'init_command': 'set collation_connection=utf8mb4_unicode_ci'
'init_command': "SET NAMES 'utf8mb4'" "init_command": "SET NAMES 'utf8mb4'",
} },
} },
} }
} }


Expand Down
18 changes: 8 additions & 10 deletions .travis/postgresql_settings.py
Expand Up @@ -39,16 +39,14 @@
# Testing database types # Testing database types


DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.postgresql_psycopg2', "ENGINE": "django.db.backends.postgresql_psycopg2",
'NAME': 'evennia', "NAME": "evennia",
'USER': 'evennia', "USER": "evennia",
'PASSWORD': 'password', "PASSWORD": "password",
'HOST': 'localhost', "HOST": "localhost",
'PORT': '', # use default "PORT": "", # use default
'TEST': { "TEST": {"NAME": "default"},
'NAME': 'default'
}
} }
} }


Expand Down
138 changes: 92 additions & 46 deletions bin/project_rename.py
Expand Up @@ -23,7 +23,7 @@
FAKE_MODE = False FAKE_MODE = False


# if these words are longer than output word, retain given case # if these words are longer than output word, retain given case
CASE_WORD_EXCEPTIONS = ('an', ) CASE_WORD_EXCEPTIONS = ("an",)


_HELP_TEXT = """This program interactively renames words in all files of your project. It's _HELP_TEXT = """This program interactively renames words in all files of your project. It's
currently renaming {sources} to {targets}. currently renaming {sources} to {targets}.
Expand Down Expand Up @@ -80,6 +80,7 @@ def _case_sensitive_replace(string, old, new):
`old` has been replaced with `new`, retaining case. `old` has been replaced with `new`, retaining case.
""" """

def repl(match): def repl(match):
current = match.group() current = match.group()
# treat multi-word sentences word-by-word # treat multi-word sentences word-by-word
Expand All @@ -99,15 +100,21 @@ def repl(match):
all_upper = False all_upper = False
# special cases - keep remaing case) # special cases - keep remaing case)
if new_word.lower() in CASE_WORD_EXCEPTIONS: if new_word.lower() in CASE_WORD_EXCEPTIONS:
result.append(new_word[ind + 1:]) result.append(new_word[ind + 1 :])
# append any remaining characters from new # append any remaining characters from new
elif all_upper: elif all_upper:
result.append(new_word[ind + 1:].upper()) result.append(new_word[ind + 1 :].upper())
else: else:
result.append(new_word[ind + 1:].lower()) result.append(new_word[ind + 1 :].lower())
out.append("".join(result)) out.append("".join(result))
# if we have more new words than old ones, just add them verbatim # if we have more new words than old ones, just add them verbatim
out.extend([new_word for ind, new_word in enumerate(new_words) if ind >= len(old_words)]) out.extend(
[
new_word
for ind, new_word in enumerate(new_words)
if ind >= len(old_words)
]
)
return " ".join(out) return " ".join(out)


regex = re.compile(re.escape(old), re.I) regex = re.compile(re.escape(old), re.I)
Expand Down Expand Up @@ -147,16 +154,20 @@ def rename_in_tree(path, in_list, out_list, excl_list, fileend_list, is_interact
print("%s skipped (excluded)." % full_path) print("%s skipped (excluded)." % full_path)
continue continue


if not fileend_list or any(file.endswith(ending) for ending in fileend_list): if not fileend_list or any(
file.endswith(ending) for ending in fileend_list
):
rename_in_file(full_path, in_list, out_list, is_interactive) rename_in_file(full_path, in_list, out_list, is_interactive)


# rename file - always ask # rename file - always ask
new_file = file new_file = file
for src, dst in repl_mapping: for src, dst in repl_mapping:
new_file = _case_sensitive_replace(new_file, src, dst) new_file = _case_sensitive_replace(new_file, src, dst)
if new_file != file: if new_file != file:
inp = input(_green("Rename %s\n -> %s\n Y/[N]? > " % (file, new_file))) inp = input(
if inp.upper() == 'Y': _green("Rename %s\n -> %s\n Y/[N]? > " % (file, new_file))
)
if inp.upper() == "Y":
new_full_path = os.path.join(root, new_file) new_full_path = os.path.join(root, new_file)
try: try:
os.rename(full_path, new_full_path) os.rename(full_path, new_full_path)
Expand All @@ -171,8 +182,10 @@ def rename_in_tree(path, in_list, out_list, excl_list, fileend_list, is_interact
for src, dst in repl_mapping: for src, dst in repl_mapping:
new_root = _case_sensitive_replace(new_root, src, dst) new_root = _case_sensitive_replace(new_root, src, dst)
if new_root != root: if new_root != root:
inp = input(_green("Dir Rename %s\n -> %s\n Y/[N]? > " % (root, new_root))) inp = input(
if inp.upper() == 'Y': _green("Dir Rename %s\n -> %s\n Y/[N]? > " % (root, new_root))
)
if inp.upper() == "Y":
try: try:
os.rename(root, new_root) os.rename(root, new_root)
except OSError as err: except OSError as err:
Expand Down Expand Up @@ -201,7 +214,7 @@ def rename_in_file(path, in_list, out_list, is_interactive):
print("%s is a directory. You should use the --recursive option." % path) print("%s is a directory. You should use the --recursive option." % path)
sys.exit() sys.exit()


with open(path, 'r') as fil: with open(path, "r") as fil:
org_text = fil.read() org_text = fil.read()


repl_mapping = list(zip(in_list, out_list)) repl_mapping = list(zip(in_list, out_list))
Expand All @@ -215,7 +228,7 @@ def rename_in_file(path, in_list, out_list, is_interactive):
if FAKE_MODE: if FAKE_MODE:
print(" ... Saved changes to %s. (faked)" % path) print(" ... Saved changes to %s. (faked)" % path)
else: else:
with open(path, 'w') as fil: with open(path, "w") as fil:
fil.write(new_text) fil.write(new_text)
print(" ... Saved changes to %s." % path) print(" ... Saved changes to %s." % path)
else: else:
Expand All @@ -239,18 +252,24 @@ def rename_in_file(path, in_list, out_list, is_interactive):


while True: while True:


for iline, renamed_line in sorted(list(renamed.items()), key=lambda tup: tup[0]): for iline, renamed_line in sorted(
list(renamed.items()), key=lambda tup: tup[0]
):
print("%3i orig: %s" % (iline + 1, org_lines[iline])) print("%3i orig: %s" % (iline + 1, org_lines[iline]))
print(" new : %s" % (_yellow(renamed_line))) print(" new : %s" % (_yellow(renamed_line)))
print(_green("%s (%i lines changed)" % (path, len(renamed)))) print(_green("%s (%i lines changed)" % (path, len(renamed))))


ret = input(_green("Choose: " ret = input(
"[q]uit, " _green(
"[h]elp, " "Choose: "
"[s]kip file, " "[q]uit, "
"[i]gnore lines, " "[h]elp, "
"[c]lear ignores, " "[s]kip file, "
"[a]ccept/save file: ".lower())) "[i]gnore lines, "
"[c]lear ignores, "
"[a]ccept/save file: ".lower()
)
)


if ret == "s": if ret == "s":
# skip file entirely # skip file entirely
Expand All @@ -267,7 +286,7 @@ def rename_in_file(path, in_list, out_list, is_interactive):
if FAKE_MODE: if FAKE_MODE:
print(" ... Saved file %s (faked)" % path) print(" ... Saved file %s (faked)" % path)
return return
with open(path, 'w') as fil: with open(path, "w") as fil:
fil.writelines("\n".join(org_lines)) fil.writelines("\n".join(org_lines))
print(" ... Saved file %s" % path) print(" ... Saved file %s" % path)
return return
Expand All @@ -278,7 +297,11 @@ def rename_in_file(path, in_list, out_list, is_interactive):
input(_HELP_TEXT.format(sources=in_list, targets=out_list)) input(_HELP_TEXT.format(sources=in_list, targets=out_list))
elif ret.startswith("i"): elif ret.startswith("i"):
# ignore one or more lines # ignore one or more lines
ignores = [int(ind) - 1 for ind in ret[1:].split(',') if ind.strip().isdigit()] ignores = [
int(ind) - 1
for ind in ret[1:].split(",")
if ind.strip().isdigit()
]
if not ignores: if not ignores:
input("Ignore example: i 2,7,34,133\n (return to continue)") input("Ignore example: i 2,7,34,133\n (return to continue)")
continue continue
Expand All @@ -291,36 +314,57 @@ def rename_in_file(path, in_list, out_list, is_interactive):
import argparse import argparse


parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Rename text in a source tree, or a single file") description="Rename text in a source tree, or a single file"

)
parser.add_argument('-i', '--input', action='append',
help="Source word to rename (quote around multiple words)") parser.add_argument(
parser.add_argument('-o', '--output', action='append', "-i",
help="Word to rename a matching src-word to") "--input",
parser.add_argument('-x', '--exc', action='append', action="append",
help="File path patterns to exclude") help="Source word to rename (quote around multiple words)",
parser.add_argument('-a', '--auto', action='store_true', )
help="Automatic mode, don't ask to rename") parser.add_argument(
parser.add_argument('-r', '--recursive', action='store_true', "-o", "--output", action="append", help="Word to rename a matching src-word to"
help="Recurse subdirs") )
parser.add_argument('-f', '--fileending', action='append', parser.add_argument(
help="Change which file endings to allow (default .py and .html)") "-x", "--exc", action="append", help="File path patterns to exclude"
parser.add_argument('--nocolor', action='store_true', )
help="Turn off in-program color") parser.add_argument(
parser.add_argument('--fake', action='store_true', "-a", "--auto", action="store_true", help="Automatic mode, don't ask to rename"
help="Simulate run but don't actually save") )
parser.add_argument('path', parser.add_argument(
help="File or directory in which to rename text") "-r", "--recursive", action="store_true", help="Recurse subdirs"
)
parser.add_argument(
"-f",
"--fileending",
action="append",
help="Change which file endings to allow (default .py and .html)",
)
parser.add_argument(
"--nocolor", action="store_true", help="Turn off in-program color"
)
parser.add_argument(
"--fake", action="store_true", help="Simulate run but don't actually save"
)
parser.add_argument("path", help="File or directory in which to rename text")


args = parser.parse_args() args = parser.parse_args()


in_list, out_list, exc_list, fileend_list = args.input, args.output, args.exc, args.fileending in_list, out_list, exc_list, fileend_list = (
args.input,
args.output,
args.exc,
args.fileending,
)


if not (in_list and out_list): if not (in_list and out_list):
print('At least one source- and destination word must be given.') print("At least one source- and destination word must be given.")
sys.exit() sys.exit()
if len(in_list) != len(out_list): if len(in_list) != len(out_list):
print('Number of sources must be identical to the number of destination arguments.') print(
"Number of sources must be identical to the number of destination arguments."
)
sys.exit() sys.exit()


exc_list = exc_list or [] exc_list = exc_list or []
Expand All @@ -332,6 +376,8 @@ def rename_in_file(path, in_list, out_list, is_interactive):
FAKE_MODE = args.fake FAKE_MODE = args.fake


if is_recursive: if is_recursive:
rename_in_tree(args.path, in_list, out_list, exc_list, fileend_list, is_interactive) rename_in_tree(
args.path, in_list, out_list, exc_list, fileend_list, is_interactive
)
else: else:
rename_in_file(args.path, in_list, out_list, is_interactive) rename_in_file(args.path, in_list, out_list, is_interactive)
1 change: 1 addition & 0 deletions bin/windows/evennia_launcher.py
Expand Up @@ -14,4 +14,5 @@
sys.path.insert(0, os.path.join(sys.prefix, "Lib", "site-packages")) sys.path.insert(0, os.path.join(sys.prefix, "Lib", "site-packages"))


from evennia.server.evennia_launcher import main from evennia.server.evennia_launcher import main

main() main()
8 changes: 6 additions & 2 deletions evennia/__init__.py
Expand Up @@ -142,7 +142,9 @@ def _create_version():
print(err) print(err)
try: try:
rev = ( rev = (
check_output("git rev-parse --short HEAD", shell=True, cwd=root, stderr=STDOUT) check_output(
"git rev-parse --short HEAD", shell=True, cwd=root, stderr=STDOUT
)
.strip() .strip()
.decode() .decode()
) )
Expand Down Expand Up @@ -261,7 +263,9 @@ class _EvContainer(object):


def _help(self): def _help(self):
"Returns list of contents" "Returns list of contents"
names = [name for name in self.__class__.__dict__ if not name.startswith("_")] names = [
name for name in self.__class__.__dict__ if not name.startswith("_")
]
names += [name for name in self.__dict__ if not name.startswith("_")] names += [name for name in self.__dict__ if not name.startswith("_")]
print(self.__doc__ + "-" * 60 + "\n" + ", ".join(names)) print(self.__doc__ + "-" * 60 + "\n" + ", ".join(names))


Expand Down

0 comments on commit 064bf30

Please sign in to comment.