1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 14:10:00 +00:00

Fix lint check + update lint script (#224)

* Fix PEP8 E301 on nyaa/models.py

* Add utils/ to lint checker

* Run of lint.sh + manual fixes

As suggested https://github.com/nyaadevs/nyaa/pull/157#issuecomment-305051428

* Fix backwards tick in README

* Updated script

* Update Travis config
This commit is contained in:
Kfir Hadas 2017-06-01 14:40:33 +03:00 committed by Alex Ingram
parent 3e2437bba1
commit 3165389d52
6 changed files with 115 additions and 52 deletions

View file

@ -1,18 +1,18 @@
language: python language: python
python: python: "3.6"
- 3.6
dist: xenial dist: xenial
sudo: false sudo: false
matrix:
fast_finish: true
cache: pip cache: pip
install: install: pip install --upgrade pycodestyle
- pip install --upgrade pycodestyle
script: script: ./lint.sh --check
- pycodestyle nyaa/ --show-source --max-line-length=100
notifications: notifications:
email: false email: false

View file

@ -7,7 +7,7 @@ It's not impossible to run Nyaa on Windows, but this guide doesn't focus on that
### Code Quality: ### Code Quality:
- Before we get any deeper, remember to follow PEP8 style guidelines and run `./lint.sh` before committing. - Before we get any deeper, remember to follow PEP8 style guidelines and run `./lint.sh` before committing.
- You may also use `pycodestyle nyaa/ --show-source --max-line-length=100´ to see a list of warnings/problems instead of having `lint.sh` making modifications for you - You may also use `./lint.sh -c` to see a list of warnings/problems instead of having `lint.sh` making modifications for you
- Other than PEP8, try to keep your code clean and easy to understand, as well. It's only polite! - Other than PEP8, try to keep your code clean and easy to understand, as well. It's only polite!
### Setting up Pyenv ### Setting up Pyenv

49
lint.sh
View file

@ -1,6 +1,51 @@
autopep8 nyaa/ \ # Lint checker/fixer
check_paths="nyaa/ utils/"
max_line_length=100
function auto_pep8() {
autopep8 ${check_paths} \
--recursive \ --recursive \
--in-place \ --in-place \
--pep8-passes 2000 \ --pep8-passes 2000 \
--max-line-length 100 \ --max-line-length ${max_line_length} \
--verbose --verbose
}
function check_lint() {
pycodestyle ${check_paths} \
--show-source \
--max-line-length=${max_line_length} \
--format '%(path)s [%(row)s:%(col)s] %(code)s: %(text)s'
}
# MAIN
action=auto_pep8 # default action
for arg in "$@"
do
case "$arg" in
"-h" | "--help")
echo "Lint checker/fixer"
echo ""
echo "Usage: $0 [-c|--check] [-h|--help]"
echo " No arguments : Check and auto-fix some warnings/errors"
echo " -c | --check : only check lint (don't auto-fix)"
echo " -h | --help : show this help and exit"
exit 0;
;;
"-c" | "--check")
action=check_lint
;;
esac
done
${action} # run selected action
result=$?
if [[ ${action} == check_lint ]]; then
if [[ ${result} == 0 ]]; then
echo "Looks good!"
else
echo "The code requires some changes."
fi
fi

View file

@ -67,12 +67,14 @@ class DeclarativeHelperBase(object):
class FlagProperty(object): class FlagProperty(object):
''' This class will act as a wrapper between the given flag and the class's ''' This class will act as a wrapper between the given flag and the class's
flag collection. ''' flag collection. '''
def __init__(self, flag, flags_attr='flags'): def __init__(self, flag, flags_attr='flags'):
self._flag = flag self._flag = flag
self._flags_attr_name = flags_attr self._flags_attr_name = flags_attr
def _get_flags(self, instance): def _get_flags(self, instance):
return getattr(instance, self._flags_attr_name) return getattr(instance, self._flags_attr_name)
def _set_flags(self, instance, value): def _set_flags(self, instance, value):
return setattr(instance, self._flags_attr_name, value) return setattr(instance, self._flags_attr_name, value)

View file

@ -186,6 +186,7 @@ def search_elastic(term='', user=None, sort='id', order='desc',
class QueryPairCaller(object): class QueryPairCaller(object):
''' Simple stupid class to filter one or more queries with the same args ''' ''' Simple stupid class to filter one or more queries with the same args '''
def __init__(self, *items): def __init__(self, *items):
self.items = list(items) self.items = list(items)

View file

@ -38,6 +38,7 @@ SUKEBEI_CATS = '''1_1 - Art - Anime
2_1 - Real Life - Photobooks / Pictures 2_1 - Real Life - Photobooks / Pictures
2_2 - Real Life - Videos''' 2_2 - Real Life - Videos'''
class CategoryPrintAction(argparse.Action): class CategoryPrintAction(argparse.Action):
def __init__(self, option_strings, nargs='?', help=None, **kwargs): def __init__(self, option_strings, nargs='?', help=None, **kwargs):
super().__init__(option_strings=option_strings, super().__init__(option_strings=option_strings,
@ -55,15 +56,20 @@ class CategoryPrintAction(argparse.Action):
print(NYAA_CATS) print(NYAA_CATS)
parser.exit() parser.exit()
environment_epillog = '''You may also provide environment variables NYAA_API_HOST, NYAA_API_USERNAME and NYAA_API_PASSWORD for connection info.'''
parser = argparse.ArgumentParser(description='Upload torrents to Nyaa.si', epilog=environment_epillog) environment_epillog = ('You may also provide environment variables NYAA_API_HOST, NYAA_API_USERNAME'
' and NYAA_API_PASSWORD for connection info.')
parser.add_argument('--list-categories', default=False, action=CategoryPrintAction, nargs='?', help='List torrent categories. Include "sukebei" to show Sukebei categories') parser = argparse.ArgumentParser(
description='Upload torrents to Nyaa.si', epilog=environment_epillog)
parser.add_argument('--list-categories', default=False, action=CategoryPrintAction, nargs='?',
help='List torrent categories. Include "sukebei" to show Sukebei categories')
conn_group = parser.add_argument_group('Connection options') conn_group = parser.add_argument_group('Connection options')
conn_group.add_argument('-s', '--sukebei', default=False, action='store_true', help='Upload to sukebei.nyaa.si') conn_group.add_argument('-s', '--sukebei', default=False,
action='store_true', help='Upload to sukebei.nyaa.si')
conn_group.add_argument('-u', '--user', help='Username or email') conn_group.add_argument('-u', '--user', help='Username or email')
conn_group.add_argument('-p', '--password', help='Password') conn_group.add_argument('-p', '--password', help='Password')
@ -71,8 +77,10 @@ conn_group.add_argument('--host', help='Select another api host (for debugging p
resp_group = parser.add_argument_group('Response options') resp_group = parser.add_argument_group('Response options')
resp_group.add_argument('--raw', default=False, action='store_true', help='Print only raw response (JSON)') resp_group.add_argument('--raw', default=False, action='store_true',
resp_group.add_argument('-m', '--magnet', default=False, action='store_true', help='Print magnet uri') help='Print only raw response (JSON)')
resp_group.add_argument('-m', '--magnet', default=False,
action='store_true', help='Print magnet uri')
tor_group = parser.add_argument_group('Torrent options') tor_group = parser.add_argument_group('Torrent options')
@ -80,16 +88,23 @@ tor_group.add_argument('-c', '--category', required=True, help='Torrent category
tor_group.add_argument('-n', '--name', help='Display name for the torrent (optional)') tor_group.add_argument('-n', '--name', help='Display name for the torrent (optional)')
tor_group.add_argument('-i', '--information', help='Information field (optional)') tor_group.add_argument('-i', '--information', help='Information field (optional)')
tor_group.add_argument('-d', '--description', help='Description for the torrent (optional)') tor_group.add_argument('-d', '--description', help='Description for the torrent (optional)')
tor_group.add_argument('-D', '--description-file', metavar='FILE', help='Read description from a file (optional)') tor_group.add_argument('-D', '--description-file', metavar='FILE',
help='Read description from a file (optional)')
tor_group.add_argument('-A', '--anonymous', default=False, action='store_true', help='Upload torrent anonymously') tor_group.add_argument('-A', '--anonymous', default=False,
tor_group.add_argument('-H', '--hidden', default=False, action='store_true', help='Hide torrent from results') action='store_true', help='Upload torrent anonymously')
tor_group.add_argument('-C', '--complete', default=False, action='store_true', help='Mark torrent as complete (eg. season batch)') tor_group.add_argument('-H', '--hidden', default=False, action='store_true',
tor_group.add_argument('-R', '--remake', default=False, action='store_true', help='Mark torrent as remake (derivative work from another release)') help='Hide torrent from results')
tor_group.add_argument('-C', '--complete', default=False, action='store_true',
help='Mark torrent as complete (eg. season batch)')
tor_group.add_argument('-R', '--remake', default=False, action='store_true',
help='Mark torrent as remake (derivative work from another release)')
trusted_group = tor_group.add_mutually_exclusive_group(required=False) trusted_group = tor_group.add_mutually_exclusive_group(required=False)
trusted_group.add_argument('-T', '--trusted', dest='trusted', action='store_true', help='Mark torrent as trusted, if possible. Defaults to true') trusted_group.add_argument('-T', '--trusted', dest='trusted', action='store_true',
trusted_group.add_argument('--no-trusted', dest='trusted', action='store_false', help='Do not mark torrent as trusted') help='Mark torrent as trusted, if possible. Defaults to true')
trusted_group.add_argument('--no-trusted', dest='trusted',
action='store_false', help='Do not mark torrent as trusted')
parser.set_defaults(trusted=True) parser.set_defaults(trusted=True)
tor_group.add_argument('torrent', metavar='TORRENT_FILE', help='The .torrent file to upload') tor_group.add_argument('torrent', metavar='TORRENT_FILE', help='The .torrent file to upload')