#1960 Flake8 clean up of pagure.lib
Merged 7 years ago by pingou. Opened 7 years ago by pingou.

file modified
+31 -32
@@ -225,9 +225,6 @@ 

          # Nothing to do here, move right along

          return

  

-         #keyline_file = os.path.join(gitolite_keydir,

-         #                            'keys_%i' % i,

-         #                            '%s.pub' % user.user)

      # First remove deploykeys that no longer exist

      keyfiles = ['deploykey_%s_%s.pub' %

                  (werkzeug.secure_filename(project.fullname),
@@ -605,9 +602,6 @@ 

              repo=issue_blocked.project,

              repofolder=ticketfolder)

  

-         #pagure.lib.notify.notify_assigned_issue(issue, user_obj)

-         #pagure.lib.notify.notify_assigned_issue(issue_blocked, user_obj)

- 

          if not issue.private:

              pagure.lib.notify.log(

                  issue.project,
@@ -665,9 +659,6 @@ 

              repo=issue_blocked.project,

              repofolder=ticketfolder)

  

-         #pagure.lib.notify.notify_assigned_issue(issue, user_obj)

-         #pagure.lib.notify.notify_assigned_issue(issue_blocked, user_obj)

- 

          if not issue.private:

              pagure.lib.notify.log(

                  issue.project,
@@ -810,8 +801,8 @@ 

  

      # check for change

      no_change_in_tag = old_tag.tag == new_tag \

-                        and old_tag_description == new_tag_description \

-                        and old_tag_color == new_tag_color

+         and old_tag_description == new_tag_description \

+         and old_tag_color == new_tag_color

      if no_change_in_tag:

          raise pagure.exceptions.PagureException(

              'No change.  Old tag "%s(%s)[%s]" is the same as '
@@ -852,9 +843,12 @@ 

              issue, repo=issue.project, repofolder=ticketfolder)

  

      msgs = []

-     msgs.append('Edited tag: %s(%s)[%s] to %s(%s)[%s]' %

-                 (old_tag_name, old_tag_description, old_tag_color,

-                 new_tag, new_tag_description, new_tag_color))

+     msgs.append(

+         'Edited tag: %s(%s)[%s] to %s(%s)[%s]' % (

+             old_tag_name, old_tag_description, old_tag_color,

+             new_tag, new_tag_description, new_tag_color

+         )

+     )

      pagure.lib.notify.log(

          project,

          topic='project.tag.edited',
@@ -897,7 +891,7 @@ 

      # If we dupe keys, gitolite might choke.

      ssh_search_key = ssh_short_key.split(' ')[1]

      if session.query(model.DeployKey).filter(

-             model.DeployKey.ssh_search_key==ssh_search_key).count() != 0:

+             model.DeployKey.ssh_search_key == ssh_search_key).count() != 0:

          raise pagure.exceptions.PagureException(

              'Deploy key already exists.'

          )
@@ -926,8 +920,11 @@ 

      new_user_obj = get_user(session, new_user)

      user_obj = get_user(session, user)

  

-     users = set([user_.user for user_ in

-         get_project_users(session, project, access, combine=False)])

+     users = set([

+         user_.user

+         for user_ in get_project_users(

+             session, project, access, combine=False)

+     ])

      users.add(project.user.user)

  

      if new_user in users:
@@ -1014,8 +1011,11 @@ 

              'You are not allowed to add a group of users to this project'

          )

  

-     groups = set([group.group_name for group in

-         get_project_groups(session, project, access, combine=False)])

+     groups = set([

+         group.group_name

+         for group in get_project_groups(

+             session, project, access, combine=False)

+     ])

  

      if new_group in groups:

          raise pagure.exceptions.PagureException(
@@ -1302,7 +1302,7 @@ 

      if repo:

          raise pagure.exceptions.RepoExistsException(

              'The project repo "%s" already exists in the database' % (

-             path)

+                 path)

          )

  

      project = model.Project(
@@ -2197,11 +2197,11 @@ 

                  )

          elif str(assignee).lower() in ['true', '1']:

              query = query.filter(

-                 model.Issue.assignee_id != None

+                 model.Issue.assignee_id.isnot(None)

              )

          else:

              query = query.filter(

-                 model.Issue.assignee_id == None

+                 model.Issue.assignee_id.is_(None)

              )

      if author is not None:

          query = query.filter(
@@ -2232,13 +2232,13 @@ 

          if isinstance(milestones, basestring):

              milestones = [milestones]

          query = query.filter(

-             (model.Issue.milestone == None) |

+             (model.Issue.milestone.is_(None)) |

              (model.Issue.milestone.in_(milestones))

          )

      elif no_milestones:

          # Asking for issues without a milestone

          query = query.filter(

-             model.Issue.milestone == None

+             model.Issue.milestone.is_(None)

          )

      elif milestones is not None and milestones != []:

          # Asking for a single specific milestone
@@ -2428,11 +2428,11 @@ 

                  )

          elif str(assignee).lower() in ['true', '1']:

              query = query.filter(

-                 model.PullRequest.assignee_id != None

+                 model.PullRequest.assignee_id.isnot(None)

              )

          else:

              query = query.filter(

-                 model.PullRequest.assignee_id == None

+                 model.PullRequest.assignee_id.is_(None)

              )

  

      if author is not None:
@@ -2505,7 +2505,7 @@ 

  def reset_status_pull_request(session, project):

      ''' Reset the status of all opened Pull-Requests of a project.

      '''

-     query = session.query(

+     session.query(

          model.PullRequest

      ).filter(

          model.PullRequest.project_id == project.id
@@ -2750,7 +2750,6 @@ 

      toadd = set(depends) - set(issue.depends_text)

      torm = set(issue.depends_text) - set(depends)

      messages = []

-     comment = ""

  

      # Add issue depending

      for depend in sorted([int(i) for i in toadd]):
@@ -2817,7 +2816,6 @@ 

              # we should never be in this case but better safe than sorry...

              continue

  

- 

          add_issue_dependency(

              session,

              issue=issue,
@@ -3302,7 +3300,7 @@ 

      if text:

          try:

              text = md_processor.convert(text)

-         except Exception as err:

+         except Exception:

              LOG.debug(

                  'A markdown error occured while processing: ``%s``',

                  str(text))
@@ -3333,12 +3331,12 @@ 

      attrs['table'] = ['class']

      attrs['span'] = ['class', 'id']

      attrs['div'] = ['class']

-     if not ignore or not 'img' in ignore:

+     if not ignore or 'img' not in ignore:

          attrs['img'] = filter_img_src

  

      tags = bleach.ALLOWED_TAGS + [

          'p', 'br', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',

-         'table', 'td', 'tr', 'th', 'thead','tbody',

+         'table', 'td', 'tr', 'th', 'thead', 'tbody',

          'col', 'pre', 'img', 'hr', 'dl', 'dt', 'dd', 'span',

          'kbd', 'var', 'del', 'cite',

      ]
@@ -3971,6 +3969,7 @@ 

      """

      if pattern is None:

          return {}, None

+ 

      def finalize_token(token, custom_search):

          if ':' in token:

              # This was a "key:value" parameter

file modified
+1 -1
@@ -17,7 +17,7 @@ 

  

  from chardet import universaldetector

  

- from pagure.exceptions import PagureException

+ from pagure.exceptions import PagureEncodingException

  

  

  _log = logging.getLogger(__name__)

file modified
+4 -3
@@ -1210,7 +1210,7 @@ 

      refname = '%s:refs/heads/%s' % (branch_ref.name, request.branch)

      if (

              (merge is not None and merge.is_uptodate)

-             or

+             or  # noqa

              (merge is None and

               mergecode & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE)):

  
@@ -1236,7 +1236,7 @@ 

  

      elif (

              (merge is not None and merge.is_fastforward)

-             or

+             or  # noqa

              (merge is None and

               mergecode & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD)):

  
@@ -1349,7 +1349,8 @@ 

          raise pagure.exceptions.PagureException(

              'Fork is empty, there are no commits to request pulling')

  

-     if not orig_repo.is_empty and request.branch not in orig_repo.listall_branches():

+     if not orig_repo.is_empty \

+             and request.branch not in orig_repo.listall_branches():

          raise pagure.exceptions.PagureException(

              'The branch into which this pull-request was to be merged: %s '

              'seems to no longer be present in this repo' % request.branch)

file modified
-2
@@ -14,8 +14,6 @@ 

  

  import pagure.exceptions

  import pagure.lib

- from pagure.lib import model

- from pagure.hooks import pagure_ci

  

  

  BUILD_STATS = {

file modified
+21 -12
@@ -8,8 +8,8 @@ 

  

  """

  

- __requires__ = ['SQLAlchemy >= 0.8', 'jinja2 >= 2.4']

- import pkg_resources

+ __requires__ = ['SQLAlchemy >= 0.8', 'jinja2 >= 2.4']  # noqa

+ import pkg_resources  # noqa

  

  import datetime

  import collections
@@ -32,7 +32,7 @@ 

  CONVENTION = {

      "ix": 'ix_%(table_name)s_%(column_0_label)s',

      # Checks are currently buggy and prevent us from naming them correctly

-     #"ck": "ck_%(table_name)s_%(constraint_name)s",

+     # "ck": "ck_%(table_name)s_%(constraint_name)s",

      "fk": "%(table_name)s_%(column_0_name)s_fkey",

      "pk": "%(table_name)s_pkey",

      "uq": "%(table_name)s_%(column_0_name)s_key",
@@ -408,7 +408,8 @@ 

          secondaryjoin="pagure_group.c.id==projects_groups.c.group_id",

          backref=backref(

              "projects",

-             order_by="func.lower(projects.c.namespace).desc(), func.lower(projects.c.name)"

+             order_by="func.lower(projects.c.namespace).desc(), \

+                       func.lower(projects.c.name)"

          )

      )

  
@@ -763,8 +764,10 @@ 

              'deploykeys', cascade="delete, delete-orphan", single_parent=True)

          )

  

-     creator_user = relation('User', foreign_keys=[creator_user_id],

-                     remote_side=[User.id])

+     creator_user = relation(

+         'User',

+         foreign_keys=[creator_user_id],

+         remote_side=[User.id])

  

  

  class Issue(BASE):
@@ -889,7 +892,9 @@ 

                      link, filename, display_name = extract_info(line)

                      attachments.append(

                          (link, filename, display_name,

-                          self.date_created.strftime('%Y-%m-%d %H:%M:%S'), None))

+                          self.date_created.strftime('%Y-%m-%d %H:%M:%S'),

+                          None)

+                     )

          if self.comments:

              # Check the comments for attachments

              for comment in self.comments:
@@ -903,7 +908,8 @@ 

                          link, filename, display_name = extract_info(line)

                          attachments.append(

                              (link, filename, display_name,

-                              comment.date_created.strftime('%Y-%m-%d %H:%M:%S'),

+                              comment.date_created.strftime(

+                                 '%Y-%m-%d %H:%M:%S'),

                               str(comment.id)))

          return attachments

  
@@ -1173,13 +1179,15 @@ 

      issue = relation(

          'Issue', foreign_keys=[issue_uid], remote_side=[Issue.uid],

          backref=backref(

-             'other_fields', cascade="delete, delete-orphan", single_parent=True)

+             'other_fields',

+             cascade="delete, delete-orphan",

+             single_parent=True)

          )

  

      key = relation(

          'IssueKeys', foreign_keys=[key_id], remote_side=[IssueKeys.id],

          backref=backref('values', cascade="delete, delete-orphan")

-         )

+     )

  

  

  class Tag(BASE):
@@ -1228,7 +1236,6 @@ 

          return 'TagIssue(issue:%s, tag:%s)' % (self.issue.id, self.tag)

  

  

- 

  class TagColored(BASE):

      """ Stores the colored tags.

  
@@ -2088,7 +2095,9 @@ 

      )

  

      pull_request = relation(

-         'PullRequest', foreign_keys=[pull_request_uid], remote_side=[PullRequest.uid],

+         'PullRequest',

+         foreign_keys=[pull_request_uid],

+         remote_side=[PullRequest.uid],

          backref=backref(

              'watchers', cascade="delete, delete-orphan",

          ),

no initial comment

1 new commit added

  • Finish cleaning up with flake8 the pagure.lib module
7 years ago

1 new commit added

  • Use is_() and isnot() when filtering for None or not None in queries
7 years ago

I'm a huge fan of PEP-8ing as you know from my PRs ☺

LGTM!

Thanks for the review, rebasing and merging then :)

rebased

7 years ago

Pull-Request has been merged by pingou

7 years ago