Skip to content

Commit 084d6bf

Browse files
authored
Merge pull request #24 from Linusp/pre-commit
setup pre-commit
2 parents 31b35c5 + 0c294c4 commit 084d6bf

File tree

11 files changed

+106
-75
lines changed

11 files changed

+106
-75
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Python package
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
- uses: pre-commit/[email protected]

.github/workflows/pythonpackage.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ ENV/
6262

6363
# Spyder project settings
6464
.spyderproject
65-
.idea/*
65+
.idea/*

.pre-commit-config.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
fail_fast: true
2+
repos:
3+
- repo: meta
4+
hooks:
5+
- id: check-hooks-apply
6+
- id: check-useless-excludes
7+
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.1.0
10+
hooks:
11+
- id: check-merge-conflict
12+
- id: check-yaml
13+
- id: end-of-file-fixer
14+
exclude: |
15+
(?x)(
16+
.md$|
17+
^.gitignore|
18+
^.ipython/|
19+
^.pytest_cache/
20+
)
21+
- id: trailing-whitespace
22+
exclude: |
23+
(?x)(
24+
.md$|
25+
^.ipython/|
26+
^.pytest_cache/
27+
)
28+
29+
- repo: https://github.com/PyCQA/isort
30+
rev: 5.12.0
31+
hooks:
32+
- id: isort
33+
34+
- repo: https://github.com/psf/black
35+
rev: 22.6.0
36+
hooks:
37+
- id: black
38+
39+
- repo: https://github.com/PyCQA/flake8
40+
rev: 6.1.0
41+
hooks:
42+
- id: flake8
43+
additional_dependencies:
44+
- setuptools
45+
- flake8-bugbear
46+
- flake8-comprehensions
47+
- flake8-debugger
48+
- flake8-logging-format
49+
- flake8-pytest-style
50+
- flake8-tidy-imports
51+
52+
- repo: https://github.com/codespell-project/codespell
53+
rev: v2.1.0
54+
hooks:
55+
- id: codespell
56+
name: codespell
57+
entry: codespell -q 3 -S "*.lock" -I codespell-ignore-words.txt --regex="[a-zA-Z0-9\-'’`]+"
58+
types: [text]

codespell-ignore-words.txt

Whitespace-only changes.

inoreader/client.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525

2626
class InoreaderClient(object):
27-
2827
# paths
2928
TOKEN_PATH = '/oauth2/token'
3029
USER_INFO_PATH = 'user-info'
@@ -190,13 +189,11 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, lim
190189
fetched_count = 0
191190
response = self.parse_response(self.session.post(url, params=params, proxies=self.proxies))
192191
for data in response['items']:
193-
categories = set(
194-
[
195-
category.split('/')[-1]
196-
for category in data.get('categories', [])
197-
if category.find('label') > 0
198-
]
199-
)
192+
categories = {
193+
category.split('/')[-1]
194+
for category in data.get('categories', [])
195+
if category.find('label') > 0
196+
}
200197
if tags and not categories.issuperset(set(tags)):
201198
continue
202199

@@ -212,13 +209,11 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, lim
212209
self.session.post(url, params=params, proxies=self.proxies)
213210
)
214211
for data in response['items']:
215-
categories = set(
216-
[
217-
category.split('/')[-1]
218-
for category in data.get('categories', [])
219-
if category.find('label') > 0
220-
]
221-
)
212+
categories = {
213+
category.split('/')[-1]
214+
for category in data.get('categories', [])
215+
if category.find('label') > 0
216+
}
222217
if tags and not categories.issuperset(set(tags)):
223218
continue
224219
yield Article.from_json(data)
@@ -305,6 +300,6 @@ def edit_subscription(self, stream_id, action, title=None, add_folder=None, remo
305300
response = self.parse_response(
306301
r,
307302
# self.session.post(url, params=params, proxies=self.proxies),
308-
json_data=False
303+
json_data=False,
309304
)
310305
return response

inoreader/main.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def wrapper(*args, **kwargs):
9595
return wrapper
9696

9797

98-
@click.group(context_settings=dict(help_option_names=['-h', '--help']))
98+
@click.group(context_settings={'help_option_names': ['-h', '--help']})
9999
def main():
100100
pass
101101

@@ -199,7 +199,7 @@ def list_tags():
199199

200200
@main.command("fetch-unread")
201201
@click.option("-f", "--folder", required=True, help='Folder which articles belong to')
202-
@click.option("-t", "--tags", help="Tag(s) for filtering, seprate with comma")
202+
@click.option("-t", "--tags", help="Tag(s) for filtering, separate with comma")
203203
@click.option("-o", "--outfile", required=True, help="Filename to save articles")
204204
@click.option(
205205
"--out-format",
@@ -270,7 +270,7 @@ def apply_action(articles, client, action, tags):
270270
elif action == 'broadcast':
271271
client.broadcast(articles)
272272
for article in articles:
273-
LOGGER.info("Boradcast article: %s", article.title)
273+
LOGGER.info("Broadcast article: %s", article.title)
274274
elif action == 'star':
275275
client.mark_as_starred(articles)
276276
for article in articles:
@@ -362,7 +362,7 @@ def get_subscriptions(outfile, folder, out_format):
362362
client = get_client()
363363
results = []
364364
for sub in client.get_subscription_list():
365-
sub_categories = set([category['label'] for category in sub.categories])
365+
sub_categories = {category['label'] for category in sub.categories}
366366
if folder and folder not in sub_categories:
367367
continue
368368

@@ -452,9 +452,7 @@ def dedupe(folder, thresh):
452452
for docid, doc, _ in related:
453453
if docid == article.id:
454454
continue
455-
sims[doc] = sim_of(
456-
doc, article.title, method='cosine', term='char', ngram_range=(2, 3)
457-
)
455+
sims[doc] = sim_of(doc, article.title, method='cosine', term='char', ngram_range=(2, 3))
458456

459457
if sims and max(sims.values()) >= thresh:
460458
top_doc, top_score = sims.most_common()[0]
@@ -470,7 +468,7 @@ def dedupe(folder, thresh):
470468

471469
@main.command("fetch-starred")
472470
@click.option("-f", "--folder", help='Folder which articles belong to')
473-
@click.option("-t", "--tags", help="Tag(s) for filtering, seprate with comma")
471+
@click.option("-t", "--tags", help="Tag(s) for filtering, separate with comma")
474472
@click.option(
475473
"-o", "--outfile", help="Filename to save articles, required when output format is `csv`"
476474
)
@@ -587,10 +585,13 @@ def fetch_starred(folder, tags, outfile, outdir, limit, save_image, out_format):
587585

588586

589587
@main.command("edit-subscription")
590-
@click.option("-a", "--action",
591-
required=True,
592-
type=click.Choice(['follow', 'unfollow', 'rename', 'add-folder', 'remove-folder']),
593-
help="")
588+
@click.option(
589+
"-a",
590+
"--action",
591+
required=True,
592+
type=click.Choice(['follow', 'unfollow', 'rename', 'add-folder', 'remove-folder']),
593+
help="",
594+
)
594595
@click.option("-i", "--stream-id", required=True, help='Stream ID which you want to fetch')
595596
@click.option("-n", "--name", help='The name of subscription, for action follow/rename(required)')
596597
@click.option("-f", "--folder", help='Folder which subscription belong to')
@@ -616,11 +617,7 @@ def edit_subscriptions(action, stream_id, name, folder):
616617
remove_folder = folder if action == 'remove-folder' else None
617618
try:
618619
response = client.edit_subscription(
619-
stream_id,
620-
edit_action,
621-
title=name,
622-
add_folder=add_folder,
623-
remove_folder=remove_folder
620+
stream_id, edit_action, title=name, add_folder=add_folder, remove_folder=remove_folder
624621
)
625622
click.secho(response, fg="green")
626623
except Exception as exception:

inoreader/sim.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def make_terms(text, term, ngram_range=None, lower=True, ignore_punct=True, gram
2222
elif term == 'char':
2323
term_seq = list(re.sub(r'\s', '', text))
2424
else:
25-
raise ValueError("unsupported term type: {}".foramt(term))
25+
raise ValueError(f"unsupported term type: {term}")
2626

2727
if ngram_range and not (len(ngram_range) == 2 and ngram_range[0] < ngram_range[1]):
28-
raise ValueError("wrong `ngram_range`: {}".foramt(ngram_range))
28+
raise ValueError(f"wrong `ngram_range`: {ngram_range}")
2929

3030
terms = []
3131
min_ngram, max_ngram = ngram_range or (1, 2)
@@ -96,7 +96,7 @@ def cosine_sim(
9696
first_norm += freq**2
9797
inner_product += freq * second_term_freq[term]
9898

99-
for term, freq in second_term_freq.items():
99+
for _, freq in second_term_freq.items():
100100
second_norm += freq**2
101101

102102
if first_norm == 0 and second_norm == 0:

inoreader/subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def from_json(cls, data):
1818
subscription_info = {
1919
'id': data['id'],
2020
'title': data['title'],
21-
'categories': [item for item in data['categories']],
21+
'categories': list(data['categories']),
2222
'sortid': data['sortid'],
2323
'firstitemmsec': data['firstitemmsec'],
2424
'url': data['url'],

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.black]
2-
line-length = 99
2+
line-length = 100
33
skip-string-normalization = true
44
extend-exclude = '''
55
/(
@@ -22,6 +22,6 @@ include_trailing_comma = true
2222
force_grid_wrap = 0
2323
use_parentheses = true
2424
ensure_newline_before_comments = true
25-
line_length = 99
25+
line_length = 100
2626
skip = [".ipython"]
2727
remove_redundant_aliases = true

0 commit comments

Comments
 (0)