Skip to content

Commit

Permalink
Merge pull request #76 from acsone/drop-kaptan
Browse files Browse the repository at this point in the history
Drop support for other configuration file formats than yaml
  • Loading branch information
sbidoul authored Jul 22, 2023
2 parents 319a937 + 6ab5170 commit 0491848
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ To work around API limitation, you must first generate a
Changes
=======

4.0 (2023-07-22)
----------------

* [BREAKING] drop support for other configuration file formats than yaml
* Ensure git pull is always done in fast-forward mode

3.0.1 (2022-09-21)
Expand Down
16 changes: 12 additions & 4 deletions git_aggregator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
from string import Template

import kaptan
import yaml

from .exception import ConfigException
from ._compat import string_types

Expand Down Expand Up @@ -148,7 +149,11 @@ def load_config(config, expand_env=False, env_file=None, force=False):
raise ConfigException('Unable to find configuration file: %s' % config)

file_extension = os.path.splitext(config)[1][1:]
conf = kaptan.Kaptan(handler=kaptan.HANDLER_EXT.get(file_extension))
if file_extension not in ("yaml", "yml"):
raise ConfigException(
"Only .yaml and .yml configuration files are supported "
"(got %s)" % file_extension
)

if expand_env:
environment = {}
Expand All @@ -165,6 +170,9 @@ def load_config(config, expand_env=False, env_file=None, force=False):
with open(config, 'r') as file_handler:
config = Template(file_handler.read())
config = config.substitute(environment)
else:
config = open(config, 'r').read()

conf = yaml.load(config, Loader=yaml.SafeLoader)

conf.import_config(config)
return get_repos(conf.export('dict') or {}, force)
return get_repos(conf or {}, force)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'setuptools_scm',
],
install_requires=[
'kaptan',
'PyYAML>=5',
'argcomplete',
'colorama',
'requests',
Expand Down
7 changes: 3 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import os
import tempfile
import unittest
import kaptan
from textwrap import dedent

import yaml

from git_aggregator import config
from git_aggregator.exception import ConfigException
from git_aggregator._compat import PY2
Expand All @@ -15,9 +16,7 @@
class TestConfig(unittest.TestCase):

def _parse_config(self, config_str):
conf = kaptan.Kaptan(handler='yaml')
conf.import_config(config_str)
return conf.export('dict')
return yaml.load(config_str, Loader=yaml.SafeLoader)

def test_load(self):
config_yaml = """
Expand Down

0 comments on commit 0491848

Please sign in to comment.