From f05372005c8f17323141c1ff488e155567df4a1a Mon Sep 17 00:00:00 2001 From: chrisspen Date: Tue, 25 Jun 2024 22:00:09 -0400 Subject: [PATCH] Fixed pylint errors --- bin/chroniker | 42 +++----- chroniker/management/commands/cron.py | 41 +------- chroniker/management/commands/cronserver.py | 2 +- chroniker/models.py | 25 +++-- chroniker/utils.py | 3 +- pylint.rc | 111 +------------------- setup.py | 10 +- 7 files changed, 36 insertions(+), 198 deletions(-) diff --git a/bin/chroniker b/bin/chroniker index b155ee1..d213d6f 100755 --- a/bin/chroniker +++ b/bin/chroniker @@ -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 @@ -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 @@ -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) diff --git a/chroniker/management/commands/cron.py b/chroniker/management/commands/cron.py index 7441bfd..597866c 100644 --- a/chroniker/management/commands/cron.py +++ b/chroniker/management/commands/cron.py @@ -6,7 +6,6 @@ from collections import defaultdict from functools import partial from multiprocessing import Queue -from optparse import make_option import psutil @@ -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() @@ -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 = [] @@ -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 @@ -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', diff --git a/chroniker/management/commands/cronserver.py b/chroniker/management/commands/cronserver.py index af0b8d3..8957f4b 100644 --- a/chroniker/management/commands/cronserver.py +++ b/chroniker/management/commands/cronserver.py @@ -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): diff --git a/chroniker/models.py b/chroniker/models.py index 4180cd8..082b793 100644 --- a/chroniker/models.py +++ b/chroniker/models.py @@ -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) @@ -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 @@ -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): """ @@ -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 diff --git a/chroniker/utils.py b/chroniker/utils.py index c16a496..7f068ae 100644 --- a/chroniker/utils.py +++ b/chroniker/utils.py @@ -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): diff --git a/pylint.rc b/pylint.rc index 6d25eb4..76b6743 100644 --- a/pylint.rc +++ b/pylint.rc @@ -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 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. @@ -26,84 +16,13 @@ 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] @@ -111,14 +30,6 @@ disable=C1001,C0103,R0201,W0212,W0614,W0401,W0704,E1101,W0142,R0904,R0913,W0404, # (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 @@ -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 @@ -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 # @@ -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 @@ -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 diff --git a/setup.py b/setup.py index 9e5dd62..88ac95c 100644 --- a/setup.py +++ b/setup.py @@ -6,18 +6,14 @@ CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) -try: - with open(os.path.join(CURRENT_DIR, 'README.md'), encoding='utf-8') as f: - long_description = f.read() -except TypeError: - with open(os.path.join(CURRENT_DIR, 'README.md')) as f: - long_description = f.read() +with open(os.path.join(CURRENT_DIR, 'README.md'), encoding='utf-8') as f: + long_description = f.read() def get_reqs(*fns): lst = [] for fn in fns: - for package in open(os.path.join(CURRENT_DIR, fn)).readlines(): + for package in open(os.path.join(CURRENT_DIR, fn), encoding='utf-8').readlines(): package = package.strip() if not package: continue