Skip to content

Commit fe4459b

Browse files
authored
Merge pull request #1084 from isso-comments/ruff
Format with ruff
2 parents 009e2c9 + 459853b commit fe4459b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1578
-1753
lines changed

.github/workflows/python-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ jobs:
7272
run: pip install pytest pytest-cov
7373

7474
- name: Install style check dependencies
75-
run: pip install flake8
75+
run: pip install ruff
7676

7777
- name: Run style check
7878
run: make flakes
7979

80+
- name: Run format check
81+
run: make format-check
82+
8083
- name: Run coverage check, fail if <70%
8184
run: |
8285
make coverage

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RUN virtualenv --download /isso \
5353
# Install Isso's python dependencies via pip in a separate step before copying
5454
# over client files, so that changing Isso js/python source code will not
5555
# trigger a re-installation of all pip packages from scratch
56-
COPY ["setup.py", "setup.cfg", "README.md", "LICENSE", "./"]
56+
COPY ["setup.py", "pyproject.toml", "README.md", "LICENSE", "./"]
5757
RUN --mount=type=cache,target=/root/.cache \
5858
. /isso/bin/activate \
5959
&& pip install -e .

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ init:
4949
npm install --omit=optional
5050

5151
flakes:
52-
flake8 isso/ contrib/ --count --max-line-length=127 --show-source --statistics
52+
ruff check isso/ contrib/ --statistics
53+
54+
format:
55+
ruff format isso/ contrib/
56+
57+
format-check:
58+
ruff format --check isso/ contrib/
5359

5460
# Note: It doesn't make sense to split up configs by output file with
5561
# webpack, just run everything at once

contrib/dump_comments.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,24 @@
4444
from textwrap import indent
4545

4646

47-
class ColorFallback():
48-
__getattr__ = lambda self, name: '' # noqa: E731
47+
class ColorFallback:
48+
__getattr__ = lambda self, name: "" # noqa: E731
4949

5050

5151
try:
5252
from colorama import Fore, Style, init
53+
5354
init() # needed for Windows
5455
except ImportError: # fallback so that the imported classes always exist
5556
Fore = Style = ColorFallback()
5657

5758

58-
Comment = namedtuple('Comment', ('uri', 'id', 'parent', 'created', 'text', 'author', 'email', 'website', 'likes', 'dislikes', 'replies'))
59+
Comment = namedtuple(
60+
"Comment", ("uri", "id", "parent", "created", "text", "author", "email", "website", "likes", "dislikes", "replies")
61+
)
5962

60-
INDENT = ' '
61-
QUERY = 'SELECT uri, comments.id, parent, created, text, author, email, website, likes, dislikes FROM comments INNER JOIN threads on comments.tid = threads.id'
63+
INDENT = " "
64+
QUERY = "SELECT uri, comments.id, parent, created, text, author, email, website, likes, dislikes FROM comments INNER JOIN threads on comments.tid = threads.id"
6265

6366

6467
def main():
@@ -95,34 +98,44 @@ def main():
9598

9699

97100
def print_comment(prefix, comment):
98-
author = comment.author or 'Anonymous'
99-
email = comment.email or ''
100-
website = comment.website or ''
101+
author = comment.author or "Anonymous"
102+
email = comment.email or ""
103+
website = comment.website or ""
101104
when = date.fromtimestamp(comment.created)
102-
popularity = ''
105+
popularity = ""
103106
if comment.likes:
104-
popularity = '+{.likes}'.format(comment)
107+
popularity = "+{.likes}".format(comment)
105108
if comment.dislikes:
106109
if popularity:
107-
popularity += '/'
108-
popularity = '-{.dislikes}'.format(comment)
109-
print(prefix + '{Style.BRIGHT}{author}{Style.RESET_ALL} {Style.DIM}- {email} {website}{Style.RESET_ALL} {when} {Style.DIM}{popularity}{Style.RESET_ALL}'.format(Style=Style, **locals()))
110+
popularity += "/"
111+
popularity = "-{.dislikes}".format(comment)
112+
print(
113+
prefix
114+
+ "{Style.BRIGHT}{author}{Style.RESET_ALL} {Style.DIM}- {email} {website}{Style.RESET_ALL} {when} {Style.DIM}{popularity}{Style.RESET_ALL}".format(
115+
Style=Style, **locals()
116+
)
117+
)
110118
print(indent(comment.text, prefix))
111119

112120

113121
def parse_args():
114-
parser = argparse.ArgumentParser(description='Dump all Isso comments in chronological order, grouped by replies',
115-
formatter_class=ArgparseHelpFormatter)
116-
parser.add_argument('db_path', help='File path to Isso Sqlite DB')
117-
parser.add_argument('--sort-by-last-reply', action='store_true', help='By default comments are sorted by "parent" comment date, this sort comments based on the last replies')
118-
parser.add_argument('--url-prefix', default='', help='Optional domain name to prefix to pages URLs')
119-
parser.add_argument('--no-colors', action='store_false', dest='colors', default=True, help='Disabled colored output')
122+
parser = argparse.ArgumentParser(
123+
description="Dump all Isso comments in chronological order, grouped by replies", formatter_class=ArgparseHelpFormatter
124+
)
125+
parser.add_argument("db_path", help="File path to Isso Sqlite DB")
126+
parser.add_argument(
127+
"--sort-by-last-reply",
128+
action="store_true",
129+
help='By default comments are sorted by "parent" comment date, this sort comments based on the last replies',
130+
)
131+
parser.add_argument("--url-prefix", default="", help="Optional domain name to prefix to pages URLs")
132+
parser.add_argument("--no-colors", action="store_false", dest="colors", default=True, help="Disabled colored output")
120133
return parser.parse_args()
121134

122135

123136
class ArgparseHelpFormatter(argparse.RawTextHelpFormatter, argparse.ArgumentDefaultsHelpFormatter):
124137
pass
125138

126139

127-
if __name__ == '__main__':
140+
if __name__ == "__main__":
128141
main()

contrib/import_blogger.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
try:
2929
import feedparser
3030
except ImportError:
31-
print("Error: Package feedparser not installed! You can install it via "
32-
"'pip install feedparser' inside your virtualenv.")
31+
print("Error: Package feedparser not installed! You can install it via 'pip install feedparser' inside your virtualenv.")
3332
import sys
33+
3434
sys.exit(1)
3535

3636
from urllib.parse import urlparse
@@ -43,21 +43,21 @@ def __init__(self, url):
4343
self.comments = []
4444

4545
def add_comment(self, comment):
46-
comment['id'] = len(self.comments) + 1
46+
comment["id"] = len(self.comments) + 1
4747
self.comments.append(comment)
4848

4949

5050
def encode_post(post):
5151
ret = {}
52-
ret['id'] = post.url
53-
ret['title'] = post.title
54-
ret['comments'] = post.comments
52+
ret["id"] = post.url
53+
ret["title"] = post.title
54+
ret["comments"] = post.comments
5555
return ret
5656

5757

5858
class ImportBlogger:
59-
TYPE_COMMENT = 'http://schemas.google.com/blogger/2008/kind#comment'
60-
TYPE_POST = 'http://schemas.google.com/blogger/2008/kind#post'
59+
TYPE_COMMENT = "http://schemas.google.com/blogger/2008/kind#comment"
60+
TYPE_POST = "http://schemas.google.com/blogger/2008/kind#post"
6161

6262
def __init__(self, filename_in, filename_out, prefix):
6363
self.channel = feedparser.parse(filename_in)
@@ -77,7 +77,7 @@ def run(self):
7777
self.process_post(item)
7878

7979
data = [encode_post(p) for p in self.posts.values() if p.comments]
80-
with open(self.filename_out, 'w') as fp:
80+
with open(self.filename_out, "w") as fp:
8181
json.dump(data, fp, indent=2)
8282

8383
def process_post(self, item):
@@ -99,29 +99,27 @@ def ensure_post(self, item):
9999

100100
def process_comment(self, item):
101101
comment = {}
102-
comment['author'] = item.author_detail.name
103-
comment['email'] = item.author_detail.email
104-
comment['website'] = item.author_detail.get('href', '')
105-
t = time.strftime('%Y-%m-%d %H:%M:%S', item.published_parsed)
106-
comment['created'] = t
107-
comment['text'] = item.content[0].value
108-
comment['remote_addr'] = '127.0.0.1'
102+
comment["author"] = item.author_detail.name
103+
comment["email"] = item.author_detail.email
104+
comment["website"] = item.author_detail.get("href", "")
105+
t = time.strftime("%Y-%m-%d %H:%M:%S", item.published_parsed)
106+
comment["created"] = t
107+
comment["text"] = item.content[0].value
108+
comment["remote_addr"] = "127.0.0.1"
109109
return comment
110110

111111
def post_id(self, item):
112112
u = urlparse(item.link)
113113
return self.prefix + u.path
114114

115115

116-
if __name__ == '__main__':
116+
if __name__ == "__main__":
117117
import argparse
118-
parser = argparse.ArgumentParser(
119-
description='Convert comments from blogger.com')
120-
parser.add_argument('input', help='input file')
121-
parser.add_argument('output', help='output file')
122-
parser.add_argument('-p', dest='prefix',
123-
help='prefix to be added to paths (ID)',
124-
type=str, default='')
118+
119+
parser = argparse.ArgumentParser(description="Convert comments from blogger.com")
120+
parser.add_argument("input", help="input file")
121+
parser.add_argument("output", help="output file")
122+
parser.add_argument("-p", dest="prefix", help="prefix to be added to paths (ID)", type=str, default="")
125123
args = parser.parse_args()
126124

127125
importer = ImportBlogger(args.input, args.output, args.prefix)

0 commit comments

Comments
 (0)