Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ jobs:
os: ${{ matrix.os }}
- name: Run genesis tests
run: |
HATHOR_TEST_CONFIG_YAML='./hathor/conf/mainnet.yml' poetry run pytest -n0 --cov=hathor hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathor/conf/testnet.yml' poetry run pytest -n0 --cov=hathor --cov-append hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathor/conf/nano_testnet.yml' poetry run pytest -n0 --cov=hathor --cov-append hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathorlib/hathorlib/conf/mainnet.yml' poetry run pytest -n0 --cov=hathor hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathorlib/hathorlib/conf/testnet.yml' poetry run pytest -n0 --cov=hathor --cov-append hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathorlib/hathorlib/conf/nano_testnet.yml' poetry run pytest -n0 --cov=hathor --cov-append hathor_tests/tx/test_genesis.py
- name: Run custom tests
run: poetry run bash ./extras/custom_tests.sh
- name: Run CI tests
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ tests-quick:

.PHONY: tests-genesis
tests-genesis:
HATHOR_TEST_CONFIG_YAML='./hathor/conf/mainnet.yml' pytest -n0 hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathor/conf/testnet.yml' pytest -n0 hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathor/conf/nano_testnet.yml' pytest -n0 hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathorlib/hathorlib/conf/mainnet.yml' pytest -n0 hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathorlib/hathorlib/conf/testnet.yml' pytest -n0 hathor_tests/tx/test_genesis.py
HATHOR_TEST_CONFIG_YAML='./hathorlib/hathorlib/conf/nano_testnet.yml' pytest -n0 hathor_tests/tx/test_genesis.py

.PHONY: tests-ci
tests-ci:
Expand Down
15 changes: 0 additions & 15 deletions hathor/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path

from hathor.conf.get_settings import HathorSettings

parent_dir = Path(__file__).parent

MAINNET_SETTINGS_FILEPATH = str(parent_dir / 'mainnet.yml')
TESTNET_INDIA_SETTINGS_FILEPATH = str(parent_dir / 'testnet.yml')
NANO_TESTNET_SETTINGS_FILEPATH = str(parent_dir / 'nano_testnet.yml')
LOCALNET_SETTINGS_FILEPATH = str(parent_dir / 'localnet.yml')
UNITTESTS_SETTINGS_FILEPATH = str(parent_dir / 'unittests.yml')

__all__ = [
'MAINNET_SETTINGS_FILEPATH',
'TESTNET_INDIA_SETTINGS_FILEPATH',
'NANO_TESTNET_SETTINGS_FILEPATH',
'LOCALNET_SETTINGS_FILEPATH',
'UNITTESTS_SETTINGS_FILEPATH',
'HathorSettings',
]
43 changes: 17 additions & 26 deletions hathor/conf/get_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

from __future__ import annotations

import importlib
import os
from typing import TYPE_CHECKING, NamedTuple, Optional

from structlog import get_logger

from hathorlib.conf.utils import load_module_settings, load_yaml_settings

if TYPE_CHECKING:
from hathor.conf.settings import HathorSettings as Settings

Expand All @@ -29,17 +30,17 @@
class _SettingsMetadata(NamedTuple):
source: str
is_yaml: bool
settings: Settings
settings: 'Settings'


_settings_singleton: Optional[_SettingsMetadata] = None


def get_global_settings() -> Settings:
def get_global_settings() -> 'Settings':
return HathorSettings()


def HathorSettings() -> Settings:
def HathorSettings() -> 'Settings':
"""
Returns the configuration named tuple.

Expand All @@ -53,7 +54,7 @@ def HathorSettings() -> Settings:
if settings_module_filepath is not None:
return _load_settings_singleton(settings_module_filepath, is_yaml=False)

from hathor import conf
from hathorlib import conf
settings_yaml_filepath = os.environ.get('HATHOR_CONFIG_YAML', conf.MAINNET_SETTINGS_FILEPATH)
return _load_settings_singleton(settings_yaml_filepath, is_yaml=True)

Expand All @@ -68,7 +69,7 @@ def get_settings_source() -> str:
return _settings_singleton.source


def _load_settings_singleton(source: str, *, is_yaml: bool) -> Settings:
def _load_settings_singleton(source: str, *, is_yaml: bool) -> 'Settings':
global _settings_singleton

if _settings_singleton is not None:
Expand All @@ -79,29 +80,19 @@ def _load_settings_singleton(source: str, *, is_yaml: bool) -> Settings:

return _settings_singleton.settings

settings_loader = _load_yaml_settings if is_yaml else _load_module_settings
if not is_yaml:
log = logger.new()
log.warn(
"Setting a config module via the 'HATHOR_CONFIG_FILE' env var will be deprecated soon. "
"Use the '--config-yaml' CLI option or the 'HATHOR_CONFIG_YAML' env var to set a yaml filepath instead."
)
from hathor.conf.settings import HathorSettings as Settings

settings_loader = load_yaml_settings if is_yaml else load_module_settings
_settings_singleton = _SettingsMetadata(
source=source,
is_yaml=is_yaml,
settings=settings_loader(source)
settings=settings_loader(Settings, source)
)

return _settings_singleton.settings


def _load_module_settings(module_path: str) -> Settings:
log = logger.new()
log.warn(
"Setting a config module via the 'HATHOR_CONFIG_FILE' env var will be deprecated soon. "
"Use the '--config-yaml' CLI option or the 'HATHOR_CONFIG_YAML' env var to set a yaml filepath instead."
)
settings_module = importlib.import_module(module_path)
settings = getattr(settings_module, 'SETTINGS')
from hathor.conf.settings import HathorSettings as Settings
assert isinstance(settings, Settings)
return settings


def _load_yaml_settings(filepath: str) -> Settings:
from hathor.conf.settings import HathorSettings as Settings
return Settings.from_yaml(filepath=filepath)
3 changes: 2 additions & 1 deletion hathor/conf/mainnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
# limitations under the License.

from hathor.checkpoint import Checkpoint as cp
from hathor.conf.settings import FeatureSetting, HathorSettings
from hathor.conf.settings import HathorSettings
from hathor.feature_activation.feature import Feature
from hathor.feature_activation.model.criteria import Criteria
from hathor.feature_activation.settings import Settings as FeatureActivationSettings
from hathorlib.conf.settings import FeatureSetting

SETTINGS = HathorSettings(
P2PKH_VERSION_BYTE=b'\x28',
Expand Down
Loading
Loading