#2220 frontend: avoid cyclic imports, and function-local imports
Merged 2 months ago by frostyx. Opened 2 months ago by praiskup.
copr/ praiskup/copr preparations-cyclic  into  main

@@ -27,7 +27,6 @@ 

  from coprs.helpers import fix_protocol_for_backend, clone_sqlalchemy_instance

  

  from coprs.logic.actions_logic import ActionsLogic

- from coprs.logic.users_logic import UsersLogic

  

  

  class CoprsLogic(object):
@@ -267,7 +266,7 @@ 

  

  

          if group is not None:

-             UsersLogic.raise_if_not_in_group(user, group)

+             users_logic.UsersLogic.raise_if_not_in_group(user, group)

              copr.group = group

  

          copr_dir = models.CoprDir(
@@ -406,7 +405,7 @@ 

              return

  

          if copr.group:

-             return UsersLogic.raise_if_not_in_group(user, copr.group)

+             return users_logic.UsersLogic.raise_if_not_in_group(user, copr.group)

  

          if user == copr.user:

              return
@@ -899,7 +898,7 @@ 

              buildroot_pkgs = ""

          if repos is None:

              repos = ""

-         UsersLogic.raise_if_cant_update_copr(

+         users_logic.UsersLogic.raise_if_cant_update_copr(

              user, copr,

              "Only owners and admins may update their projects.")

  
@@ -940,7 +939,7 @@ 

          :type user: models.User

          :type copr_chroot: models.CoprChroot

          """

-         UsersLogic.raise_if_cant_update_copr(

+         users_logic.UsersLogic.raise_if_cant_update_copr(

              user, copr_chroot.copr,

              "Only owners and admins may update their projects.")

  
@@ -1008,7 +1007,7 @@ 

          :type user: models.User

          """

  

-         UsersLogic.raise_if_cant_update_copr(

+         users_logic.UsersLogic.raise_if_cant_update_copr(

              user, copr,

              "Only owners and admins may update their projects.")

  
@@ -1101,7 +1100,7 @@ 

  

      @classmethod

      def remove_comps(cls, user, copr_chroot):

-         UsersLogic.raise_if_cant_update_copr(

+         users_logic.UsersLogic.raise_if_cant_update_copr(

              user, copr_chroot.copr,

              "Only owners and admins may update their projects.")

  
@@ -1115,7 +1114,7 @@ 

          """

          :param models.CoprChroot chroot:

          """

-         UsersLogic.raise_if_cant_update_copr(

+         users_logic.UsersLogic.raise_if_cant_update_copr(

              user, copr_chroot.copr,

              "Only owners and admins may update their projects.")

  

@@ -5,6 +5,7 @@ 

  from flask import url_for

  

  from coprs import app, db

+ from coprs.logic import coprs_logic

  from coprs.models import User, Group

  from coprs.helpers import copr_url, generate_api_token

  from sqlalchemy import update
@@ -202,11 +203,10 @@ 

  

      @property

      def projects(self):

-         # @FIXME We get into circular import when this import is on module-level

-         from coprs.logic.coprs_logic import CoprsLogic

          return [{"full_name": p.full_name,

                   "url": copr_url("coprs_ns.copr_detail", p, _external=True)}

-                 for p in CoprsLogic.filter_by_user_name(CoprsLogic.get_multiple(), self.user.name)]

+                 for p in coprs_logic.CoprsLogic.filter_by_user_name(

+                         coprs_logic.CoprsLogic.get_multiple(), self.user.name)]

  

      @property

      def builds(self):

Typical work-around to the "cyclic import" problems in Python is stop
consuming the module contents at the "importing time" (aka "from module
import Class") but delay the consumption to the runtime. We shouldn't
delay the importing stuff to runtime, though.

rebased onto 147a9ec6c06b29831277970e5dcc398c76a179bf

2 months ago

Build succeeded.

rebased onto 6c2fa2d

2 months ago

Build succeeded.

Pull-Request has been merged by frostyx

2 months ago