Skip to content

Commit 686645c

Browse files
author
Joshua Li
committed
lots of pre-commit
1 parent c00bd97 commit 686645c

9 files changed

+53
-28
lines changed

.pre-commit-config.yaml

+23-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@ repos:
22
- repo: local
33
hooks:
44
- id: flake8
5-
name: flake8
65
entry: flake8
6+
name: flake8
77
language: python
8-
types: [python]
8+
types: [file, python]
99
- id: black
10+
entry: black -v
1011
name: black
11-
entry: black
1212
language: python
13-
types: [python]
13+
types: [file, python]
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v1.4.0
16+
hooks:
17+
- id: trailing-whitespace
18+
- id: end-of-file-fixer
19+
- id: fix-encoding-pragma
20+
- id: check-docstring-first
21+
- id: check-merge-conflict
22+
- id: check-yaml
23+
- id: debug-statements
24+
- id: name-tests-test
25+
- id: check-added-large-files
26+
- id: check-byte-order-marker
27+
- id: mixed-line-ending
28+
- id: requirements-txt-fixer
29+
- repo: https://github.com/asottile/reorder_python_imports
30+
rev: v1.2.0
31+
hooks:
32+
- id: reorder-python-imports

pylibgen/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
from .pylibgen import Library, Book, constants
1+
# -*- coding: utf-8 -*-
2+
from .pylibgen import Book
3+
from .pylibgen import constants
4+
from .pylibgen import Library

pylibgen/constants.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
from collections import namedtuple
23

34
__Mirror = namedtuple("Mirror", ("name", "search", "lookup"))
@@ -15,7 +16,7 @@
1516
"&open={open}"
1617
"&phrase={phrase}",
1718
"http://libgen.io/json.php" "?ids={ids}" "&fields={fields}",
18-
)
19+
),
1920
# TODO gen.lib.rus.ec support
2021
}
2122

@@ -33,19 +34,11 @@
3334
"phrase": 0,
3435
}
3536

37+
# modes year, publisher, series, language, extension, tags are possible,
38+
# but way too general and not recommended.
39+
# AFAIK, there isn't a way to combine multiple search modes and respective
40+
# strings to filter down the search.
3641
SEARCH_MODES = ("title", "author", "isbn")
37-
"""
38-
The following modes are possible, but way too general and not recommended.
39-
AFAIK, there isn't a way to combine multiple search modes and respective
40-
strings to filter down the search.
41-
42-
'year',
43-
'publisher',
44-
'series',
45-
'language',
46-
'extension',
47-
'tags',
48-
"""
4942

5043
# strangely, libgen only allows these amounts.
5144
SEARCH_RESULTS_PER_PAGE = (25, 50, 100)

pylibgen/exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
class LibraryException(Exception):
23
pass
34

pylibgen/pylibgen.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# -*- coding: utf-8 -*-
12
import re
23
from urllib.parse import quote_plus
34

45
import requests
56

6-
from . import constants, exceptions
7+
from . import constants
8+
from . import exceptions
79

810

911
class Library(object):

setup.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# -*- coding: utf-8 -*-
12
import os
2-
from setuptools import setup, find_packages
3+
4+
from setuptools import find_packages
5+
from setuptools import setup
36

47
version = "2.0.0b2"
58
url = "https://github.com/JoshuaRLi/pylibgen"

tests/test_book.py tests/book_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
13
import requests
4+
25
import pylibgen
3-
import pytest
46

57

68
def check_url(url):

tests/test_library.py tests/library_test.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import pylibgen
1+
# -*- coding: utf-8 -*-
22
import pytest
33

4+
import pylibgen
5+
46
test_books = {
57
# Automate the Boring Stuff with Python: Practical Programming for Total Beginners
68
("automate the boring stuff", "title"): {
@@ -31,13 +33,13 @@
3133
@pytest.mark.parametrize("test_book", list(test_books.items()))
3234
def test_mirror(mirror, test_book):
3335
search_params, md5_of_ids = test_book
34-
l = pylibgen.Library(mirror)
35-
ids = l.search(*search_params)
36+
library = pylibgen.Library(mirror)
37+
ids = library.search(*search_params)
3638

3739
assert isinstance(ids, list)
3840
assert set(ids) == set(md5_of_ids.keys())
3941

40-
books = l.lookup(ids)
42+
books = library.lookup(ids)
4143
assert isinstance(books, list)
4244
assert all((isinstance(b, pylibgen.Book) for b in books))
4345
for book in books:
@@ -46,6 +48,6 @@ def test_mirror(mirror, test_book):
4648

4749
@pytest.mark.parametrize("mirror", pylibgen.constants.MIRRORS)
4850
def test_all_book_fields(mirror):
49-
l = pylibgen.Library(mirror)
50-
book = l.lookup("112887", fields=["*"])
51+
library = pylibgen.Library(mirror)
52+
book = library.lookup("112887", fields=["*"])
5153
assert set(book.__dict__.keys()) == pylibgen.constants.ALL_BOOK_FIELDS

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ commands =
1212

1313
[flake8]
1414
max-line-length = 90
15-
exclude = tests/test_*.py,__init__.py,setup.py
15+
exclude = __init__.py,setup.py

0 commit comments

Comments
 (0)