#3039 mock.module_setup_commands tag extra option
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue2483  into  master

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

                      'opts': self.config['extra']['mock.plugin_conf.sign_opts.opts'],

                  }

              }

+         if 'mock.module_setup_commands' in self.config['extra']:

+             opts['module_setup_commands'] = self.config['extra']['mock.module_setup_commands']

          if self.internal_dev_setup is not None:

              opts['internal_dev_setup'] = bool(self.internal_dev_setup)

          opts['tag_macros'] = {}

file modified
+6 -3
@@ -1147,6 +1147,8 @@ 

          opts['bootstrap_image'] = buildcfg['extra']['mock.bootstrap_image']

      if 'mock.use_bootstrap' in buildcfg['extra']:

          opts['use_bootstrap'] = buildcfg['extra']['mock.use_bootstrap']

+     if 'mock.module_setup_commands' in buildcfg['extra']:

+         opts['module_setup_commands'] = buildcfg['extra']['mock.module_setup_commands']

      opts['tag_macros'] = {}

      for key in buildcfg['extra']:

          if key.startswith('rpm.macro.'):
@@ -5305,7 +5307,7 @@ 

      parser.add_option("--no-include-all", action="store_true",

                        help="Do not include all packages in this tag when generating Maven repos")

      parser.add_option("-x", "--extra", action="append", default=[], metavar="key=value",

-                       help="Set tag extra option")

+                       help="Set tag extra option. JSON-encoded or simple value")

      parser.add_option("-r", "--remove-extra", action="append", default=[], metavar="key",

                        help="Remove tag extra option")

      parser.add_option("-b", "--block-extra", action="append", default=[], metavar="key",
@@ -5340,8 +5342,9 @@ 

          extra = {}

          for xopt in options.extra:

              key, value = xopt.split('=', 1)

-             value = arg_filter(value)

-             extra[key] = value

+             if key in extra:

+                 parser.error("Duplicate extra key: %s" % key)

+             extra[key] = arg_filter(value, parse_json=True)

          opts['extra'] = extra

      opts['remove_extra'] = options.remove_extra

      opts['block_extra'] = options.block_extra

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

  from __future__ import absolute_import, division

  

  import hashlib

+ import json

  import optparse

  import os

  import random
@@ -9,7 +10,6 @@ 

  import string

  import sys

  import time

- import json

  from contextlib import closing

  from copy import copy

  
@@ -86,7 +86,7 @@ 

            'False': False}

  

  

- def arg_filter(arg):

+ def arg_filter(arg, parse_json=False):

      try:

          return int(arg)

      except ValueError:
@@ -98,6 +98,11 @@ 

      if arg in ARGMAP:

          return ARGMAP[arg]

      # handle lists/dicts?

+     if parse_json:

+         try:

+             return json.loads(arg)

+         except Exception:  # ValueError < 2.7, JSONDecodeError > 3.5

+             pass

      return arg

  

  

@@ -321,7 +321,7 @@ 

      cancel-task          Cancel a task

      help                 List available commands

      latest-build         Print the latest builds for a tag

-     [...] 

+     [...]

  

  ::

  
@@ -335,7 +335,7 @@ 

      --skip-tag            Do not attempt to tag package

      --scratch             Perform a scratch build

      --nowait              Don't wait on build

-     [...] 

+     [...]

  

  Using koji to generate a mock config to replicate a buildroot

  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -428,6 +428,11 @@ 

  

    - this option will automatically turn ``mock.use_bootstrap`` (this is how

      it is implemented in mock)

+ * ``mock.module_setup_commands`` - commands for configuring the modules active

+   in a buildroot. Available in `mock 2.4

+   <https://github.com/rpm-software-management/mock/wiki/Release-Notes-2.4>`__.

+ * ``mock.yum.best`` - 0/1 value. If set yum/dnf will use highest available rpm

+   version (see man yum.conf)

  * ``mock.yum.module_hotfixes`` - 0/1 value. If set, yum/dnf will use packages

    regardless if they come from modularity repo or not. It makes sense only for

    tags with external repositories. (See dnf `docs

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

          config_opts['bootstrap_image'] = opts['bootstrap_image']

      if 'use_bootstrap' in opts:

          config_opts['use_bootstrap'] = bool(opts['use_bootstrap'])

+     if 'module_setup_commands' in opts:

+         config_opts['module_setup_commands'] = opts['module_setup_commands']

  

      # bind_opts are used to mount parts (or all of) /dev if needed.

      # See kojid::LiveCDTask for a look at this option in action.

@@ -0,0 +1,19 @@ 

+ import unittest

+ 

+ from koji_cli.lib import arg_filter

+ 

+ class TestArgFilter(unittest.TestCase):

+     def test_valid_values(self):

+         for parse_json in (True, False):

+             self.assertEqual(arg_filter("1", parse_json=parse_json), 1)

+             self.assertEqual(arg_filter("1.123", parse_json=parse_json), 1.123)

+             self.assertEqual(arg_filter("True", parse_json=parse_json), True)

+             self.assertEqual(arg_filter("False", parse_json=parse_json), False)

+             self.assertEqual(arg_filter("None", parse_json=parse_json), None)

+ 

+         # non/json

+         self.assertEqual(arg_filter('{"a": 1}'), '{"a": 1}')

+         self.assertDictEqual(arg_filter('{"a": 1}', parse_json=True), {"a": 1})

+ 

+         # invalid json

+         self.assertEqual(arg_filter("{'a': 1}", parse_json=True), "{'a': 1}")

@@ -130,7 +130,7 @@ 

    --no-include-all      Do not include all packages in this tag when

                          generating Maven repos

    -x key=value, --extra=key=value

-                         Set tag extra option

+                         Set tag extra option. JSON-encoded or simple value

    -r key, --remove-extra=key

                          Remove tag extra option

    -b key, --block-extra=key

rebased onto 0c1c04a82fbc68a5f540e705d50de2cc3b80a0c6

2 years ago

Would this work with side-tags too?

1 new commit added

  • fix docs typo
2 years ago

Would this work with side-tags too?

Yes, sidetags don't differ on this level.

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @jcupova:
- Pull-request untagged with: testing-ready

2 years ago

rebased onto 6b7fd0c46726de2cef5f12e78f74bcb5d2d2173d

2 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-ready

2 years ago

rebased onto 1b4bdfd

2 years ago

The rebases in this PR have masked notable fixes to the PR:

  • added code in kojid to actually handle mock.module_setup_commands extra setting
  • dropped duplicate import json in cli/koji_cli/lib.py

breadcrumb: the docs changes also include missing doc for #2318

Commit d5a8f5c fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago

Metadata Update from @mfilip:
- Pull-request tagged with: testing-done

2 years ago