#86 Run black on the dist_git_auth plugin and pagure_distgit
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

file modified
+40 -35
@@ -30,6 +30,7 @@ 

  

  from pagure.config import config as pagure_config

  from pagure.lib import model

+ 

  try:

      from pagure.lib import get_user

  except ImportError:
@@ -44,6 +45,7 @@ 

  

  class DistGitAuth(GitAuthHelper):

      """ A Fedora and CentOS dist-Git authentication module. """

+ 

      is_dynamic = True

  

      def __init__(self):
@@ -51,25 +53,27 @@ 

  

          self.is_debug = pagure_config.get("ACL_DEBUG", False)

          self.global_pr_only = pagure_config.get("PR_ONLY", False)

-         self.block_unspecified = pagure_config.get("ACL_BLOCK_UNSPECIFIED",

-                                                    True)

-         self.blacklists = [re.compile(refre)

-                            for refre

-                            in pagure_config["BLACKLIST_RES"]]

+         self.block_unspecified = pagure_config.get(

+             "ACL_BLOCK_UNSPECIFIED", True

+         )

+         self.blacklists = [

+             re.compile(refre) for refre in pagure_config["BLACKLIST_RES"]

+         ]

          self.unspecified_blacklist = [

              re.compile(refre)

-             for refre

-             in pagure_config.get("UNSPECIFIED_BLACKLIST_RES", [])]

-         self.rcm_branches = [re.compile(refre)

-                              for refre

-                              in pagure_config["RCM_BRANCHES"]]

+             for refre in pagure_config.get("UNSPECIFIED_BLACKLIST_RES", [])

+         ]

+         self.rcm_branches = [

+             re.compile(refre) for refre in pagure_config["RCM_BRANCHES"]

+         ]

          self.rcm_group = pagure_config.get("RCM_GROUP")

          self.supported_sigs = set(pagure_config.get("SUPPORTED_SIGS", []))

          self.sig_prefixes = pagure_config.get("SIG_PREFIXES", [])

          self.protected_namespaces = pagure_config.get(

-             "ACL_PROTECTED_NAMESPACES", ["rpms"])

+             "ACL_PROTECTED_NAMESPACES", ["rpms"]

+         )

  

-         pdc_url = pagure_config.get('PDC_URL')

+         pdc_url = pagure_config.get("PDC_URL")

          if pdc_url and PDCClient:

              self.pdcclient = PDCClient(pdc_url, develop=True)

          else:
@@ -84,23 +88,25 @@ 

          if not self.pdcclient:

              # No way to confirm this is a supported branch, not supported

              return None

-         if not refname.startswith('refs/heads/'):

+         if not refname.startswith("refs/heads/"):

              # Anything outside of refs/heads is out-of-scope

              return None

-         refname = refname[len('refs/heads/'):]

+         refname = refname[len("refs/heads/") :]

  

          namespace2pdctype = {

-             'rpms': 'rpm',

-             'modules': 'module',

-             'container': 'container',

+             "rpms": "rpm",

+             "modules": "module",

+             "container": "container",

          }

-         res = list(self.pdcclient.get_paged(

-             self.pdcclient['component-branches'],

-             global_component=project.name,

-             type=namespace2pdctype[project.namespace],

-             name=refname,

-             fields=['active'],

-         ))

+         res = list(

+             self.pdcclient.get_paged(

+                 self.pdcclient["component-branches"],

+                 global_component=project.name,

+                 type=namespace2pdctype[project.namespace],

+                 name=refname,

+                 fields=["active"],

+             )

+         )

          if len(res) == 0:

              # No status

              return None
@@ -108,7 +114,7 @@ 

              # PDC couldn't make up its mind....

              # Should never happen, but just in case...

              raise ValueError("PDC was unable to make up its mind")

-         return res[0]['active']

+         return res[0]["active"]

  

      def info(self, msg):

          """ Function to print information.
@@ -148,7 +154,7 @@ 

              return False

  

          # Do not allow branch deletions

-         if not project.is_fork and revto == '0'*40:

+         if not project.is_fork and revto == "0" * 40:

              self.info("Branch deletion is not allowed")

              return False

  
@@ -189,9 +195,9 @@ 

          self.debug("Blacklists: %s" % self.blacklists)

          self.debug("User: %s" % user)

          self.debug("User groups: %s" % usergroups)

-         self.debug('Committer: %s' % is_committer)

-         self.debug('SIG memberships: %s' % user_sigs)

-         self.debug('RCM: %s' % is_rcm)

+         self.debug("Committer: %s" % is_committer)

+         self.debug("SIG memberships: %s" % user_sigs)

+         self.debug("RCM: %s" % is_rcm)

  

          # We have data, start the actual ACL checking

          if (
@@ -234,8 +240,9 @@ 

                  self.debug("No supported status available")

  

              if self.block_unspecified:

-                 self.info("Access to namespace %s is restricted"

-                           % project.namespace)

+                 self.info(

+                     "Access to namespace %s is restricted" % project.namespace

+                 )

                  return False

  

              # Block second level blacklists
@@ -254,10 +261,8 @@ 

              # this is not a fork, only allow pushing if this is a PR merge.

              pr_only = project.settings.get("pull_request_access_only", False)

              if (

-                 (pr_only

-                 or (self.global_pr_only and not project.is_fork))

-                 and pull_request is None

-             ):

+                 pr_only or (self.global_pr_only and not project.is_fork)

+             ) and pull_request is None:

                  self.info("A pull request is required for this branch")

                  return False

  

file modified
+69 -33
@@ -122,7 +122,7 @@ 

              500,

              error_code=APIERROR.ENOCODE,

              error="This pagure instance has no PDC_URL configured, please inform"

-             " your pagure administrators"

+             " your pagure administrators",

          )

      else:

          pdc_url = "%s/component-branches/" % pdc_url.rstrip("/")
@@ -134,8 +134,9 @@ 

          "modules": "module",

          "container": "container",

      }

-     to_pdc_namespace = flask.current_app.config.get("PDC_NAMESPACES") \

-         or to_pdc_namespace

+     to_pdc_namespace = (

+         flask.current_app.config.get("PDC_NAMESPACES") or to_pdc_namespace

+     )

  

      try:

          pdc_namespace = to_pdc_namespace[namespace]
@@ -143,12 +144,15 @@ 

          raise pagure.exceptions.APIError(

              500,

              error_code=APIERROR.ENOCODE,

-             error="Namespace: %s could not be converted to a PDC namespace" %

-                 namespace

+             error="Namespace: %s could not be converted to a PDC namespace"

+             % namespace,

          )

  

      url = "%s?global_component=%s&name=master&type=%s" % (

-         pdc_url, name, pdc_namespace)

+         pdc_url,

+         name,

+         pdc_namespace,

+     )

  

      _log.info("Querying PDC at: %s", url)

      try:
@@ -157,7 +161,7 @@ 

          raise pagure.exceptions.APIError(

              500,

              error_code=APIERROR.ENOCODE,

-             error="An error occured while querying pdc: %s" % err

+             error="An error occured while querying pdc: %s" % err,

          )

  

      try:
@@ -166,10 +170,12 @@ 

          raise pagure.exceptions.APIError(

              500,

              error_code=APIERROR.ENOCODE,

-             error="The output of %s could not be converted to JSON" % req.url

+             error="The output of %s could not be converted to JSON" % req.url,

          )

  

-     _log.info("%s/%s is active: %s", namespace, name, data["results"][0]["active"])

+     _log.info(

+         "%s/%s is active: %s", namespace, name, data["results"][0]["active"]

+     )

      return data["results"][0]["active"] == True

  

  
@@ -196,7 +202,7 @@ 

          )

  

      user_grps = set(user_obj.groups)

-     req_grps = set(['packager'])

+     req_grps = set(["packager"])

      if not user_grps.intersection(req_grps):

          raise pagure.exceptions.APIError(

              403,
@@ -210,7 +216,7 @@ 

              400,

              error_code=APIERROR.EINVALIDREQ,

              errors="This project has been retired and cannot be unorphaned "

-                 "here, please open a releng ticket for it.",

+             "here, please open a releng ticket for it.",

          )

  

      try:
@@ -225,9 +231,7 @@ 

      pagure.lib.notify.log(

          repo,

          topic="project.adopt",

-         msg=dict(

-             project=repo.to_json(public=True), agent=user_obj.username

-         ),

+         msg=dict(project=repo.to_json(public=True), agent=user_obj.username),

      )

  

      output = {"point_of_contact": repo.user.user}
@@ -242,9 +246,14 @@ 

      """

      if namespace not in ["rpms"]:

          raise pagure.exceptions.APIError(

-             400, error_code=APIERROR.EINVALIDREQ, errors=["Namespace not supported"])

+             400,

+             error_code=APIERROR.EINVALIDREQ,

+             errors=["Namespace not supported"],

+         )

  

-     _log.info("Received request for the bodhi updates of: %s/%s", namespace, repo)

+     _log.info(

+         "Received request for the bodhi updates of: %s/%s", namespace, repo

+     )

  

      repo = _get_repo(repo, namespace=namespace)

      html = pagure.utils.is_true(flask.request.args.get("html", False))
@@ -262,11 +271,17 @@ 

          req = requests.get(url)

          if not req.ok:

              raise pagure.exceptions.APIError(

-                 400, error_code=APIERROR.EINVALIDREQ, errors=["Could not call bodhi"])

+                 400,

+                 error_code=APIERROR.EINVALIDREQ,

+                 errors=["Could not call bodhi"],

+             )

  

          data = req.json()

          for release in data.get("releases", []):

-             if any(word in release["long_name"] for word in ["Flatpaks", "Containers", "Modular"]):

+             if any(

+                 word in release["long_name"]

+                 for word in ["Flatpaks", "Containers", "Modular"]

+             ):

                  continue

              if release["state"] in ["pending", "current"]:

                  releases[release["name"]] = release["long_name"]
@@ -278,14 +293,20 @@ 

          page += 1

  

      # Retrieves the updates of that package in bodhi

-     update_url = "%s/updates?packages=%s" % (bodhi_base_url.rstrip("/"), repo.name)

+     update_url = "%s/updates?packages=%s" % (

+         bodhi_base_url.rstrip("/"),

+         repo.name,

+     )

      updates = collections.defaultdict(dict)

  

      _log.info("Calling bodhi at: %s", update_url)

      req = requests.get(update_url)

      if not req.ok:

          raise pagure.exceptions.APIError(

-             400, error_code=APIERROR.EINVALIDREQ, errors=["Could not call bodhi"])

+             400,

+             error_code=APIERROR.EINVALIDREQ,

+             errors=["Could not call bodhi"],

+         )

  

      data = req.json()

      for update in data["updates"]:
@@ -308,30 +329,45 @@ 

              row = "<tr><td scope='row' class='text-align-left'>{release}</td><td>{stable}</td><td>{testing}</td></tr>"

              stable = ""

              if updates.get(release, {}).get("stable"):

-                 stable = "<a href='https://koji.fedoraproject.org/koji/search?" \

-                 "terms={0}&type=build&match=glob'>{0}</a>".format(

-                     updates[release].get("stable"))

+                 stable = (

+                     "<a href='https://koji.fedoraproject.org/koji/search?"

+                     "terms={0}&type=build&match=glob'>{0}</a>".format(

+                         updates[release].get("stable")

+                     )

+                 )

              else:

                  # This makes things a little slower and is only needed up until all releases will have gone

                  # through bodhi all the time (ie: up until about F31 is eol).

-                 mdapi_url = "https://mdapi.fedoraproject.org/%s/srcpkg/%s" % (release.lower(), repo.name)

+                 mdapi_url = "https://mdapi.fedoraproject.org/%s/srcpkg/%s" % (

+                     release.lower(),

+                     repo.name,

+                 )

                  _log.info("Calling mdapi at: %s", mdapi_url)

                  req = requests.get(mdapi_url)

                  if req.ok:

                      _log.info("mdapi returned ok")

                      data = req.json()

-                     build = "%s-%s-%s" % (data["basename"], data["version"], data["release"])

-                     stable = "<a href='https://koji.fedoraproject.org/koji/search?" \

-                         "terms={0}&type=build&match=glob'>{0}</a>".format(build)

+                     build = "%s-%s-%s" % (

+                         data["basename"],

+                         data["version"],

+                         data["release"],

+                     )

+                     stable = (

+                         "<a href='https://koji.fedoraproject.org/koji/search?"

+                         "terms={0}&type=build&match=glob'>{0}</a>".format(

+                             build

+                         )

+                     )

              testing = ""

              if updates.get(release, {}).get("testing"):

-                 testing = "<a href='https://koji.fedoraproject.org/koji/search?" \

-                 "terms={0}&type=build&match=glob'>{0}</a>".format(

-                     updates[release].get("testing"))

+                 testing = (

+                     "<a href='https://koji.fedoraproject.org/koji/search?"

+                     "terms={0}&type=build&match=glob'>{0}</a>".format(

+                         updates[release].get("testing")

+                     )

+                 )

              row = row.format(

-                 release=releases[release],

-                 stable=stable,

-                 testing=testing,

+                 release=releases[release], stable=stable, testing=testing

              )

              html_output += row

          html_output += "</table>"

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

:thumbsup:

with -l79 ?

with -l79 ?

Yes, force of habits :)

with -l79 ?

Yes, force of habits :)

fine, just wanna know how to run it and not reformat all the files :)

Thanks for the review!

Pull-Request has been merged by pingou

5 years ago