Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed NEPTUNE_ENABLED flag #43

Merged
merged 8 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## [UNRELEASED] kedro-neptune 0.1.2

### Fixes
- Fixed custom run id generation on catalog creation ([#42](https://github.com/neptune-ai/kedro-neptune/pull/42))
- Fixed custom run id generation on catalog creation ([#42](https://github.com/neptune-ai/kedro-neptune/pull/42))
- Fixed parsing of `NEPTUNE_ENABLED` flag ([#43](https://github.com/neptune-ai/kedro-neptune/pull/43))

## kedro-neptune 0.1.1

Expand Down
2 changes: 1 addition & 1 deletion examples/planets/conf/base/neptune.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ neptune:
#GLOBAL CONFIG
project: $NEPTUNE_PROJECT
base_namespace: kedro
enabled: true
enabled: $NEPTUNE_ENABLED

#LOGGING
upload_source_files:
Expand Down
17 changes: 6 additions & 11 deletions kedro_neptune/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
from typing import List
from dataclasses import dataclass


def _parse_config_input(config_input: str):
if isinstance(config_input, str) and config_input.startswith('$'):
return os.environ.get(config_input[1:])
return config_input
from kedro_neptune.utils import parse_config_value, ensure_bool


@dataclass()
Expand All @@ -38,11 +33,11 @@ def get_neptune_config(settings) -> NeptuneConfig:
credentials = config_loader.get("credentials_neptune*")
config = config_loader.get('neptune*')

api_token = _parse_config_input(credentials['neptune']['api_token'])
project = _parse_config_input(config['neptune']['project'])
base_namespace = config['neptune']['base_namespace']
source_files = config['neptune']['upload_source_files']
enabled = bool(_parse_config_input(config['neptune'].get('enabled', True)))
api_token = parse_config_value(credentials['neptune']['api_token'])
project = parse_config_value(config['neptune']['project'])
base_namespace = parse_config_value(config['neptune']['base_namespace'])
source_files = parse_config_value(config['neptune']['upload_source_files'])
enabled = ensure_bool(parse_config_value(config['neptune'].get('enabled', True)))

return NeptuneConfig(
api_token=api_token,
Expand Down
40 changes: 40 additions & 0 deletions kedro_neptune/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2022, Neptune Labs Sp. z o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
__all__ = [
'ensure_bool',
'parse_config_value',
]

import os

from typing import Any, Union, Optional


def parse_config_value(config_value: Any):
return extract_env_variable(value=config_value)


def extract_env_variable(value: Any):
if isinstance(value, str) and value.startswith('$'):
return os.environ.get(value[1:], '')
return value


def ensure_bool(value: Optional[Union[str, bool]]) -> bool:
if isinstance(value, str):
return value.lower().strip() not in ('false', 'no', '0')

return value
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ persistent=yes
load-plugins=pylintfileheader

# File header
file-header=#\n# Copyright \(c\) (2019|2020|2021), Neptune Labs Sp\. z o\.o\.\n#\n# Licensed under the Apache License, Version 2\.0 \(the "License"\);\n# you may not use this file except in compliance with the License\.\n# You may obtain a copy of the License at\n#\n# http://www\.apache\.org/licenses/LICENSE-2\.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an "AS IS" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.\n# See the License for the specific language governing permissions and\n# limitations under the License\.\n#\n
file-header=#\n# Copyright \(c\) (2019|2020|2021|2022), Neptune Labs Sp\. z o\.o\.\n#\n# Licensed under the Apache License, Version 2\.0 \(the "License"\);\n# you may not use this file except in compliance with the License\.\n# You may obtain a copy of the License at\n#\n# http://www\.apache\.org/licenses/LICENSE-2\.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an "AS IS" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.\n# See the License for the specific language governing permissions and\n# limitations under the License\.\n#\n

[MESSAGES CONTROL]

Expand Down
36 changes: 36 additions & 0 deletions tests/kedro_neptune/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright (c) 2021, Neptune Labs Sp. z o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from kedro_neptune.utils import ensure_bool


class TestUtils:
def test_ensure_bool(self):
assert ensure_bool(value=False) is False
assert ensure_bool(value="FALSE") is False
assert ensure_bool(value=" False ") is False
assert ensure_bool(value="False") is False
assert ensure_bool(value="false") is False
assert ensure_bool(value="no") is False
assert ensure_bool(value="0") is False

assert ensure_bool(value=True) is True
assert ensure_bool(value="") is True
assert ensure_bool(value="non_boolean") is True
assert ensure_bool(value="1") is True
assert ensure_bool(value="TRUE") is True
assert ensure_bool(value=" True ") is True
assert ensure_bool(value="True") is True
assert ensure_bool(value="true") is True