Skip to content

Commit

Permalink
Fix or silence all PyLint warnings (as appropriate)
Browse files Browse the repository at this point in the history
Add secondary pylintrc which warns about a few extra things - intended to show potential candidates for refactoring
  • Loading branch information
Pidgeot committed Dec 1, 2015
1 parent e46d6e4 commit 2c29d90
Show file tree
Hide file tree
Showing 23 changed files with 464 additions and 100 deletions.
4 changes: 2 additions & 2 deletions core/baselines.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def simplify_pack(pack, folder):
None if folder is empty
"""
valid_dirs = ('graphics', 'mods', 'baselines')
if not folder in valid_dirs:
if folder not in valid_dirs:
return False
log.i('Simplifying {}: {}'.format(folder, pack))
files_before = sum(len(f) for (_, _, f) in os.walk(paths.get(folder, pack)))
Expand All @@ -103,7 +103,7 @@ def simplify_pack(pack, folder):
f = os.path.join(root, k)
if not any(fnmatch.fnmatch(f, os.path.join(d, p)) for p in keep):
os.remove(f)
if not folder == 'mods':
if folder != 'mods':
init_files = ('colors', 'd_init', 'init', 'overrides')
init_dir = paths.get(folder, pack, 'data', 'init')
for f in os.listdir(init_dir):
Expand Down
9 changes: 5 additions & 4 deletions core/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def get_archive_name(self):
return base + '_s.zip'
return base + '.zip'

# pylint:disable=too-few-public-methods
@total_ordering
class Version(object):
"""Container for a version number for easy comparisons."""
Expand All @@ -254,16 +255,16 @@ def __init__(self, version):
self.data = tuple(data)

def __lt__(self, other):
if type(self) != Version:
if not isinstance(self, Version):
return Version(self) < other
if type(other) != Version:
if not isinstance(other, Version):
return self < Version(other)
return self.data < other.data

def __eq__(self, other):
if type(self) != Version:
if not isinstance(self, Version):
return Version(self) == other
if type(other) != Version:
if not isinstance(other, Version):
return self == Version(other)
return self.data == other.data

Expand Down
7 changes: 4 additions & 3 deletions core/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import os, shutil, tempfile
from threading import Thread, Lock
from .lnp import VERSION

from . import log

try: # Python 2
# pylint:disable=import-error
Expand All @@ -17,6 +14,9 @@
from urllib.request import urlopen, Request
from urllib.error import URLError

from .lnp import VERSION
from . import log

__download_queues = {}

def download_str(url, **kwargs):
Expand Down Expand Up @@ -57,6 +57,7 @@ def get_queue(queue):
__download_queues.setdefault(queue, DownloadQueue(queue))
return __download_queues[queue]

# pylint:disable=too-many-instance-attributes
class DownloadQueue(object):
"""Queue used for downloading files."""
def __init__(self, name):
Expand Down
2 changes: 1 addition & 1 deletion core/hacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read_hacks():
hacklines = []
for init_file in ('dfhack', 'onLoad', 'onMapLoad'):
try:
with open(paths.get('df', init_file + '_PyLNP.init'),
with open(paths.get('df', init_file + '_PyLNP.init'),
encoding='latin1') as f:
hacklines.extend(l.strip() for l in f.readlines())
except IOError:
Expand Down
9 changes: 6 additions & 3 deletions core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def run_program(path, force=False, is_df=False, spawn_terminal=False):

try:
workdir = os.path.dirname(path)
# pylint:disable=redefined-variable-type
run_args = path
if spawn_terminal and not sys.platform.startswith('win'):
term = get_terminal_launcher()
Expand All @@ -119,13 +120,15 @@ def run_program(path, force=False, is_df=False, spawn_terminal=False):
environ = os.environ
if lnp.bundle:
environ = copy.deepcopy(os.environ)
if 'TCL_LIBRARY' in environ and sys._MEIPASS in environ['TCL_LIBRARY']:
if ('TCL_LIBRARY' in environ and
sys._MEIPASS in environ['TCL_LIBRARY']): # pylint:disable=no-member
del environ['TCL_LIBRARY']
if 'TK_LIBRARY' in environ and sys._MEIPASS in environ['TK_LIBRARY']:
if ('TK_LIBRARY' in environ and
sys._MEIPASS in environ['TK_LIBRARY']): # pylint:disable=no-member
del environ['TK_LIBRARY']

lnp.running[path] = subprocess.Popen(
run_args, cwd=workdir, environ=environ)
run_args, cwd=workdir, env=environ)
return True
except OSError:
sys.excepthook(*sys.exc_info())
Expand Down
3 changes: 3 additions & 0 deletions core/lnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

VERSION = '0.10b'

# pylint:disable=too-many-instance-attributes

lnp = None
class PyLNP(object):
"""
Expand Down Expand Up @@ -183,6 +185,7 @@ def detect_basedir(self):
df.find_df_folders()
if len(self.folders) != 0:
return
# pylint:disable=redefined-variable-type
prev_path = os.path.abspath(self.BASEDIR)
self.BASEDIR = os.path.join(self.BASEDIR, '..')
except UnicodeDecodeError:
Expand Down
6 changes: 3 additions & 3 deletions core/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ def merge_folder(mod_folder, vanilla_folder, mixed_folder):
status = max(1, status)
else:
with open(mod_f, 'rb') as f:
mb = f.read()
mb = f.read() # pylint:disable=no-member
with open(gen_f, 'rb') as f:
gb = f.read()
if not mb == gb:
gb = f.read() # pylint:disable=no-member
if mb != gb:
shutil.copyfile(mod_f, gen_f)
status = max(2, status)
log.d('merged with status {}'.format(status))
Expand Down
1 change: 1 addition & 0 deletions core/rawlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
def check_file(path):
"""Validates the raw file located at <path>. Error details are printed to
the log with level WARNING. Returns True/False."""
# pylint:disable=too-many-branches
file_ok = True
if not path.endswith('.txt'):
log.w('Unrecognized filename')
Expand Down
2 changes: 1 addition & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .dfraw import DFRaw

# Markers to read certain settings correctly

# pylint:disable=too-few-public-methods,too-many-instance-attributes,too-many-statements,too-many-arguments
class _DisableValues(object):
"""Marker class for DFConfiguration. Value is disabled by replacing [ and ]
with !."""
Expand Down
10 changes: 5 additions & 5 deletions core/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

import re, time, os, threading, zipfile, tarfile

from .lnp import lnp
from . import launcher, paths, download, log
from .json_config import JSONConfiguration

try: # Python 2
# pylint:disable=import-error, no-name-in-module
from urllib import quote, unquote
Expand All @@ -17,6 +13,10 @@
# pylint:disable=import-error, no-name-in-module
from urllib.parse import quote, unquote, urlparse

from .lnp import lnp
from . import launcher, paths, download, log
from .json_config import JSONConfiguration

def updates_configured():
"""Returns True if update checking have been configured."""
return prepare_updater() is not None
Expand Down Expand Up @@ -143,7 +143,7 @@ def update_needed(self):
if not curr_version:
log.e("Current pack version is not set, cannot check for updates")
return False
return (self.get_version() != curr_version)
return self.get_version() != curr_version

def get_check_url(self):
"""Returns the URL used to check for updates."""
Expand Down
6 changes: 3 additions & 3 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
init-hook='import sys, os; sys.path.append(os.path.abspath("."))'

# Add files or directories to the blacklist. They should be base names, not
# paths.
Expand Down Expand Up @@ -41,7 +41,7 @@ load-plugins=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=star-args,invalid-name,protected-access,maybe-no-member,locally-disabled,too-many-ancestors,duplicate-code
disable=invalid-name,protected-access,locally-disabled,locally-enabled,too-many-ancestors,duplicate-code,multiple-imports,cyclic-import,fixme


[REPORTS]
Expand Down Expand Up @@ -151,7 +151,7 @@ method-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=__.*__
no-docstring-rgx=_.*

# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
Expand Down
Loading

0 comments on commit 2c29d90

Please sign in to comment.