Skip to content

Commit 402e659

Browse files
committed
config: per-repo configuration support
Resolves: #89 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent a096c08 commit 402e659

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/pkgdev/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from snakeoil.contexts import patch
1111
from snakeoil.klass import jit_attr_none
1212
from snakeoil.mappings import OrderedSet
13+
from pkgcore.repository import errors as repo_errors
14+
from pkgcore.util.commandline import _mk_domain
1315

1416
from . import const
1517

@@ -113,6 +115,7 @@ def __init__(self, parents=(), **kwargs):
113115
It's also possible to disable all types of settings loading by
114116
specifying an argument of 'false' or 'no'.
115117
""")
118+
_mk_domain(config_options)
116119
super().__init__(parents=[*parents, self.config_argparser], **kwargs)
117120

118121
def parse_known_args(self, args=None, namespace=None):
@@ -131,5 +134,13 @@ def parse_known_args(self, args=None, namespace=None):
131134
namespace = config_parser.parse_config_options(
132135
namespace, configs=(namespace.config_file, ))
133136

137+
try:
138+
repo = temp_namespace.domain.find_repo(
139+
os.getcwd(), config=temp_namespace.config, configure=False)
140+
if repo is not None:
141+
namespace = config_parser.parse_config_sections(namespace, repo.aliases)
142+
except (repo_errors.InitializationError, IOError) as exc:
143+
self.error(str(exc))
144+
134145
# parse command line args to override config defaults
135146
return super().parse_known_args(args, namespace)

src/pkgdev/scripts/pkgdev_manifest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def _restrict_targets(repo, targets):
6767
if os.path.exists(target):
6868
try:
6969
restrictions.append(repo.path_restrict(target))
70-
except ValueError as e:
71-
manifest.error(e)
70+
except ValueError as exc:
71+
manifest.error(exc)
7272
else:
7373
try:
7474
restrictions.append(parse_match(target))

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
@pytest.fixture(scope="session")
1010
def tool():
1111
"""Generate a tool utility for running pkgdev."""
12-
tool = Tool(pkgdev.argparser)
13-
return tool
12+
return Tool(pkgdev.argparser)
1413

1514

1615
@pytest.fixture

tests/scripts/test_pkgdev_commit.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,28 @@ def test_config_opts(self, capsys, repo, make_git_repo, tmp_path):
996996
assert not err
997997
assert 'MissingLicense' in out
998998

999+
def test_config_repo_opts(self, capsys, repo, make_git_repo, tmp_path):
1000+
config_file = str(tmp_path / 'config')
1001+
with open(config_file, 'w') as f:
1002+
f.write(textwrap.dedent("""
1003+
[fake]
1004+
commit.scan=
1005+
"""))
1006+
1007+
git_repo = make_git_repo(repo.location)
1008+
repo.create_ebuild('cat/pkg-0')
1009+
git_repo.add_all('cat/pkg-0')
1010+
repo.create_ebuild('cat/pkg-1', license='')
1011+
git_repo.add_all('cat/pkg-1', commit=False)
1012+
with patch('sys.argv', ['pkgdev', 'commit', '--config', config_file] + self.scan_args), \
1013+
pytest.raises(SystemExit) as excinfo, \
1014+
chdir(git_repo.path):
1015+
self.script()
1016+
out, err = capsys.readouterr()
1017+
assert excinfo.value.code == 1
1018+
assert not err
1019+
assert 'MissingLicense' in out
1020+
9991021
def test_failed_manifest(self, capsys, repo, make_git_repo):
10001022
git_repo = make_git_repo(repo.location)
10011023
repo.create_ebuild('cat/pkg-0')

0 commit comments

Comments
 (0)