Skip to content

Commit

Permalink
Fix flake8 errors and run flake8 in Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed May 27, 2017
1 parent e3bd2d4 commit f8caa0e
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .flake8
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 99
7 changes: 7 additions & 0 deletions .travis.yml
@@ -0,0 +1,7 @@
language: python
python:
- "3.6"
install:
- "pip install -r requirements.txt"
- "pip install flake8"
script: flake8
12 changes: 4 additions & 8 deletions chaos.py
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 1 addition & 2 deletions github_api/__init__.py
Expand Up @@ -2,7 +2,6 @@
import re
import math
import requests
import json
from requests.auth import HTTPBasicAuth
import logging

Expand All @@ -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"
}
Expand Down
1 change: 0 additions & 1 deletion github_api/comments.py
@@ -1,4 +1,3 @@
import arrow
import settings
from . import prs

Expand Down
8 changes: 5 additions & 3 deletions 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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions 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)
Expand Down
5 changes: 2 additions & 3 deletions 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)
2 changes: 0 additions & 2 deletions github_api/voting.py
@@ -1,6 +1,4 @@
from math import log
import arrow
import re
from emoji import demojize

from . import prs
Expand Down
2 changes: 2 additions & 0 deletions memoize/__init__.py
@@ -1 +1,3 @@
from .decorator import memoize

__all__ = ["memoize"]
4 changes: 2 additions & 2 deletions 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
Expand All @@ -33,4 +34,3 @@ def get_self_urn():
urn = "chaosbot/chaos"

return urn

2 changes: 2 additions & 0 deletions patch.py
Expand Up @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions redditchaosbot.py
Expand Up @@ -2,8 +2,6 @@
# -*- coding: utf-8 -*-

import praw
import pprint
from praw.models import MoreComments


'''Authenticated instance of Reddit'''
Expand Down
2 changes: 2 additions & 0 deletions server/server.py
Expand Up @@ -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
Expand Down Expand Up @@ -36,5 +37,6 @@ def main():
# serve HTTP on port 80
httpd.serve_forever()


if __name__ == "__main__":
main()

0 comments on commit f8caa0e

Please sign in to comment.