Skip to content

Commit

Permalink
feat(config): add core.check_updates configuration
Browse files Browse the repository at this point in the history
This option is disabled in tests through new Config.overrides variable
  • Loading branch information
Toilal committed Feb 9, 2021
1 parent 28d9126 commit 3a779a4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ddb/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class Config: # pylint:disable=too-many-instance-attributes
"""
Configuration
"""
# Static default values for configuration, can be modified from code mainly for tests purpose
# Static default/overrides values for configuration, can be modified from code mainly for tests purpose
defaults = None
overrides = lambda config: config

def __init__(self,
paths: Union[ConfigPaths, None] = None,
Expand Down Expand Up @@ -168,6 +169,9 @@ def read(self, defaults=None, files=None):
if file_data:
loaded_data = config_merger.merge(loaded_data, file_data)

if Config.overrides: # pylint:disable=using-constant-test
Config.overrides(loaded_data)

return self.apply_environ_overrides(loaded_data), found_files

def load_from_data(self, data: Dict):
Expand Down
2 changes: 1 addition & 1 deletion ddb/feature/core/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def execute(command: Command):
:param command command name
:return:
"""
if not command.avoid_stdout:
if not command.avoid_stdout and config.data.get('core.check_updates'):
cache = caches.get('core.check_for_update.version')
last_check = cache.get('last_check', None)
today = date.today()
Expand Down
1 change: 1 addition & 0 deletions ddb/feature/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ class CoreFeatureSchema(FeatureSchema):
process = fields.Dict(fields.String(), fields.Nested(ProcessSchema()), default={}) # Process binary mappings
configuration = fields.Nested(ConfigurationSchema(), default=ConfigurationSchema())
github_repository = fields.String(required=True, default="inetum-orleans/docker-devbox-ddb")
check_updates = fields.Boolean(required=True, default=True)
required_version = fields.String(required=False, allow_none=True, default=None)
1 change: 1 addition & 0 deletions docs/features/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ It also handle the two following basic commands : `ddb features` and `ddb config
| :---------: | :----: | :----------- |
| `env.available` | string[]<br>`['prod', 'stage', 'ci', 'dev']` | List of available environments. You should any new custom environment to support here before trying to set `env.current` to this custom environment.|
| `required_version` | string | Minimal required `ddb` version for the project to work properly. If `required_version` is greater than the currently running one, ddb will refuse to run until it's updated. |
| `check_updates` | boolean<br>`true` | Should check for ddb updates be enabled ? |
| `path.ddb_home` | string<br>`${env:HOME}/.docker-devbox/ddb` | The path where ddb is installed. |
| `path.home` | string<br>`${env:HOME}/.docker-devbox` | The path where docker devbox is installed. |
| `path.project_home` | string | The project directory. |
Expand Down
2 changes: 2 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_defaults():

def test_load_and_clear(data_dir):
Config.defaults = None
Config.overrides = None

ddb_home, home, project = os.path.join(data_dir, 'load', 'ddb_home'), \
os.path.join(data_dir, 'load', 'home'), \
Expand All @@ -35,6 +36,7 @@ def test_load_and_clear(data_dir):

def test_load_with_env_overrides(data_dir):
Config.defaults = None
Config.overrides = None

ddb_home, home, project = os.path.join(data_dir, 'load', 'ddb_home'), \
os.path.join(data_dir, 'load', 'home'), \
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pytest_mock import MockerFixture
from verboselogs import SPAM

from .utilstest import init_config_paths, load_config
from .utilstest import init_config_paths

pytest_plugins = ["docker_compose"]

Expand Down Expand Up @@ -65,6 +65,13 @@ def configure(mocker: MockerFixture):

Config.defaults = {'defaults': {'fail_fast': True}}

def overrides(config):
if not 'core' in config:
config['core'] = {}
config.get('core')['check_updates'] = False

Config.overrides = overrides

try:
if os.name == 'nt' and 'COMSPEC' not in os.environ:
os.environ['COMSPEC'] = r'C:\Windows\System32\cmd.exe'
Expand Down

0 comments on commit 3a779a4

Please sign in to comment.