#193 Add buildroot override for libuv
Merged 4 years ago by mohanboddu. Opened 4 years ago by sgallagh.
releng/ sgallagh/fedora-module-defaults el8  into  el8

file added
+2
@@ -0,0 +1,2 @@ 

+ *~

+ .idea

file modified
-1
@@ -7,6 +7,5 @@ 

          make \

          python3-six \

          python3-libmodulemd \

-         python3-libmodulemd1 \

          python3-GitPython \

      && dnf -y clean all

@@ -0,0 +1,8 @@ 

+ document: modulemd-defaults

+ version: 1

+ data:

+   module: libuv

+   stream:  epel8-buildroot

+   modified: 202002241511

+   profiles:

+     epel8-buildroot: []

file modified
+34 -20
@@ -6,36 +6,41 @@ 

  import sys

  

  from gi.repository import GLib

- gi.require_version('Modulemd', '2.0')

+ 

+ gi.require_version("Modulemd", "2.0")

  from gi.repository import Modulemd

  

+ 

  def print_failure(failure):

      print("Error: %s" % failure.get_gerror())

      print("Offending YAML: \n%s" % failure.get_yaml())

  

+ 

  def unusable_baseline():

      print("Baseline was unusable. Skipping test.")

      return os.EX_OK

  

- def get_index_and_defaults (repo, filename, commit):

+ 

+ def get_index_and_defaults(repo, filename, commit):

      try:

-         yaml = repo.git.show('%s:%s' % (commit, filename))

+         yaml = repo.git.show("%s:%s" % (commit, filename))

      except git.exc.GitCommandError as e:

          # This file didn't exist in the commit, so return

          # FileNotFoundError to skip checking it.

-         raise FileNotFoundError("{} does not exist at commit {}".format(filename, commit))

- 

+         raise FileNotFoundError(

+             "{} does not exist at commit {}".format(filename, commit)

+         )

  

      index = Modulemd.ModuleIndex.new()

      try:

          ret, failures = index.update_from_string(yaml, True)

          if ret != True:

              for failure in failures:

-                 print_failure (failure)

+                 print_failure(failure)

              raise IOError("Invalid modulemd-defaults document")

  

      except gi.repository.GLib.Error as e:

-         print ("Error: %s" % e)

+         print("Error: %s" % e)

          raise IOError("Invalid YAML document")

  

      module_names = index.get_module_names()
@@ -50,6 +55,7 @@ 

  

      return index, defaults

  

+ 

  def main():

      filename = sys.argv[1]

      baseline_commit = sys.argv[2]
@@ -57,13 +63,13 @@ 

  

      script_dir = os.path.dirname(os.path.realpath(__file__))

  

-     repo = git.Repo(script_dir,

-                     search_parent_directories=True)

+     repo = git.Repo(script_dir, search_parent_directories=True)

  

      # First get the defaults from the baseline commit

      try:

-         baseline_index, baseline_defaults = get_index_and_defaults (

-             repo, filename, baseline_commit)

+         baseline_index, baseline_defaults = get_index_and_defaults(

+             repo, filename, baseline_commit

+         )

      except FileNotFoundError as e:

          # The baseline file didn't exist, so there's no valid original

          # to compare to. Check it only with validate.py.
@@ -78,11 +84,17 @@ 

  

      try:

          updated_commit = updated_commit

-         updated_index, updated_defaults = get_index_and_defaults (

-             repo, filename, updated_commit)

+         updated_index, updated_defaults = get_index_and_defaults(

+             repo, filename, updated_commit

+         )

      except FileNotFoundError as e:

          # The PR is removing this file. Assume that this is acceptable

-         print("{} is being removed. Not performing any comparison tests.".format(filename), file=sys.stderr)

+         print(

+             "{} is being removed. Not performing any comparison tests.".format(

+                 filename

+             ),

+             file=sys.stderr,

+         )

          return os.EX_OK

      except IOError as e:

          # If we hit this, the patch is broken.
@@ -90,10 +102,12 @@ 

          return os.EX_DATAERR

  

      if updated_defaults.get_modified() <= baseline_defaults.get_modified():

-         print ("%s has changed but the 'modified' field has not increased." %

-                filename)

-         print ("Baseline modified: {}".format(baseline_defaults.get_modified()))

-         print ("Updated modified: {}".format(updated_defaults.get_modified()))

+         print(

+             "%s has changed but the 'modified' field has not increased."

+             % filename

+         )

+         print("Baseline modified: {}".format(baseline_defaults.get_modified()))

+         print("Updated modified: {}".format(updated_defaults.get_modified()))

          return os.EX_DATAERR

  

      # Confirm that these two sets of defaults merge cleanly
@@ -104,11 +118,11 @@ 

      try:

          merger.resolve()

      except gi.repository.GLib.Error as e:

-         print ("Merge Error: %s" % e, file=sys.stderr)

+         print("Merge Error: %s" % e, file=sys.stderr)

          return os.EX_DATAERR

  

      return os.EX_OK

  

+ 

  if __name__ == "__main__":

      sys.exit(main())

- 

file modified
+2
@@ -10,6 +10,7 @@ 

  

  # Skip any .gitignore files

  overrides/.gitignore

+ .gitignore

  

  # Skip the validator files

  tests/common_tests.sh
@@ -24,4 +25,5 @@ 

  tests/intents.yaml

  tests/missingstream.yaml

  tests/module.yaml

+ tests/modulewithnames.yaml

  tests/nodejs.yaml

@@ -0,0 +1,53 @@ 

+ ---

+ document: modulemd

+ version: 2

+ data:

+   name: nodejs

+   stream: testing

+   summary: Javascript runtime

+   description: >-

+     Node.js is a platform built on Chrome''s JavaScript runtime for easily building

+     fast, scalable network applications. Node.js uses an event-driven, non-blocking

+     I/O model that makes it lightweight and efficient, perfect for data-intensive

+     real-time applications that run across distributed devices.

+   license:

+     module:

+     - MIT

+   dependencies:

+   - buildrequires:

+       platform: []

+     requires:

+       platform: []

+   references:

+     community: http://nodejs.org

+     documentation: http://nodejs.org/en/docs

+     tracker: https://github.com/nodejs/node/issues

+   profiles:

+     default:

+       rpms:

+       - nodejs

+       - npm

+     development:

+       rpms:

+       - nodejs

+       - nodejs-devel

+       - npm

+     minimal:

+       rpms:

+       - nodejs

+   api:

+     rpms:

+     - nodejs

+     - nodejs-devel

+     - npm

+   components:

+     rpms:

+       libuv:

+         rationale: Platform abstraction layer for Node.js

+         ref: 1.20

+         buildorder: 0

+       nodejs:

+         rationale: Javascript runtime and npm package manager.

+         ref: 10

+         buildorder: 10

+ ...

file modified
+93 -56
@@ -5,77 +5,94 @@ 

  import git

  import os

  import sys

+ import logging

+ from logging import error, info

  

  from gi.repository import GLib

- gi.require_version('Modulemd', '1.0')

- from gi.repository import Modulemd

+ 

+ gi.require_version("Modulemd", "2.0")

+ from gi.repository import Modulemd  # noqa

+ 

+ logging.getLogger().setLevel(logging.INFO)

+ 

  

  def do_validate(filename):

      # Valid filenames must end in ".yaml" to be properly included by Pungi

      if not filename.endswith(".yaml"):

-         print("%s does not end with .yaml. It will not be included by "

-               "Pungi. If this file does not contain defaults, it should "

-               "be added to the tests/exclusions.txt file." % filename,

-               file=sys.stderr,)

+         error(

+             "{} does not end with .yaml. It will not be included by "

+             "Pungi. If this file does not contain defaults, it should "

+             "be added to the tests/exclusions.txt file.".format(filename)

+         )

          return False, None

  

      # The files must parse correctly

+     idx = Modulemd.ModuleIndex()

      try:

-         (objects, failures) = Modulemd.objects_from_file_ext(filename)

+         (objects, failures) = idx.update_from_file(filename, True)

      except GLib.Error as e:

-         print(e.message, file=sys.stderr)

+         error("{}".format(e.message))

          return False, None

  

-     if (failures):

+     if failures:

          for failure in failures:

-             print("Failed subdocument (%s): \n%s\n", failure.message,

-                   failure.doc, file=sys.stderr)

+             error(

+                 "Failed subdocument ({}): \n{}\n".format(

+                     failure.get_gerror().message, failure.get_yaml()

+                 )

+             )

          return False, None

  

      # There must be exactly one object per file

-     if len(objects) != 1:

-         print("There must be exactly one subdocument", file=sys.stderr)

+     names = idx.get_module_names()

+     if len(names) != 1:

+         error("There must be exactly one module represented by this file")

          return False, None

  

      # The files must have exactly one Modulemd.Defaults object

-     try:

-         (default, def_failures) = \

-             Modulemd.Defaults.new_from_file_ext (filename)

-     except GLib.Error as e:

-         print(e.message, file=sys.stderr)

+     module = idx.get_module(names[0])

+     defaults = module.get_defaults()

+ 

+     if defaults is None:

+         error(

+             "No defaults document provided for {}".format(

+                 module.props.module_name

+             )

+         )

          return False, None

  

-     # Filenames must match their contents

-     expected_name = os.path.basename(filename).rsplit('.', maxsplit=1)[0]

+     # The files must not contain any streams

+     if len(module.get_stream_names()) != 0:

+         error("File included a stream document.")

+         return False, None

  

-     if expected_name != default.props.module_name:

-         print("Module name \"%s\" doesn't match filename \"%s.yaml\"" % (

-               default.props.module_name, expected_name),

-               file=sys.stderr)

+     # Filenames must match their contents

+     expected_name = os.path.basename(filename).rsplit(".", maxsplit=1)[0]

+ 

+     if expected_name != defaults.props.module_name:

+         error(

+             'Module name "{}" doesn\'t match filename "{}.yaml"'.format(

+                 defaults.props.module_name, expected_name

+             )

+         )

          return False, None

  

-     if default.props.default_stream:

+     default_stream = defaults.get_default_stream()

+     if default_stream:

          # Default streams must also appear in the profiles list

-         if not default.props.default_stream in default.props.profile_defaults:

-             print("Stream '%s' missing from profiles" % (

-                   default.props.default_stream),

-                   file=sys.stderr)

+         if defaults.get_default_profiles_for_stream(default_stream) is None:

+             error(

+                 "Stream '{}' is missing from the profiles for '{}'".format(

+                     default_stream, defaults.get_module_name()

+                 )

+             )

              return False, None

  

      # Modules in Fedora must not specify "Intents"

-     try:

-         if (default.props.intents):

-             print ('Module name "%s" includes the intents section, which is '

-                    'not currently permitted in Fedora.' % (

-                        default.props.module_name),

-                    file=sys.stderr)

-             return False, None

-     except AttributeError:

-         # The available version of libmodulemd does not support intents

-         pass

+     # TODO: This needs a new interface exposed in libmodulemd v2

  

-     print("%s is valid" % filename)

-     return (True, default)

+     info("{} is valid".format(filename))

+     return (True, idx)

  

  

  def main():
@@ -85,10 +102,11 @@ 

          script_dir = os.path.abspath(sys.argv[1])

      else:

          script_dir = os.path.dirname(os.path.realpath(__file__))

+     defaults_dir = os.path.abspath(os.path.join(script_dir, '..'))

+     overrides_dir = os.path.join(defaults_dir, 'overrides')

  

      # Get the repo we're running in

-     repo = git.Repo(script_dir,

-                     search_parent_directories=True)

+     repo = git.Repo(defaults_dir, search_parent_directories=True)

  

      # Get the list of files in this repository

      files = [x for (x, y) in repo.index.entries.keys()]
@@ -104,25 +122,17 @@ 

              exclusions.append(line.strip())

  

      # Validate all of the files

-     prioritizer = Modulemd.Prioritizer()

      for file in files:

          excluded = False

          for excl in exclusions:

-             if (file.startswith(excl)):

+             if file.startswith(excl):

                  excluded = True

                  break

          if not excluded:

-             (valid, obj) = do_validate(file)

+             (valid, idx) = do_validate(file)

              if not valid:

-                 print("%s failed to validate" % file, file=sys.stderr)

+                 error("{} failed to validate".format(file))

                  result = os.EX_DATAERR

-             else:

-                 try:

-                     prioritizer.add([obj,], 0)

-                 except GLib.Error as e:

-                     print("Could not merge %s with other defaults: %s" % (

-                           file, e.message))

-                     result = os.EX_DATAERR

  

      if result == os.EX_DATAERR:

          return result
@@ -131,13 +141,40 @@ 

      # conflicts arise that weren't detected by the above tests. This should be

      # impossible.

      try:

-         prioritizer.resolve()

+         idx = Modulemd.ModuleIndex()

+         idx.update_from_defaults_directory(path=defaults_dir,

+                                            strict=True)

      except GLib.Error as e:

-         print("Could not merge all defaults: %s" % e.message)

+         error("Could not merge all defaults: {}".format(e.message))

          result = os.EX_DATAERR

  

+     if result == os.EX_OK:

+         info("Merging all of the documents encountered no errors.")

+ 

+     print("\nDefault streams (Runtime):")

+     print("================")

+     for m, s in idx.get_default_streams().items():

+         print("{}:{}".format(m, s))

+ 

+     try:

+         idx = Modulemd.ModuleIndex()

+         idx.update_from_defaults_directory(path=defaults_dir,

+                                            overrides_path=overrides_dir,

+                                            strict=True)

+     except GLib.Error as e:

+         error("Could not merge all defaults: {}".format(e.message))

+         result = os.EX_DATAERR

+ 

+     if result == os.EX_OK:

+         info("Merging all of the documents encountered no errors.")

+ 

+     print("\nDefault streams (Buildroot):")

+     print("================")

+     for m, s in idx.get_default_streams().items():

+         print("{}:{}".format(m, s))

  

      return result

  

+ 

  if __name__ == "__main__":

      sys.exit(main())

Should fix BZ #1759510

Signed-off-by: Stephen Gallagher sgallagh@redhat.com

pretty please pagure-ci rebuild

4 years ago

rebased onto 01aec00

4 years ago

5 new commits added

  • Add buildroot override for libuv
  • Test and display both runtime and buildroot defaults
  • Test defaults and overrides with .update_from_defaults_directory()
  • Reformat python code with black
  • Convert remaining tests to libmodulemd v2
4 years ago

5 new commits added

  • Add buildroot override for libuv
  • Test and display both runtime and buildroot defaults
  • Test defaults and overrides with .update_from_defaults_directory()
  • Reformat python code with black
  • Convert remaining tests to libmodulemd v2
4 years ago

Added several backported test fixes.

6 new commits added

  • Add buildroot override for libuv
  • Fix tests for no default profile for the default stream
  • Test and display both runtime and buildroot defaults
  • Test defaults and overrides with .update_from_defaults_directory()
  • Reformat python code with black
  • Convert remaining tests to libmodulemd v2
4 years ago

OK, this is passing now.

Pull-Request has been merged by mohanboddu

4 years ago