Skip to content

Commit 28b4e60

Browse files
authored
IGVF-55-add-linting-and-precommit-hooks (#14)
1 parent a6d7897 commit 28b4e60

Some content is hidden

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

58 files changed

+393
-218
lines changed

.circleci/config.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ version: 2.1
33
workflows:
44
igvf-tests:
55
jobs:
6-
- run-tests
6+
- lint
7+
- run-tests:
8+
requires:
9+
- lint
710

811
jobs:
12+
lint:
13+
docker:
14+
- image: circleci/python:3.9
15+
working_directory: ~/igvfd
16+
steps:
17+
- checkout
18+
- run: pip install pre-commit==2.17.0
19+
- run: pre-commit run --all-files
20+
921
run-tests:
1022
machine:
1123
image: ubuntu-2004:202111-02

.coveragerc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[run]
2-
omit =
3-
*/test*
2+
omit =
3+
*/test*

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.test-reports
2-
.test-results
2+
.test-results

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ dmypy.json
131131
*~
132132
.DS_Store
133133
.test-reports
134-
.test-results
134+
.test-results

.pre-commit-config.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-autopep8
3+
rev: v1.6.0
4+
hooks:
5+
- id: autopep8
6+
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v2.2.3
9+
hooks:
10+
- id: double-quote-string-fixer
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: pretty-format-json
14+
args: ['--autofix', '--no-sort-keys', '--indent=4']
15+
- id: check-yaml

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ $ pytest
4646
4. Stop and clean.
4747
```bash
4848
docker compose down -v
49-
```
49+
```
50+
51+
## Automatic linting
52+
This repo includes configuration for pre-commit hooks. To use pre-commit, install pre-commit, and activate the hooks:
53+
```bash
54+
pip install pre-commit==2.17.0
55+
pre-commit install
56+
```
57+
Now every time you run `git commit` the automatic checks are run to check the changes you made.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM postgres:14.1
1+
FROM postgres:14.1

config/docker_compose/pyramid/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ RUN pip install -e .[test]
3232

3333
COPY . .
3434

35-
ENTRYPOINT ["/docker/entrypoint.sh"]
35+
ENTRYPOINT ["/docker/entrypoint.sh"]

config/nginx/local.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ http {
4141
proxy_pass $1$is_args$args;
4242
}
4343
}
44-
}
44+
}

config/pyramid/ini/docker.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ level = NOTSET
5252
keys = console
5353

5454
[logger_igvfd]
55-
handlers =
55+
handlers =
5656
level = DEBUG
5757
qualname = igvfd
5858

@@ -67,7 +67,7 @@ propagate = 0
6767
qualname = snovault.batchupgrade
6868

6969
[logger_wsgi]
70-
handlers =
70+
handlers =
7171
level = DEBUG
7272
qualname = wsgi
7373

@@ -82,4 +82,4 @@ set pyramid.includes = pyramid_translogger
8282
host = 0.0.0.0
8383
port = 6543
8484
threads = 1
85-
use = egg:waitress#main
85+
use = egg:waitress#main

config/pyramid/ini/local.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ level = NOTSET
5151
keys = console
5252

5353
[logger_igvfd]
54-
handlers =
54+
handlers =
5555
level = DEBUG
5656
qualname = igvfd
5757

@@ -66,7 +66,7 @@ propagate = 0
6666
qualname = snovault.batchupgrade
6767

6868
[logger_wsgi]
69-
handlers =
69+
handlers =
7070
level = DEBUG
7171
qualname = wsgi
7272

@@ -81,4 +81,4 @@ set pyramid.includes = pyramid_translogger
8181
host = 0.0.0.0
8282
port = 6543
8383
threads = 1
84-
use = egg:waitress#main
84+
use = egg:waitress#main

config/pyramid/ini/testing.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ level = NOTSET
5252
keys = console
5353

5454
[logger_igvfd]
55-
handlers =
55+
handlers =
5656
level = DEBUG
5757
qualname = igvfd
5858

@@ -67,7 +67,7 @@ propagate = 0
6767
qualname = snovault.batchupgrade
6868

6969
[logger_wsgi]
70-
handlers =
70+
handlers =
7171
level = DEBUG
7272
qualname = wsgi
7373

@@ -82,4 +82,4 @@ set pyramid.includes = pyramid_translogger
8282
host = 0.0.0.0
8383
port = 6543
8484
threads = 1
85-
use = egg:waitress#main
85+
use = egg:waitress#main

docker-compose.test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ services:
3333
ports:
3434
- "8000:8000"
3535
depends_on:
36-
- pyramid
36+
- pyramid

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ services:
4545
ports:
4646
- "8000:8000"
4747
depends_on:
48-
- pyramid
48+
- pyramid

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
[tool.autopep8]
2+
max_line_length = 120
3+
14
[build-system]
25
requires = [
36
"setuptools>=42",
47
"wheel"
58
]
6-
build-backend = "setuptools.build_meta"
9+
build-backend = "setuptools.build_meta"

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ console_scripts =
7272
paste.app_factory =
7373
main = igvfd:main
7474
paste.filter_app_factory =
75-
memlimit = igvfd.memlimit:filter_app
75+
memlimit = igvfd.memlimit:filter_app

src/igvfd/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__version__ = '0.0.1'
22

33

4-
import igvfd.schema_formats # needed to import before snovault to add FormatCheckers
4+
import igvfd.schema_formats # needed to import before snovault to add FormatCheckers
55
import base64
66
import codecs
77
import copy
@@ -29,7 +29,7 @@
2929

3030

3131
def json_asset(spec, **kw):
32-
utf8 = codecs.getreader("utf-8")
32+
utf8 = codecs.getreader('utf-8')
3333
asset = AssetResolver(caller_package()).resolve(spec)
3434
return json.load(utf8(asset.stream()), **kw)
3535

@@ -66,8 +66,8 @@ def changelogs(config):
6666

6767
def configure_engine(settings):
6868
settings = copy.deepcopy(settings)
69-
engine_url = os.environ.get("SQLALCHEMY_URL") or settings['sqlalchemy.url']
70-
settings["sqlalchemy.url"] = engine_url
69+
engine_url = os.environ.get('SQLALCHEMY_URL') or settings['sqlalchemy.url']
70+
settings['sqlalchemy.url'] = engine_url
7171
engine_opts = {}
7272
if engine_url.startswith('postgresql'):
7373
application_name = 'app'
@@ -95,7 +95,7 @@ def set_postgresql_statement_timeout(engine, timeout=20 * 1000):
9595
def connect(dbapi_connection, connection_record):
9696
cursor = dbapi_connection.cursor()
9797
try:
98-
cursor.execute("SET statement_timeout TO %d" % timeout)
98+
cursor.execute('SET statement_timeout TO %d' % timeout)
9999
except psycopg2.Error:
100100
dbapi_connection.rollback()
101101
finally:

src/igvfd/auth0.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def includeme(config):
4646
class LoginDenied(HTTPForbidden):
4747
title = 'Login failure'
4848

49+
4950
class Auth0AuthenticationPolicy(CallbackAuthenticationPolicy):
5051
"""
5152
Checks assertion during authentication so login can construct user session.
@@ -72,10 +73,10 @@ def unauthenticated_userid(self, request):
7273
request)
7374
request._auth0_authenticated = None
7475
return None
75-
76+
7677
try:
7778
domain = 'encode.auth0.com'
78-
user_url = "https://{domain}/userinfo?access_token={access_token}" \
79+
user_url = 'https://{domain}/userinfo?access_token={access_token}' \
7980
.format(domain=domain, access_token=access_token)
8081
user_info = requests.get(user_url).json()
8182
except Exception as e:
@@ -93,7 +94,6 @@ def unauthenticated_userid(self, request):
9394
else:
9495
return None
9596

96-
9797
def remember(self, request, principal, **kw):
9898
return []
9999

src/igvfd/authentication.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def basic_auth_check(username, password, request):
9797
return None
9898

9999
#valid, new_hash = crypt_context.verify_and_update(password, hash)
100-
#if new_hash:
100+
# if new_hash:
101101
# replace_user_hash(user, new_hash)
102102

103103
return []

src/igvfd/commands/run_local.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def nginx_server_process(prefix='', echo=False):
5656

5757

5858
def main():
59-
set_start_method("fork")
59+
set_start_method('fork')
6060
import argparse
6161
parser = argparse.ArgumentParser(
62-
description="Run development servers", epilog=EPILOG,
62+
description='Run development servers', epilog=EPILOG,
6363
formatter_class=argparse.RawDescriptionHelpFormatter,
6464
)
6565
parser.add_argument(
@@ -72,10 +72,10 @@ def main():
7272
default=f'{Path().absolute()}/config/pyramid/ini/local.ini',
7373
help='path to configfile',
7474
)
75-
parser.add_argument('--clear', action="store_true", help="Clear existing data")
76-
parser.add_argument('--init', action="store_true", help="Init database")
77-
parser.add_argument('--load', action="store_true", help="Load test set")
78-
parser.add_argument('--datadir', default='/tmp/igvfd', help="path to datadir")
75+
parser.add_argument('--clear', action='store_true', help='Clear existing data')
76+
parser.add_argument('--init', action='store_true', help='Init database')
77+
parser.add_argument('--load', action='store_true', help='Load test set')
78+
parser.add_argument('--datadir', default='/tmp/igvfd', help='path to datadir')
7979
args = parser.parse_args()
8080

8181
logging.basicConfig()
@@ -132,5 +132,6 @@ def cleanup_process():
132132
for p in print_processes:
133133
p.start()
134134

135+
135136
if __name__ == '__main__':
136137
main()

src/igvfd/edw_hash.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class EDWHash(uh.StaticHandler):
2121
checksum_size = 64
2222

2323
setting_kwds = ('salt_before', 'salt_after', 'salt_base')
24-
salt_before = b"186ED79BAEXzeusdioIsdklnw88e86cd73"
25-
salt_after = b"<*#$*(#)!DSDFOUIHLjksdf"
24+
salt_before = b'186ED79BAEXzeusdioIsdklnw88e86cd73'
25+
salt_after = b'<*#$*(#)!DSDFOUIHLjksdf'
2626
salt_base = b64decode(b"""\
2727
Kf8r/S37L/kh9yP1JfMn8TnvO+096z/pMecz5TXjN+EJ3wvdDdsP2QHXA9UF0wfRGc8bzR3LH8kR
2828
xxPFFcMXwWm/a71tu2+5YbdjtWWzZ7F5r3utfat/qXGnc6V1o3ehSZ9LnU2bT5lBl0OVRZNHkVmP
@@ -40,7 +40,7 @@ def _calc_checksum(self, secret):
4040
secret = secret.encode('utf-8')
4141
salted = self.salt_before + secret + self.salt_after + b'\0'
4242
if len(salted) > len(self.salt_base):
43-
raise ValueError("Password too long")
43+
raise ValueError('Password too long')
4444
salted += self.salt_base[len(salted):]
4545
chk = sha384(salted).digest()
46-
return b64encode(chk).decode("ascii")
46+
return b64encode(chk).decode('ascii')

src/igvfd/loadxl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ def attachment(path):
421421
im = Image.open(stream)
422422
im.verify()
423423
if im.format != minor.upper():
424-
msg = "Image file format %r does not match extension for %s"
424+
msg = 'Image file format %r does not match extension for %s'
425425
raise ValueError(msg % (im.format, filename))
426426

427427
attach['width'], attach['height'] = im.size
428428
return attach
429429

430-
raise ValueError("Unknown file type for %s" % filename)
430+
raise ValueError('Unknown file type for %s' % filename)
431431

432432

433433
##############################################################################

src/igvfd/memlimit.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# https://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode
22

33

4+
import humanfriendly
5+
import psutil
6+
import logging
7+
8+
49
class Generator2:
510
def __init__(self, iterable, callback, environ):
611
self.__iterable = iterable
@@ -33,19 +38,14 @@ def __call__(self, environ, start_response):
3338
return Generator2(result, self.__callback, environ)
3439

3540

36-
import logging
37-
import psutil
38-
import humanfriendly
39-
40-
4141
def rss_checker(rss_limit=None):
4242
log = logging.getLogger(__name__)
4343
process = psutil.Process()
4444

4545
def callback(environ):
4646
rss = process.memory_info().rss
4747
if rss_limit and rss > rss_limit:
48-
msg = "Restarting process. Memory usage exceeds limit of %d: %d"
48+
msg = 'Restarting process. Memory usage exceeds limit of %d: %d'
4949
log.error(msg, rss_limit, rss)
5050
process.terminate()
5151

0 commit comments

Comments
 (0)