diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..61d90815 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 99 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..872dcaf6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: + - "3.6" +install: + - "pip install -r requirements.txt" + - "pip install flake8" +script: flake8 diff --git a/chaos.py b/chaos.py index e0740ed6..d6a3c3c7 100644 --- a/chaos.py +++ b/chaos.py @@ -6,11 +6,8 @@ import time import sys import logging -import threading -import http.server import subprocess import settings -import patch import schedule import cron import github_api as gh @@ -20,15 +17,14 @@ import github_api.comments # Has a sideeffect of creating private key if one doesn't exist already -import encryption - -from github_api import exceptions as gh_exc +# Currently imported just for the sideeffect (not currently being used) +import encryption # noqa: F401 def main(): logging.basicConfig(level=logging.DEBUG, - format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', - datefmt='%m-%d %H:%M') + format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', + datefmt='%m-%d %H:%M') logging.getLogger("requests").propagate = False logging.getLogger("sh").propagate = False diff --git a/github_api/__init__.py b/github_api/__init__.py index 9392b472..d83da816 100644 --- a/github_api/__init__.py +++ b/github_api/__init__.py @@ -2,7 +2,6 @@ import re import math import requests -import json from requests.auth import HTTPBasicAuth import logging @@ -25,7 +24,7 @@ class API(object): BASE_URL = "https://api.github.com" BASE_HEADERS = { - #"Accept": "application/vnd.github.v3+json" + # "Accept": "application/vnd.github.v3+json" # so we have access to the reactions api "Accept": "application/vnd.github.squirrel-girl-preview+json" } diff --git a/github_api/comments.py b/github_api/comments.py index 53196e29..7e3aa7d4 100644 --- a/github_api/comments.py +++ b/github_api/comments.py @@ -1,4 +1,3 @@ -import arrow import settings from . import prs diff --git a/github_api/prs.py b/github_api/prs.py index be975870..2892affc 100644 --- a/github_api/prs.py +++ b/github_api/prs.py @@ -1,5 +1,6 @@ import arrow import settings +from requests import HTTPError from . import misc from . import voting from . import comments @@ -71,8 +72,9 @@ def formatted_votes_summary(votes, total, threshold): vfor = sum(v for v in votes.values() if v > 0) vagainst = abs(sum(v for v in votes.values() if v < 0)) - return "with a vote of {vfor} for and {vagainst} against, with a weighted total of {total:.1f} and a threshold of {threshold:.1f}" \ - .strip().format(vfor=vfor, vagainst=vagainst, total=total, threshold=threshold) + return ("with a vote of {vfor} for and {vagainst} against, with a weighted total \ + of {total:.1f} and a threshold of {threshold:.1f}" + .strip().format(vfor=vfor, vagainst=vagainst, total=total, threshold=threshold)) def formatted_votes_short_summary(votes, total, threshold): @@ -89,7 +91,7 @@ def label_pr(api, urn, pr_num, labels): labels = [labels] path = "/repos/{urn}/issues/{pr}/labels".format(urn=urn, pr=pr_num) data = labels - resp = api("PUT", path, json=data) + return api("PUT", path, json=data) def close_pr(api, urn, pr): diff --git a/github_api/repos.py b/github_api/repos.py index 51a0bf96..5f25abd9 100644 --- a/github_api/repos.py +++ b/github_api/repos.py @@ -1,5 +1,6 @@ import settings + def get_num_watchers(api, urn): """ returns the number of watchers for a repo """ path = "/repos/{urn}".format(urn=urn) diff --git a/github_api/users.py b/github_api/users.py index d3801774..d58d5d3e 100644 --- a/github_api/users.py +++ b/github_api/users.py @@ -1,10 +1,9 @@ def get_user(api, user): path = "/users/{user}".format(user=user) - data = api("get", path) - return data + return api("get", path) def follow_user(api, user): follow_path = "/user/following/{user}".format(user=user) - follow_resp = api("PUT", follow_path) + return api("PUT", follow_path) diff --git a/github_api/voting.py b/github_api/voting.py index 6899f203..50e77e0b 100644 --- a/github_api/voting.py +++ b/github_api/voting.py @@ -1,6 +1,4 @@ -from math import log import arrow -import re from emoji import demojize from . import prs diff --git a/memoize/__init__.py b/memoize/__init__.py index 7d6fbd07..d6d1da59 100644 --- a/memoize/__init__.py +++ b/memoize/__init__.py @@ -1 +1,3 @@ from .decorator import memoize + +__all__ = ["memoize"] diff --git a/misc.py b/misc.py index de7ed7a1..1a768654 100644 --- a/misc.py +++ b/misc.py @@ -1,13 +1,14 @@ -import re import sh from urllib.parse import urlparse + def removeDotGit(url): """ Remove trailing `.git` from the git remote url """ if url.endswith('.git'): return url[:-4] return url + def get_self_urn(): """ determine the URN for the repo on github by looking at the remote named "origin", and parsing it, or using a sensible default. this will allow @@ -33,4 +34,3 @@ def get_self_urn(): urn = "chaosbot/chaos" return urn - diff --git a/patch.py b/patch.py index 6d34b2ac..e1698b34 100644 --- a/patch.py +++ b/patch.py @@ -15,12 +15,14 @@ import github_api.voting import github_api.repos + def decorate(fn, dec): """helper for monkey-patch-decorating functions in different modules""" mod = inspect.getmodule(fn) new_fn = dec(fn) setattr(mod, fn.__name__, new_fn) + cache_dir = join(dirname(abspath(__file__)), settings.MEMOIZE_CACHE_DIRNAME) api_memoize = partial(memoize, blacklist={"api"}, backend=json_backend(cache_dir)) diff --git a/redditchaosbot.py b/redditchaosbot.py index 8a16f888..4876561e 100755 --- a/redditchaosbot.py +++ b/redditchaosbot.py @@ -2,8 +2,6 @@ # -*- coding: utf-8 -*- import praw -import pprint -from praw.models import MoreComments '''Authenticated instance of Reddit''' diff --git a/server/server.py b/server/server.py index 1f3149a7..c462eb20 100644 --- a/server/server.py +++ b/server/server.py @@ -5,6 +5,7 @@ import socketserver import socket + def set_proc_name(newname): """Change the process name using libc.so.6""" from ctypes import cdll, byref, create_string_buffer @@ -36,5 +37,6 @@ def main(): # serve HTTP on port 80 httpd.serve_forever() + if __name__ == "__main__": main()