Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Lint the contrib/ directory in CI and linting scripts, add synctl to …
Browse files Browse the repository at this point in the history
…linting script (#7914)

Run `isort`, `flake8` and `black` over the `contrib/` directory and `synctl` script. The latter was already being done in CI, but now the linting script does it too.

Fixes #7910
  • Loading branch information
anoadragon453 authored Jul 20, 2020
1 parent 5662e2b commit b7ddece
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 82 deletions.
1 change: 1 addition & 0 deletions changelog.d/7914.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lint the `contrib/` directory in CI and linting scripts, add `synctl` to the linting script for consistency with CI.
21 changes: 10 additions & 11 deletions contrib/cmdclient/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
""" Starts a synapse client console. """
from __future__ import print_function

from twisted.internet import reactor, defer, threads
from http import TwistedHttpClient

import argparse
import cmd
import getpass
Expand All @@ -28,12 +25,14 @@
import sys
import time
import urllib
import urlparse
from http import TwistedHttpClient

import nacl.signing
import nacl.encoding
import nacl.signing
import urlparse
from signedjson.sign import SignatureVerifyException, verify_signed_json

from signedjson.sign import verify_signed_json, SignatureVerifyException
from twisted.internet import defer, reactor, threads

CONFIG_JSON = "cmdclient_config.json"

Expand Down Expand Up @@ -493,7 +492,7 @@ def do_list(self, line):
"list messages <roomid> from=END&to=START&limit=3"
"""
args = self._parse(line, ["type", "roomid", "qp"])
if not "type" in args or not "roomid" in args:
if "type" not in args or "roomid" not in args:
print("Must specify type and room ID.")
return
if args["type"] not in ["members", "messages"]:
Expand All @@ -508,7 +507,7 @@ def do_list(self, line):
try:
key_value = key_value_str.split("=")
qp[key_value[0]] = key_value[1]
except:
except Exception:
print("Bad query param: %s" % key_value)
return

Expand Down Expand Up @@ -585,7 +584,7 @@ def do_raw(self, line):
parsed_url = urlparse.urlparse(args["path"])
qp.update(urlparse.parse_qs(parsed_url.query))
args["path"] = parsed_url.path
except:
except Exception:
pass

reactor.callFromThread(
Expand Down Expand Up @@ -772,10 +771,10 @@ def main(server_url, identity_server_url, username, token, config_path):
syn_cmd.config = json.load(config)
try:
http_client.verbose = "on" == syn_cmd.config["verbose"]
except:
except Exception:
pass
print("Loaded config from %s" % config_path)
except:
except Exception:
pass

# Twisted-specific: Runs the command processor in Twisted's event loop
Expand Down
10 changes: 5 additions & 5 deletions contrib/cmdclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# limitations under the License.

from __future__ import print_function
from twisted.web.client import Agent, readBody
from twisted.web.http_headers import Headers
from twisted.internet import defer, reactor

from pprint import pformat

import json
import urllib
from pprint import pformat

from twisted.internet import defer, reactor
from twisted.web.client import Agent, readBody
from twisted.web.http_headers import Headers


class HttpClient(object):
Expand Down
47 changes: 17 additions & 30 deletions contrib/experiments/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,24 @@
"""


from synapse.federation import ReplicationHandler

from synapse.federation.units import Pdu

from synapse.util import origin_from_ucid

from synapse.app.homeserver import SynapseHomeServer

# from synapse.logging.utils import log_function

from twisted.internet import reactor, defer
from twisted.python import log

import argparse
import curses.wrapper
import json
import logging
import os
import re

import cursesio
import curses.wrapper

from twisted.internet import defer, reactor
from twisted.python import log

from synapse.app.homeserver import SynapseHomeServer
from synapse.federation import ReplicationHandler
from synapse.federation.units import Pdu
from synapse.util import origin_from_ucid

# from synapse.logging.utils import log_function


logger = logging.getLogger("example")
Expand Down Expand Up @@ -201,16 +198,6 @@ def on_receive_pdu(self, pdu):
% (pdu.context, pdu.pdu_type, json.dumps(pdu.content))
)

# def on_state_change(self, pdu):
##self.output.print_line("#%s (state) %s *** %s" %
##(pdu.context, pdu.state_key, pdu.pdu_type)
##)

# if "joinee" in pdu.content:
# self._on_join(pdu.context, pdu.content["joinee"])
# elif "invitee" in pdu.content:
# self._on_invite(pdu.origin, pdu.context, pdu.content["invitee"])

def _on_message(self, pdu):
""" We received a message
"""
Expand Down Expand Up @@ -314,7 +301,7 @@ def backfill(self, room_name, limit=5):
return self.replication_layer.backfill(dest, room_name, limit)

def _get_room_remote_servers(self, room_name):
return [i for i in self.joined_rooms.setdefault(room_name).servers]
return list(self.joined_rooms.setdefault(room_name).servers)

def _get_or_create_room(self, room_name):
return self.joined_rooms.setdefault(room_name, Room(room_name))
Expand All @@ -334,7 +321,7 @@ def main(stdscr):
user = args.user
server_name = origin_from_ucid(user)

## Set up logging ##
# Set up logging

root_logger = logging.getLogger()

Expand All @@ -354,7 +341,7 @@ def main(stdscr):
observer = log.PythonLoggingObserver()
observer.start()

## Set up synapse server
# Set up synapse server

curses_stdio = cursesio.CursesStdIO(stdscr)
input_output = InputOutput(curses_stdio, user)
Expand All @@ -368,16 +355,16 @@ def main(stdscr):

input_output.set_home_server(hs)

## Add input_output logger
# Add input_output logger
io_logger = IOLoggerHandler(input_output)
io_logger.setFormatter(formatter)
root_logger.addHandler(io_logger)

## Start! ##
# Start!

try:
port = int(server_name.split(":")[1])
except:
except Exception:
port = 12345

app_hs.get_http_server().start_listening(port)
Expand Down
21 changes: 10 additions & 11 deletions contrib/graph/graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from __future__ import print_function

import argparse
import cgi
import datetime
import json

import pydot
import urllib2

# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,15 +23,6 @@
# limitations under the License.


import sqlite3
import pydot
import cgi
import json
import datetime
import argparse
import urllib2


def make_name(pdu_id, origin):
return "%s@%s" % (pdu_id, origin)

Expand All @@ -33,7 +32,7 @@ def make_graph(pdus, room, filename_prefix):
node_map = {}

origins = set()
colors = set(("red", "green", "blue", "yellow", "purple"))
colors = {"red", "green", "blue", "yellow", "purple"}

for pdu in pdus:
origins.add(pdu.get("origin"))
Expand All @@ -49,7 +48,7 @@ def make_graph(pdus, room, filename_prefix):
try:
c = colors.pop()
color_map[o] = c
except:
except Exception:
print("Run out of colours!")
color_map[o] = "black"

Expand Down
11 changes: 6 additions & 5 deletions contrib/graph/graph2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# limitations under the License.


import sqlite3
import pydot
import argparse
import cgi
import json
import datetime
import argparse
import json
import sqlite3

import pydot

from synapse.events import FrozenEvent
from synapse.util.frozenutils import unfreeze
Expand Down Expand Up @@ -98,7 +99,7 @@ def make_graph(db_name, room_id, file_prefix, limit):
for prev_id, _ in event.prev_events:
try:
end_node = node_map[prev_id]
except:
except Exception:
end_node = pydot.Node(name=prev_id, label="<<b>%s</b>>" % (prev_id,))

node_map[prev_id] = end_node
Expand Down
22 changes: 11 additions & 11 deletions contrib/graph/graph3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from __future__ import print_function

import argparse
import cgi
import datetime

import pydot
import simplejson as json

from synapse.events import FrozenEvent
from synapse.util.frozenutils import unfreeze

# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,16 +25,6 @@
# limitations under the License.


import pydot
import cgi
import simplejson as json
import datetime
import argparse

from synapse.events import FrozenEvent
from synapse.util.frozenutils import unfreeze


def make_graph(file_name, room_id, file_prefix, limit):
print("Reading lines")
with open(file_name) as f:
Expand Down Expand Up @@ -106,7 +106,7 @@ def make_graph(file_name, room_id, file_prefix, limit):
for prev_id, _ in event.prev_events:
try:
end_node = node_map[prev_id]
except:
except Exception:
end_node = pydot.Node(name=prev_id, label="<<b>%s</b>>" % (prev_id,))

node_map[prev_id] = end_node
Expand Down
10 changes: 5 additions & 5 deletions contrib/jitsimeetbridge/jitsimeetbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"""
from __future__ import print_function

import gevent
import grequests
from BeautifulSoup import BeautifulSoup
import json
import urllib
import subprocess
import time

# ACCESS_TOKEN="" #
import gevent
import grequests
from BeautifulSoup import BeautifulSoup

ACCESS_TOKEN = ""

MATRIXBASE = "https://matrix.org/_matrix/client/api/v1/"
MYUSERNAME = "@davetest:matrix.org"
Expand Down
6 changes: 4 additions & 2 deletions contrib/scripts/kick_users.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python
from __future__ import print_function
from argparse import ArgumentParser

import json
import requests
import sys
import urllib
from argparse import ArgumentParser

import requests

try:
raw_input
Expand Down
2 changes: 1 addition & 1 deletion scripts-dev/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [ $# -ge 1 ]
then
files=$*
else
files="synapse tests scripts-dev scripts"
files="synapse tests scripts-dev scripts contrib synctl"
fi

echo "Linting these locations: $files"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ deps =
black==19.10b0
commands =
python -m black --check --diff .
/bin/sh -c "flake8 synapse tests scripts scripts-dev synctl {env:PEP8SUFFIX:}"
/bin/sh -c "flake8 synapse tests scripts scripts-dev contrib synctl {env:PEP8SUFFIX:}"
{toxinidir}/scripts-dev/config-lint.sh

[testenv:check_isort]
Expand Down

0 comments on commit b7ddece

Please sign in to comment.