Skip to content

Commit

Permalink
bugfixes from pair programming
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Jan 25, 2024
1 parent ad25fb3 commit 09f654a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 197 deletions.
186 changes: 0 additions & 186 deletions makim.yaml

This file was deleted.

23 changes: 15 additions & 8 deletions src/sugar/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
self._load_config()
self._load_env()
self._load_defaults()
self._load_root_services()
self._verify_args()
self._load_compose_app()
self._load_compose_args()
Expand Down Expand Up @@ -120,12 +121,16 @@ def _check_config_file(self):

# Check if services item is given
def _check_services_item(self):
return bool(self.config.get('services'))
return hasattr(self.config, 'services')

# set default group main
def _set_default_group(self):
def _set_default_group(self) -> None:
# must set the default group
services = self.config.get('services', {})

if not services:
return

self.config['groups'] = {
'main': {
'project-name': services.get('project-name'),
Expand All @@ -138,7 +143,7 @@ def _set_default_group(self):
}
}
self.defaults['group'] = 'main'
self.config_group = self.config['groups']['main']
self.service_group = deepcopy(self.config['groups']['main'])
del self.config['services']

def _filter_service_group(self):
Expand Down Expand Up @@ -195,19 +200,21 @@ def _load_config(self):
# check if either services or groups are present
if not (self.config.get('services') or self.config.get('groups')):
KxgrLogs.raise_error(
'either `services` OR `groups` flag must be given',
'Either `services` OR `groups` flag must be given',
KxgrErrorType.KXGR_INVALID_CONFIGURATION,
)
# check if both services and groups are present
if self.config.get('services') and self.config.get('groups'):
KxgrLogs.raise_error(
'`services` and `groups` flag given, only 1 is allowed.',
'`services` and `groups` flags given, only 1 is allowed.',
KxgrErrorType.KXGR_INVALID_CONFIGURATION,
)

def _load_root_services(self) -> None:
"""Load services attribute in the root of the configuration."""
if self.config.get('services'):
self._set_default_group()

self._filter_service_group()
# self._filter_service_group()

def _load_compose_app(self):
compose_cmd = self.config.get('compose-app', '')
Expand All @@ -226,7 +233,7 @@ def _load_compose_app(self):
def _load_compose_args(self):
self._filter_service_group()

if 'env-file' in self.service_group:
if self.service_group.get('env-file'):
self.compose_args.extend(
['--env-file', self.service_group['env-file']]
)
Expand Down
3 changes: 0 additions & 3 deletions tests/containers/.services.sugar.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
version: 1.0
compose-app: docker compose
env-file: .env
defaults:
group: {{ env.KXGR_GROUP }}
project-name: sugar-{{ env.KXGR_PROJECT_NAME }}
services:
project-name: project1 # optional
compose-path: tests/containers/group1/compose.yaml
env-file: .env
default: service1-1,service1-3
available:
- name: service1-1
Expand Down

0 comments on commit 09f654a

Please sign in to comment.