Skip to content

Commit

Permalink
Fixed pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisspen committed Jun 26, 2024
1 parent b28003d commit f053720
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 198 deletions.
42 changes: 14 additions & 28 deletions bin/chroniker
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,18 @@ logger = logging.getLogger('chroniker')
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=('Run cron jobs for a Django '
'project using '
'django-chroniker.'),
'project using '
'django-chroniker.'),
epilog=("NOTE: You must provide one of "
"the following: settings or "
"project_dir."))
parser.add_argument(
'-s', metavar='settings', type=str, nargs='?',
dest="settings",
help=('Django settings module. You must provide.'))
parser.add_argument(
'-p', metavar='project_dir', type=str, nargs='?',
dest="project_dir", help='Path to project directory')
parser.add_argument(
'-e', metavar='virtualenv', type=str, nargs='?',
dest="virtualenv",
help=('Path to virtual environment "activate_this.py" file'))
parser.add_argument(
'-q', action='store_true', dest="quite", default=False,
help="Suppress output")
parser.add_argument(
'-l', action='store_true', dest="loud", default=False,
help="Display more output")
parser.add_argument(
'--jobs',
dest="jobs",
default='',
help='A comma-delimited list of job ids to limit executions to.')
"the following: settings or "
"project_dir.")
)
parser.add_argument('-s', metavar='settings', type=str, nargs='?', dest="settings", help=('Django settings module. You must provide.'))
parser.add_argument('-p', metavar='project_dir', type=str, nargs='?', dest="project_dir", help='Path to project directory')
parser.add_argument('-e', metavar='virtualenv', type=str, nargs='?', dest="virtualenv", help=('Path to virtual environment "activate_this.py" file'))
parser.add_argument('-q', action='store_true', dest="quite", default=False, help="Suppress output")
parser.add_argument('-l', action='store_true', dest="loud", default=False, help="Display more output")
parser.add_argument('--jobs', dest="jobs", default='', help='A comma-delimited list of job ids to limit executions to.')
args = parser.parse_args()

log_level = logging.INFO
Expand All @@ -58,7 +43,8 @@ if __name__ == "__main__":
if args.virtualenv:
virtualenv = os.path.abspath(args.virtualenv)
assert os.path.isfile(virtualenv), 'Virtualenv file "%s" does not exist.' % virtualenv
exec(open(virtualenv).read(), dict(__file__=virtualenv)) # pylint: disable=exec-used
with open(virtualenv, encoding='utf8') as fin:
exec(fin.read(), dict(__file__=virtualenv)) # pylint: disable=exec-used

# Now setup django
project_dir = args.project_dir
Expand All @@ -85,7 +71,7 @@ if __name__ == "__main__":
if settings:
os.environ['DJANGO_SETTINGS_MODULE'] = settings

jobs = args.jobs#(args.jobs or '').split(',')
jobs = args.jobs #(args.jobs or '').split(',')

logger.debug("Project dir: %s", project_dir)
logger.debug("Settings mod: %s", settings)
Expand Down
41 changes: 4 additions & 37 deletions chroniker/management/commands/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from collections import defaultdict
from functools import partial
from multiprocessing import Queue
from optparse import make_option

import psutil

Expand Down Expand Up @@ -129,7 +128,7 @@ def run_cron(jobs=None, **kwargs):
pass
elif os.path.isfile(pid_fn):
try:
old_pid = int(open(pid_fn, 'r').read())
old_pid = int(open(pid_fn, 'r', encoding='utf8').read())
if utils.pid_exists(old_pid):
print('%s already exists, exiting' % pid_fn)
sys.exit()
Expand All @@ -139,7 +138,7 @@ def run_cron(jobs=None, **kwargs):
pass
except TypeError:
pass
open(pid_fn, 'w').write(pid)
open(pid_fn, 'w', encoding='utf8').write(pid)
clear_pid = True

procs = []
Expand Down Expand Up @@ -167,13 +166,13 @@ def run_cron(jobs=None, **kwargs):
Job.objects.update()
job = Job.objects.get(id=job.id)
if not force_run and not job.is_due_with_dependencies_met(running_ids=running_ids):
utils.smart_print(u'Job {} {} is due but has unmet dependencies.'\
utils.smart_print('Job {} {} is due but has unmet dependencies.'\
.format(job.id, job))
continue

# Immediately mark the job as running so the next jobs can
# update their dependency check.
utils.smart_print(u'Running job {} {}.'.format(job.id, job))
utils.smart_print('Running job {} {}.'.format(job.id, job))
running_ids.add(job.id)
if dryrun:
continue
Expand Down Expand Up @@ -270,38 +269,6 @@ def run_cron(jobs=None, **kwargs):

class Command(BaseCommand):
help = 'Runs all jobs that are due.'
option_list = getattr(BaseCommand, 'option_list', ()) + (
make_option('--update_heartbeat',
dest='update_heartbeat',
default=1,
help='If given, launches a thread to asynchronously update ' + \
'job heartbeat status.'),
make_option('--force_run',
dest='force_run',
action='store_true',
default=False,
help='If given, forces all jobs to run.'),
make_option('--dryrun',
action='store_true',
default=False,
help='If given, only displays jobs to be run.'),
make_option('--jobs',
dest='jobs',
default='',
help='A comma-delimited list of job ids to limit executions to.'),
make_option('--name',
dest='name',
default='',
help='A name to give this process.'),
make_option('--sync',
action='store_true',
default=False,
help='If given, runs jobs one at a time.'),
make_option('--verbose',
action='store_true',
default=False,
help='If given, shows debugging info.'),
)

def add_arguments(self, parser):
parser.add_argument('--update_heartbeat',
Expand Down
2 changes: 1 addition & 1 deletion chroniker/management/commands/cronserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run(self):

class Command(BaseCommand):
args = "time"
help = _("Emulates a reoccurring cron call to run jobs at a specified " "interval. This is meant primarily for development use.")
help = _("Emulates a reoccurring cron call to run jobs at a specified interval. This is meant primarily for development use.")

def handle(self, *args, **options):

Expand Down
25 changes: 12 additions & 13 deletions chroniker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class Job(models.Model):
to the frequency options.''')
)

next_run = models.DateTimeField(_("next run"), blank=True, null=True, help_text=_("If you don't set this it will" " be determined automatically"))
next_run = models.DateTimeField(_("next run"), blank=True, null=True, help_text=_("If you don't set this it will be determined automatically"))

last_run_start_timestamp = models.DateTimeField(_("last run start timestamp"), editable=False, blank=True, null=True)

Expand Down Expand Up @@ -546,9 +546,9 @@ class Meta:

def __unicode__(self):
if self.enabled:
ret = u"{} - {} - {}".format(self.id, self.name, self.timeuntil)
ret = "{} - {} - {}".format(self.id, self.name, self.timeuntil)
else:
ret = u"{id} - {name} - disabled".format(**{'name': self.name, 'id': self.id})
ret = "{id} - {name} - disabled".format(**{'name': self.name, 'id': self.id})
if not isinstance(ret, str):
ret = str(ret)
return ret
Expand Down Expand Up @@ -812,8 +812,7 @@ def param_to_int(self, param_value):
val = int(param_value)
except ValueError as exc:
raise ValueError('rrule parameter should be integer or weekday ' 'constant (e.g. MO, TU, etc.). ' 'Error on: %s' % param_value) from exc
else:
return val
return val

def get_params(self):
"""
Expand Down Expand Up @@ -962,15 +961,15 @@ def handle_run(self, update_heartbeat=True, stdout_queue=None, stderr_queue=None

original_pid = os.getpid()

try:
# Redirect output so that we can log and easily check for errors.
stdout = utils.TeeFile(sys.stdout, auto_flush=True, queue=stdout_queue, local=self.log_stdout)
stderr = utils.TeeFile(sys.stderr, auto_flush=True, queue=stderr_queue, local=self.log_stderr)
ostdout = sys.stdout
ostderr = sys.stderr
sys.stdout = stdout
sys.stderr = stderr
# Redirect output so that we can log and easily check for errors.
stdout = utils.TeeFile(sys.stdout, auto_flush=True, queue=stdout_queue, local=self.log_stdout)
stderr = utils.TeeFile(sys.stderr, auto_flush=True, queue=stderr_queue, local=self.log_stderr)
ostdout = sys.stdout
ostderr = sys.stderr
sys.stdout = stdout
sys.stderr = stderr

try:
args, options = self.get_args()

heartbeat = None
Expand Down
3 changes: 1 addition & 2 deletions chroniker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ def pid_exists(pid):
os.kill(pid, 0)
except OSError as e:
return e.errno == errno.EPERM
else:
return True
return True


def get_cpu_usage(pid, interval=1):
Expand Down
111 changes: 1 addition & 110 deletions pylint.rc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
#
[MASTER]

# Specify a configuration file.
#rcfile=

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=

# Profiled execution.
profile=no

# Add <file or directory> to the black list. It should be a base name, not a
# path. You may set this option multiple times.
# Ignore all auto-generated South migration directories.
Expand All @@ -26,99 +16,20 @@ ignore=migrations,south_migrations
# Pickle collected data for later comparisons.
persistent=yes

# Set the cache size for astng objects.
cache-size=500

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=

[MESSAGES CONTROL]

# Enable only checker(s) with the given id(s). This option conflicts with the
# disable-checker option
#enable-checker=

# Enable all checker(s) except those with the given id(s). This option
# conflicts with the enable-checker option
#disable-checker=

# Enable all messages in the listed categories (IRCWEF).
#enable-msg-cat=

# Disable all messages in the listed categories (IRCWEF).
disable-msg-cat=I

# Enable the message(s) with the given id(s).
#enable-msg=

#http://docs.pylint.org/features.html
#http://pylint-messages.wikidot.com/all-codes
#pylint --list-msgs > pylint.messages

# All these are disabled below.
# C1001: old-style class defined (Django uses these for Meta options)
# C0103: variable regex check.
# C0111: missing docstring check. It's too vague. Complains about no docstrings in __init__ and other places we don't care about.
# C0330: bad-continuation
# E1101: member check...this is usually wrong.
# E1103: type inference...this is usually wrong.
# F0401: unable to import
# R0201: method should be function check.
# R0401: cyclic import check...because sometimes it's wrong.
# R0902: too many instance attributes check.
# R0903: too few public methods check...makes no sense with Django.
# R0904: too many public method check.
# R0913: too many argument check.
# R0921: abstract class not referenced check.
# W0104: no effect check.
# W0142: magic check.
# W0212: protected data check.
# W0232: __init__ check.
# W0311: bad-indentation
# W0401: wildcard import.
# W0404: reimport check...this is sometimes wrong.
# W0511: TODO check.
# W0612: unused variable check.
# W0613: unused argument check. Too vague.
# W0614: wildcard import usage check.
# W0704: empty except check.
# E1002: Use of super on an old style class
# E1120: No value for argument
# R0901: Too many ancestors
# E1123: Unexpected keyword argument %r in %s call
# C0302: *Too many lines in module (%s)*
# R0801: *Similar lines in %s files*
# R0914: *Too many local variables (%s/%s)*
# R0912: *Too many branches (%s/%s)*
# R0915: *Too many statements (%s/%s)*
# W0703: *Catching too general exception %s*
# E1003: *Bad first argument %r given to super()*
# E0202: *An attribute defined in %s line %s hides this method*
# W0201: *Attribute %r defined outside __init__*
# W0221: *Arguments number differs from %s method*
# C0325: *Unnecessary parens after %r keyword*
# R0916: too-many-boolean-expressions
# R0204: *Redefinition of %s type from %s to %s*
# R0101: *Too many nested blocks (%s/%s)*
# I0011: *Locally disabling %s (%s)*
# W1001: *Use of "property" on an old style class*
disable=C1001,C0103,R0201,W0212,W0614,W0401,W0704,E1101,W0142,R0904,R0913,W0404,R0903,W0232,C0111,W0613,W0612,W0511,W0104,R0902,R0921,R0401,E1103,W0311,C0330,F0401,E1002,E1120,R0901,E1123,C0302,R0801,R0914,R0912,R0915,W0703,E1003,E0202,W0201,W0221,C0325,R0916,R0204,R0101,I0011,W1001,consider-using-ternary,unsubscriptable-object,inconsistent-return-statements,keyword-arg-before-vararg,wrong-import-order
disable=C0103,W0212,W0614,W0401,E1101,R0904,R0913,W0404,R0903,C0111,W0613,W0612,W0511,W0104,R0902,R0401,E1103,W0311,F0401,E1120,R0901,E1123,C0302,R0801,R0914,R0912,R0915,W0703,E1003,E0202,W0201,W0221,C0325,R0916,R0101,I0011,consider-using-ternary,unsubscriptable-object,inconsistent-return-statements,keyword-arg-before-vararg,wrong-import-order,use-dict-literal,consider-using-f-string,consider-using-with,unsupported-binary-operation,broad-exception-raised,unnecessary-lambda-assignment

[REPORTS]

# Set the output format. Available formats are text, parseable, colorized, msvs
# (visual studio) and html
output-format=text

# Include message's id in output
include-ids=yes

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=no

Expand All @@ -129,16 +40,6 @@ reports=no
# (R0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)

# Add a comment according to your evaluation note. This is used by the global
# evaluation report (R0004).
comment=no

# Enable the report(s) with the given id(s).
#enable-report=

# Disable the report(s) with the given id(s).
#disable-report=


# checks for :
# * doc strings
Expand Down Expand Up @@ -190,9 +91,6 @@ good-names=i,j,k,ex,Run,_
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata

# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input


# try to find bugs in the code using type inference
#
Expand All @@ -206,10 +104,6 @@ ignore-mixin-members=yes
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject

# When zope mode is activated, add a predefined set of Zope acquired attributes
# to generated-members.
zope=no

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed.
generated-members=REQUEST,acl_users,aq_parent
Expand Down Expand Up @@ -273,9 +167,6 @@ max-locals=15
# Maximum number of return / yield for function / method body
max-returns=6

# Maximum number of branch for function / method body
max-branchs=12

# Maximum number of statements in function / method body
max-statements=50

Expand Down
Loading

0 comments on commit f053720

Please sign in to comment.