-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from cs50/style
Fix styling per style50
- Loading branch information
Showing
2 changed files
with
44 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
|
||
|
||
def install_certs(cmd): | ||
"""Decorator for classes subclassing one of setuptools commands. | ||
""" | ||
Decorator for classes subclassing one of setuptools commands. | ||
Installs certificates before installing the package when running | ||
Python >= 3.6 on Mac OS. | ||
|
@@ -16,8 +17,7 @@ def install_certs(cmd): | |
|
||
def run(self): | ||
if platform == "darwin" and version_info >= (3, 6): | ||
INSTALL_CERTS = \ | ||
"/Applications/Python 3.6/Install Certificates.command" | ||
INSTALL_CERTS = "/Applications/Python 3.6/Install Certificates.command" | ||
if not isfile(INSTALL_CERTS) or call(INSTALL_CERTS) != 0: | ||
raise RuntimeError("Error installing certificates.") | ||
orig_run(self) | ||
|
@@ -35,6 +35,7 @@ class CustomDevelop(develop): | |
class CustomInstall(install): | ||
pass | ||
|
||
|
||
setup( | ||
author="CS50", | ||
author_email="[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,10 +66,13 @@ class _Getch: | |
|
||
class _GetchUnix: | ||
def __init__(self): | ||
import tty, sys | ||
import tty | ||
import sys | ||
|
||
def __call__(self): | ||
import sys, termios, tty | ||
import sys | ||
import termios | ||
import tty | ||
fd = sys.stdin.fileno() | ||
old_settings = termios.tcgetattr(fd) | ||
try: | ||
|
@@ -136,16 +139,18 @@ def authenticate(org): | |
cache = os.path.expanduser("~/.git-credential-cache") | ||
try: | ||
os.mkdir(cache, 0o700) | ||
except: | ||
except BaseException: | ||
pass | ||
authenticate.SOCKET = os.path.join(cache, ORG) | ||
|
||
# check cache | ||
child = pexpect.spawn("git -c credential.helper='cache --socket {}' credential fill".format(authenticate.SOCKET)) | ||
spawn = pexpect.spawn if sys.version_info < (3, 0) else pexpect.spawnu | ||
child = spawn( | ||
"git -c credential.helper='cache --socket {}' credential fill".format(authenticate.SOCKET)) | ||
child.sendline("") | ||
if child.expect(["Username:", "Password:", pexpect.EOF]) == 2: | ||
clear_credentials() | ||
username, password = re.search("username=([^\r]+)\r\npassword=([^\r]+)", child.before, re.MULTILINE).groups() | ||
username, password = re.search( | ||
"username=([^\r]+)\r\npassword=([^\r]+)", child.before, re.MULTILINE).groups() | ||
else: | ||
try: | ||
username = run("git config --global credential.https://github.com/submit50.username", quiet=True) | ||
|
@@ -164,10 +169,10 @@ def rlinput(prompt, prefill=""): | |
try: | ||
return input(prompt) | ||
finally: | ||
readline.set_startup_hook() | ||
readline.set_startup_hook() | ||
|
||
# prompt for credentials | ||
progress(False) # because not using cprint herein | ||
progress(False) # because not using cprint herein | ||
if not password: | ||
|
||
# prompt for username, prefilling if possible | ||
|
@@ -187,18 +192,18 @@ def rlinput(prompt, prefill=""): | |
password = str() | ||
while True: | ||
ch = getch() | ||
if ch in ["\n", "\r"]: # Enter | ||
if ch in ["\n", "\r"]: # Enter | ||
print() | ||
break | ||
elif ch == "\177": # DEL | ||
elif ch == "\177": # DEL | ||
if len(password) > 0: | ||
password = password[:-1] | ||
print("\b \b", end="") | ||
sys.stdout.flush() | ||
elif ch == "\3": # ctrl-c | ||
elif ch == "\3": # ctrl-c | ||
print("^C", end="") | ||
os.kill(os.getpid(), signal.SIGINT) | ||
elif ch == "\4": # ctrl-d | ||
elif ch == "\4": # ctrl-d | ||
print() | ||
break | ||
else: | ||
|
@@ -264,7 +269,8 @@ def cprint(text="", color=None, on_color=None, attrs=None, **kwargs): | |
|
||
# assume 80 in case not running in a terminal | ||
columns, lines = get_terminal_size() | ||
if columns == 0: columns = 80 # because get_terminal_size's default fallback doesn't work in pipes | ||
if columns == 0: | ||
columns = 80 # because get_terminal_size's default fallback doesn't work in pipes | ||
|
||
# print text | ||
termcolor.cprint(textwrap.fill(text, columns, drop_whitespace=False), | ||
|
@@ -284,19 +290,20 @@ def excepthook(type, value, tb): | |
if run.verbose: | ||
traceback.print_exception(type, value, tb) | ||
cprint(_("Sorry, something's wrong! Let [email protected] know!"), "yellow") | ||
if authenticate.SOCKET: # not set when using SSH | ||
if authenticate.SOCKET: # not set when using SSH | ||
try: | ||
clear_credentials() | ||
except Exception: | ||
pass | ||
cprint(_("Submission cancelled."), "red") | ||
|
||
|
||
sys.excepthook = excepthook | ||
|
||
|
||
def handler(number, frame): | ||
"""Handle SIGINT.""" | ||
os.system("stty sane 2> {}".format(os.devnull)) # in case signalled from input_with_prefill | ||
os.system("stty sane 2> {}".format(os.devnull)) # in case signalled from input_with_prefill | ||
if progress.progressing: | ||
progress(False) | ||
else: | ||
|
@@ -333,7 +340,13 @@ def run(command, cwd=None, env=None, lines=[], password=None, quiet=False, timeo | |
if sys.version_info < (3, 0): | ||
child = pexpect.spawn(command, cwd=cwd, env=env, ignore_sighup=True, timeout=timeout) | ||
else: | ||
child = pexpect.spawnu(command, cwd=cwd, encoding="utf-8", env=env, ignore_sighup=True, timeout=timeout) | ||
child = pexpect.spawnu( | ||
command, | ||
cwd=cwd, | ||
encoding="utf-8", | ||
env=env, | ||
ignore_sighup=True, | ||
timeout=timeout) | ||
|
||
# send output of command to stdout only if run with --verbose (and not quieted by caller) | ||
if run.verbose and not quiet: | ||
|
@@ -367,7 +380,7 @@ def progress(message=""): | |
|
||
# don't show in verbose mode | ||
if run.verbose: | ||
if message != False: | ||
if message: | ||
print(message + "...") | ||
return | ||
|
||
|
@@ -379,7 +392,7 @@ def progress(message=""): | |
sys.stdout.flush() | ||
|
||
# display dots if message passed | ||
if message != False: | ||
if message: | ||
def progress_helper(): | ||
sys.stdout.write(message + "...") | ||
sys.stdout.flush() | ||
|
@@ -410,7 +423,8 @@ def submit(org, branch): | |
version = subprocess.check_output(["git", "--version"]).decode("utf-8") | ||
matches = re.search(r"^git version (\d+\.\d+\.\d+).*$", version) | ||
if not matches or StrictVersion(matches.group(1)) < StrictVersion("2.7.0"): | ||
raise Error(_("You have an old version of git. Install version 2.7 or later, then re-run {}!".format(org))) | ||
raise Error( | ||
_("You have an old version of git. Install version 2.7 or later, then re-run {}!".format(org))) | ||
|
||
# update progress | ||
progress("Connecting") | ||
|
@@ -479,7 +493,8 @@ def submit(org, branch): | |
assert which("ssh") | ||
|
||
# require GitHub username in ~/.gitconfig | ||
username, password = run("git config --global credential.https://github.com/submit50.username", quiet=True), None | ||
username, password = run( | ||
"git config --global credential.https://github.com/submit50.username", quiet=True), None | ||
email = "{}@users.noreply.github.com".format(username) | ||
repo = "[email protected]:{}/{}.git".format(org, username) | ||
progress(False) | ||
|
@@ -491,7 +506,7 @@ def submit(org, branch): | |
assert i == 2 | ||
|
||
# authenticate user via HTTPS | ||
except: | ||
except BaseException: | ||
username, password, email = authenticate(org) | ||
repo = "https://{}@github.com/{}/{}".format(username, org, username) | ||
|
||
|
@@ -500,8 +515,9 @@ def submit(org, branch): | |
|
||
# clone repository | ||
try: | ||
run("git clone --bare {} {}".format(shlex.quote(repo), shlex.quote(run.GIT_DIR)), password=password) | ||
except: | ||
run("git clone --bare {} {}".format(shlex.quote(repo), | ||
shlex.quote(run.GIT_DIR)), password=password) | ||
except BaseException: | ||
if password: | ||
e = Error(_("Looks like {} isn't enabled for your account yet. " | ||
"Log into https://cs50.me/ in a browser, click \"Authorize application\", and re-run {} here!".format(org, org))) | ||
|
@@ -563,7 +579,7 @@ def submit(org, branch): | |
"Install git-lfs (or remove these files from your directory) " | ||
"and then re-run {}!").format("\n".join(large), org)) | ||
run("git lfs install --local") | ||
run("git config credential.helper cache") # for pre-push hook | ||
run("git config credential.helper cache") # for pre-push hook | ||
for file in large: | ||
run("git lfs track {}".format(file)) | ||
run("git add --force .gitattributes") | ||
|