#1019 [WIP] Suppress deprecation warnings from libmodulemd
Closed 7 months ago by cqi. Opened 7 months ago by cqi.
cqi/fm-orchestrator suppress-warnings  into  master

@@ -502,7 +502,7 @@ 

              # multilib is not enabled for this srpm in MMD.

              try:

                  mmd_component = mmd.get_rpm_components()[srpm]

-                 multilib = mmd_component.get_multilib()

+                 multilib = mmd_component.peek_multilib()

                  multilib = multilib.get() if multilib else set()

                  # The `multilib` set defines the list of architectures for which

                  # the multilib is enabled.

@@ -141,7 +141,7 @@ 

          # the return deps should be runtime requires or buildrequires.

          normdeps = lambda mmd, fn: [{name: streams.get()

                                       for name, streams in getattr(dep, fn)().items()}

-                                     for dep in mmd.get_dependencies()]

+                                     for dep in mmd.peek_dependencies()]

  

          # Each solvable object has name, version, architecture and list of

          # provides/requires/conflicts which defines its relations with other solvables.

@@ -175,7 +175,7 @@ 

  

              # Fill in the "Requires" of this module, so we can track its dependencies

              # on other modules.

-             requires = self._deps2reqs(normdeps(mmd, "get_requires"))

+             requires = self._deps2reqs(normdeps(mmd, "peek_requires"))

              solvable.add_deparray(solv.SOLVABLE_REQUIRES, requires)

  

              # Add "Conflicts: module(name)", because TODO, ask ignatenko.

@@ -212,7 +212,7 @@ 

              # Using this trick, libsolv will try to solve all the buildrequires/requires pairs,

              # because they are expressed as separate Solvables and we are able to distinguish

              # between them thanks to context value.

-             normalized_deps = normdeps(mmd, "get_buildrequires")

+             normalized_deps = normdeps(mmd, "peek_buildrequires")

              for c, deps in enumerate(mmd.get_dependencies()):

                  # $n:$s:$c-$v.src

                  solvable = self.build_repo.add_solvable()

@@ -383,7 +383,7 @@ 

          # Get the requires from the real "dependencies" section in MMD.

          mmd_requires = {}

          for deps in mmd.get_dependencies():

-             for name, streams in deps.get_requires().items():

+             for name, streams in deps.peek_requires().items():

                  if name not in mmd_requires:

                      mmd_requires[name] = set()

                  mmd_requires[name] = mmd_requires[name].union(streams.get())

@@ -90,7 +90,7 @@ 

                      dep_mmd = local_module.mmd()

                      for key in keys:

                          if key in dep_mmd.get_profiles().keys():

-                             results[key] |= set(dep_mmd.get_profiles()[key].get_rpms().get())

+                             results[key] |= set(dep_mmd.get_profiles()[key].peek_rpms().get())

                      continue

  

                  build = models.ModuleBuild.get_build_from_nsvc(

@@ -105,7 +105,7 @@ 

                  # Take note of what rpms are in this dep's profile

                  for key in keys:

                      if key in dep_mmd.get_profiles().keys():

-                         results[key] |= set(dep_mmd.get_profiles()[key].get_rpms().get())

+                         results[key] |= set(dep_mmd.get_profiles()[key].peek_rpms().get())

  

          # Return the union of all rpms in all profiles of the given keys

          return results

@@ -176,7 +176,7 @@ 

                  dep_mmd = local_module.mmd()

                  for key in keys:

                      if key in dep_mmd.get_profiles().keys():

-                         results[key] |= set(dep_mmd.get_profiles()[key].get_rpms().get())

+                         results[key] |= set(dep_mmd.get_profiles()[key].peek_rpms().get())

                  continue

  

              # Find the dep in the built modules in MBS

@@ -190,7 +190,7 @@ 

                  # Take note of what rpms are in this dep's profile.

                  for key in keys:

                      if key in dep_mmd.get_profiles().keys():

-                         results[key] |= set(dep_mmd.get_profiles()[key].get_rpms().get())

+                         results[key] |= set(dep_mmd.get_profiles()[key].peek_rpms().get())

  

          # Return the union of all rpms in all profiles of the given keys.

          return results

@@ -88,7 +88,8 @@ 

      @staticmethod

      def extract_modulemd(yaml, strict=False):

          try:

-             mmd = Modulemd.Module().new_from_string(yaml)

+             mmd = Modulemd.ModuleStream()

+             mmd.import_from_string(yaml)

              mmd.upgrade()

          except Exception:

              raise ValueError('Invalid modulemd')

@@ -98,7 +98,7 @@ 

      """

      for deps in mmd.get_dependencies():

          expanded = {}

-         for name, streams in deps.get_requires().items():

+         for name, streams in deps.peek_requires().items():

              streams_set = Modulemd.SimpleSet()

              streams_set.set(_expand_mse_streams(

                  session, name, streams, default_streams, raise_if_stream_ambigous))

@@ -106,7 +106,7 @@ 

          deps.set_requires(expanded)

  

          expanded = {}

-         for name, streams in deps.get_buildrequires().items():

+         for name, streams in deps.peek_buildrequires().items():

              streams_set = Modulemd.SimpleSet()

              streams_set.set(_expand_mse_streams(

                  session, name, streams, default_streams, raise_if_stream_ambigous))

@@ -164,7 +164,7 @@ 

          for mmd_list in added_mmds.values():

              for mmd in mmd_list:

                  for deps in mmd.get_dependencies():

-                     mmds = _get_mmds_from_requires(session, deps.get_requires(), mmds, True)

+                     mmds = _get_mmds_from_requires(session, deps.peek_requires(), mmds, True)

  

      return mmds

  

@@ -203,7 +203,7 @@ 

      # At first get all the buildrequires of the module of interest.

      for deps in mmd.get_dependencies():

          mmds = _get_mmds_from_requires(

-             session, deps.get_buildrequires(), mmds, False, default_streams,

+             session, deps.peek_buildrequires(), mmds, False, default_streams,

              raise_if_stream_ambigous)

  

      # Now get the requires of buildrequires recursively.

@@ -211,7 +211,7 @@ 

          for mmd in mmds[mmd_key]:

              for deps in mmd.get_dependencies():

                  mmds = _get_mmds_from_requires(

-                     session, deps.get_requires(), mmds, True, default_streams,

+                     session, deps.peek_requires(), mmds, True, default_streams,

                      raise_if_stream_ambigous)

  

      # Make single list from dict of lists.

@@ -320,8 +320,8 @@ 

          # will build this MMD against.

          new_dep = Modulemd.Dependencies()

          dep = mmd_copy.get_dependencies()[dependencies_id]

-         dep_requires = dep.get_requires()

-         dep_buildrequires = dep.get_buildrequires()

+         dep_requires = dep.peek_requires()

+         dep_buildrequires = dep.peek_buildrequires()

          for req_name, req_streams in dep_requires.items():

              if req_name not in dep_buildrequires:

                  # This require is not a buildrequire so just copy this runtime requirement to

@@ -96,14 +96,14 @@ 

          # to the specific commit available at the time of

          # submission (now).

          pkgref = module_build_service.scm.SCM(

-             pkg.get_repository()).get_latest(pkg.get_ref())

+             pkg.peek_repository()).get_latest(pkg.peek_ref())

      except Exception as e:

          log.exception(e)

          return {'error': "Failed to get the latest commit for %s#%s" % (

-             pkg.get_repository(), pkg.get_ref())}

+             pkg.peek_repository(), pkg.peek_ref())}

  

      return {

-         'pkg_name': pkg.get_name(),

+         'pkg_name': pkg.peek_name(),

          'pkg_ref': pkgref,

          'error': None

      }

@@ -156,30 +156,30 @@ 

              xmd['mbs']['rpms'] = {}

          # Add missing data in RPM components

          for pkgname, pkg in mmd.get_rpm_components().items():

-             if pkg.get_repository() and not conf.rpms_allow_repository:

+             if pkg.peek_repository() and not conf.rpms_allow_repository:

                  raise Forbidden(

                      "Custom component repositories aren't allowed.  "

-                     "%r bears repository %r" % (pkgname, pkg.get_repository()))

-             if pkg.get_cache() and not conf.rpms_allow_cache:

+                     "%r bears repository %r" % (pkgname, pkg.peek_repository()))

+             if pkg.peek_cache() and not conf.rpms_allow_cache:

                  raise Forbidden(

                      "Custom component caches aren't allowed.  "

                      "%r bears cache %r" % (pkgname, pkg.cache))

-             if not pkg.get_repository():

+             if not pkg.peek_repository():

                  pkg.set_repository(conf.rpms_default_repository + pkgname)

-             if not pkg.get_cache():

+             if not pkg.peek_cache():

                  pkg.set_cache(conf.rpms_default_cache + pkgname)

-             if not pkg.get_ref():

+             if not pkg.peek_ref():

                  pkg.set_ref('master')

  

          # Add missing data in included modules components

          for modname, mod in mmd.get_module_components().items():

-             if mod.get_repository() and not conf.modules_allow_repository:

+             if mod.peek_repository() and not conf.modules_allow_repository:

                  raise Forbidden(

                      "Custom module repositories aren't allowed.  "

-                     "%r bears repository %r" % (modname, mod.get_repository()))

-             if not mod.get_repository():

+                     "%r bears repository %r" % (modname, mod.peek_repository()))

+             if not mod.peek_repository():

                  mod.set_repository(conf.modules_default_repository + modname)

-             if not mod.get_ref():

+             if not mod.peek_ref():

                  mod.set_ref('master')

  

          # Check that SCM URL is valid and replace potential branches in pkg refs

@@ -207,10 +207,10 @@ 

  

  def validate_mmd(mmd):

      for modname, mod in mmd.get_module_components().items():

-         if mod.get_repository() and not conf.modules_allow_repository:

+         if mod.peek_repository() and not conf.modules_allow_repository:

              raise Forbidden(

                  "Custom module repositories aren't allowed.  "

-                 "%r bears repository %r" % (modname, mod.get_repository()))

+                 "%r bears repository %r" % (modname, mod.peek_repository()))

  

  

  def merge_included_mmd(mmd, included_mmd):

@@ -266,7 +266,7 @@ 

          return

  

      rpm_weights = module_build_service.builder.GenericBuilder.get_build_weights(

-         [c.get_name() for c in rpm_components])

+         [c.peek_name() for c in rpm_components])

      all_components.sort(key=lambda x: x.get_buildorder())

      # We do not start with batch = 0 here, because the first batch is

      # reserved for module-build-macros. First real components must be

@@ -284,7 +284,7 @@ 

          # set to our current batch, so the components of this module

          # are built in the right global order.

          if isinstance(component, Modulemd.ComponentModule):

-             full_url = component.get_repository() + "?#" + component.get_ref()

+             full_url = component.peek_repository() + "?#" + component.peek_ref()

              # It is OK to whitelist all URLs here, because the validity

              # of every URL have been already checked in format_mmd(...).

              included_mmd = _fetch_mmd(full_url, whitelist_url=True)[0]

@@ -292,16 +292,16 @@ 

                                              previous_buildorder, main_mmd, session=session)

              continue

  

-         component_ref = mmd.get_xmd()['mbs']['rpms'][component.get_name()]['ref']

-         full_url = component.get_repository() + "?#" + component_ref

+         component_ref = mmd.get_xmd()['mbs']['rpms'][component.peek_name()]['ref']

+         full_url = component.peek_repository() + "?#" + component_ref

          build = models.ComponentBuild(

              module_id=module.id,

-             package=component.get_name(),

+             package=component.peek_name(),

              format="rpms",

              scmurl=full_url,

              batch=batch,

              ref=component_ref,

-             weight=rpm_weights[component.get_name()]

+             weight=rpm_weights[component.peek_name()]

          )

          session.add(build)

  

file modified
+7 -7

@@ -605,11 +605,11 @@ 

                  previous_buildorder = pkg.get_buildorder()

                  batch += 1

  

-             pkgref = mmd.get_xmd()['mbs']['rpms'][pkg.get_name()]['ref']

-             full_url = pkg.get_repository() + "?#" + pkgref

+             pkgref = mmd.get_xmd()['mbs']['rpms'][pkg.peek_name()]['ref']

+             full_url = pkg.peek_repository() + "?#" + pkgref

              build = module_build_service.models.ComponentBuild(

                  module_id=2,

-                 package=pkg.get_name(),

+                 package=pkg.peek_name(),

                  format="rpms",

                  scmurl=full_url,

                  batch=batch,

@@ -649,7 +649,7 @@ 

          components2 = mmd2.get_rpm_components().values()

          # Store components to database in different order than for 570 to

          # reproduce the reusing issue.

-         components2.sort(key=lambda x: len(x.get_name()))

+         components2.sort(key=lambda x: len(x.peek_name()))

          components2.sort(key=lambda x: x.get_buildorder())

          previous_buildorder = None

          batch = 1

@@ -659,11 +659,11 @@ 

                  previous_buildorder = pkg.get_buildorder()

                  batch += 1

  

-             pkgref = mmd2.get_xmd()['mbs']['rpms'][pkg.get_name()]['ref']

-             full_url = pkg.get_repository() + "?#" + pkgref

+             pkgref = mmd2.get_xmd()['mbs']['rpms'][pkg.peek_name()]['ref']

+             full_url = pkg.peek_repository() + "?#" + pkgref

              build = module_build_service.models.ComponentBuild(

                  module_id=3,

-                 package=pkg.get_name(),

+                 package=pkg.peek_name(),

                  format="rpms",

                  scmurl=full_url,

                  batch=batch,

file modified
+14 -9

@@ -29,19 +29,24 @@ 

  BASE_DIR = os.path.dirname(__file__)

  STAGED_DATA_DIR = os.path.join(BASE_DIR, 'staged_data')

  

- _mmd = Modulemd.Module().new_from_file(

-     os.path.join(STAGED_DATA_DIR, 'platform.yaml'))

- _mmd.upgrade()

+ 

+ def load_modulemd_from_file(filename):

+     mmd = Modulemd.ModuleStream()

+     mmd.import_from_file(filename)

+     mmd.upgrade()

+     return mmd

+ 

+ 

+ modulemd_file = os.path.join(STAGED_DATA_DIR, 'platform.yaml')

+ _mmd = load_modulemd_from_file(modulemd_file)

  PLATFORM_MODULEMD = _mmd.dumps()

  

- _mmd2 = Modulemd.Module().new_from_file(

-     os.path.join(STAGED_DATA_DIR, 'formatted_testmodule.yaml'))

- _mmd2.upgrade()

+ modulemd_file = os.path.join(STAGED_DATA_DIR, 'formatted_testmodule.yaml')

+ _mmd2 = load_modulemd_from_file(modulemd_file)

  TESTMODULE_MODULEMD = _mmd2.dumps()

  

- _mmd3 = Modulemd.Module().new_from_file(

-     os.path.join(STAGED_DATA_DIR, 'formatted_testmodule.yaml'))

- _mmd3.upgrade()

+ modulemd_file = os.path.join(STAGED_DATA_DIR, 'formatted_testmodule.yaml')

+ _mmd3 = load_modulemd_from_file(modulemd_file)

  _mmd3.set_context("c2c572ed")

  TESTMODULE_MODULEMD_SECOND_CONTEXT = _mmd3.dumps()

  

@@ -71,7 +71,7 @@ 

          mmd = module.mmd()

          mmd.set_name('testmodule2')

          mmd.set_version(20180123171545)

-         requires = mmd.get_dependencies()[0].get_requires()

+         requires = mmd.get_dependencies()[0].peek_requires()

          requires['testmodule'] = Modulemd.SimpleSet()

          requires['testmodule'].add('master')

          mmd.get_dependencies()[0].set_requires(requires)

@@ -58,8 +58,8 @@ 

          module_mmds = resolver.get_module_modulemds('testmodule', 'master', '20180205135154',

                                                      '9c690d0e')

          nsvcs = set(

-             '{}:{}:{}:{}'.format(m.peek_name(), m.peek_stream(),

-                                  m.peek_version(), m.peek_context())

+             '{}:{}:{}:{}'.format(m.get_name(), m.get_stream(),

+                                  m.get_version(), m.get_context())

              for m in module_mmds

          )

          expected = set(["testmodule:master:20180205135154:9c690d0e"])

@@ -111,8 +111,8 @@ 

          resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='mbs')

          ret = resolver.get_module_modulemds('testmodule', 'master', version)

          nsvcs = set(

-             '{}:{}:{}:{}'.format(m.peek_name(), m.peek_stream(),

-                                  m.peek_version(), m.peek_context())

+             '{}:{}:{}:{}'.format(m.get_name(), m.get_stream(),

+                                  m.get_version(), m.get_context())

              for m in ret

          )

          expected = set(["testmodule:master:20180205135154:9c690d0e",

@@ -312,9 +312,9 @@ 

          module_build_service.utils.format_mmd(mmd, scmurl)

  

          # Make sure that original refs are not changed.

-         mmd_pkg_refs = [pkg.get_ref() for pkg in mmd.get_rpm_components().values()]

+         mmd_pkg_refs = [pkg.peek_ref() for pkg in mmd.get_rpm_components().values()]

          assert set(mmd_pkg_refs) == set(hashes_returned.keys())

-         br = mmd.get_dependencies()[0].get_buildrequires()

+         br = mmd.get_dependencies()[0].peek_buildrequires()

          assert br.keys() == ['platform']

          assert br.values()[0].get() == ['f28']

          xmd = {

@@ -270,7 +270,7 @@ 

  

              buildrequires = set()

              dep = mmd.get_dependencies()[0]

-             for req_name, req_streams in dep.get_buildrequires().items():

+             for req_name, req_streams in dep.peek_buildrequires().items():

                  for req_stream in req_streams.get():

                      buildrequires.add(":".join([req_name, req_stream]))

              buildrequires_per_mmd_buildrequires.add(frozenset(buildrequires))

@@ -322,7 +322,7 @@ 

              assert len(mmd.get_dependencies()) == 1

              mmd_requires = set()

              dep = mmd.get_dependencies()[0]

-             for req_name, req_streams in dep.get_requires().items():

+             for req_name, req_streams in dep.peek_requires().items():

                  for req_stream in req_streams.get():

                      mmd_requires.add(":".join([req_name, req_stream]))

              requires_per_mmd.add(frozenset(mmd_requires))

Signed-off-by: Chenxiong Qi cqi@redhat.com

Some get_* methods are deprecated and corresponding peek_* methods are recommended to call. All these deprecation warnings are printed after running tests.

@sgallagh Does peek act any differently than get? Does peek return a copy or the actual object in memory like get does?

@mprahl peek() was meant to be more explicit. Anywhere that you see peek(), it is the actual object in memory.

I should warn you that this will be changing again in API 2.0 because I got the wrong impression from GNOME guys about the convention. In 2.0, anything that is explicitly get_foo() will have the semantics of peek(). In 2.0, I will also not be offering .dup(); it will be expected that users can take a reference or make a copy on their own.

Sorry about all of the churn. There's a lot of this API that is terrible which is why I'm preparing a total rewrite of it. I will be sending the proposal out hopefully on Monday with the new design which should be FAR more usable than this current mess... (I'll be building libmodulemd with support for both APIs, so you can migrate at leisure).

@sgallagh Thanks for the info.

I'll close this pr for now.

Pull-Request has been closed by cqi

7 months ago