Skip to content

Commit

Permalink
feat: Rename package to cfg
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename package to cfg
  • Loading branch information
Rizhiy committed Dec 18, 2023
1 parent 0af1f25 commit 86d47d5
Show file tree
Hide file tree
Showing 97 changed files with 157 additions and 130 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Artem Vasenin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion ntc/__init__.py → cfg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" NeuroTrade Config Library """
"""Python Configuration System"""
from __future__ import annotations

from .errors import *
Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions cfg/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations
import sys
import argparse

from pathlib import Path

from cfg.node import CN


def get_output_dir(cfg: CN, mkdir=True, base_dir=Path("output")) -> Path:
output_dir = base_dir / cfg.NAME
if mkdir:
output_dir.mkdir(parents=True, exist_ok=True)
return output_dir


def _get_output_dir_cli() -> None:
parser = argparse.ArgumentParser("Get output dir for cfg", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("cfg_path", type=Path)
parser.add_argument("--mkdir", action="store_true", help="Will create the directory if it doesn't exist")
parser.add_argument("--base-dir", type=Path, default=Path("output"), help="Base directory for all output dirs")
args = parser.parse_args()

cfg = CN.load(args.cfg_path)
dir_ = get_output_dir(cfg, mkdir=args.mkdir, base_dir=args.base_dir)
sys.stdout.write(str(dir_))
File renamed without changes.
4 changes: 2 additions & 2 deletions ntc/leaf.py → cfg/leaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from functools import partial
from typing import TYPE_CHECKING, Any

from ntc.errors import MissingRequired, SchemaError, TypeMismatch
from ntc.full_key_value import FullKeyValue
from cfg.errors import MissingRequired, SchemaError, TypeMismatch
from cfg.full_key_value import FullKeyValue

from .utils import full_type_name

Expand Down
10 changes: 5 additions & 5 deletions ntc/node.py → cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import yaml

from ntc.errors import (
from cfg.errors import (
ConfigError,
ConfigUseError,
MissingRequired,
Expand All @@ -20,9 +20,9 @@
SchemaFrozenError,
ValidationError,
)
from ntc.full_key_value import FullKeyParent
from ntc.interfaces import CfgSavable
from ntc.utils import add_yaml_str_representer, import_module, merge_cfg_module
from cfg.full_key_value import FullKeyParent
from cfg.interfaces import CfgSavable
from cfg.utils import add_yaml_str_representer, import_module, merge_cfg_module

from .leaf import CfgLeaf

Expand Down Expand Up @@ -421,7 +421,7 @@ def _update_module(self, key: str, value) -> None:

for info in inspect.stack()[1:]:
# Kind of a hack, need to keep track of all our files
if "/".join(info.filename.rsplit("/")[-2:]) in ["ntc/node.py", "ntc/leaf.py"]:
if "/".join(info.filename.rsplit("/")[-2:]) in ["cfg/node.py", "cfg/leaf.py"]:
continue
reference_comment = f"# {info.filename}:{info.lineno} {info.code_context[0]}"
break
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions ntc/helpers.py

This file was deleted.

20 changes: 11 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@ requires = ["flit_core >=3.4,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "ntc"
authors = [{name = "Vladimir Mikhaylov", email = "v.mikhaylov@neurotrade.ru"}]
name = "cfg"
authors = [{name = "Artem Vasenin", email = "vasart169@gmail.com"}, {name = "Vladimir Mikhaylov"}]
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.9"
dynamic = ["version", "description"]
dependencies = [
"pyyaml",
"nt-utils",
]

[project.urls]
Home = "https://github.com/Rizhiy/cfg"

[project.optional-dependencies]
test = [
"nt-dev>=0.34",
"types-pyyaml",
"pytest",
]
dev = [
"ntc[test]",
"cfg[test]",
"ruff",
"semantic-release",
]

[tool.flit.sdist]
Expand All @@ -34,12 +39,9 @@ exclude = [
[tool.semantic_release]
version_variable = "ntc/__init__.py:__version__"

[tool.mypy]
exclude = ["tests/data"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--doctest-modules"

[project.scripts]
ntc-output-dir = "ntc.helpers:_get_output_dir_cli"
cfg-output-dir = "cfg.helpers:_get_output_dir_cli"
2 changes: 1 addition & 1 deletion tests/data/bad/bad_attr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_cfg_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..base_cfg import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..base_class import BaseClass
from ..good.good import cfg
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..base_cfg import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_changes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.bad.bad_inherit import cfg

cfg = CN(cfg)
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CL
from cfg import CL

from ..base_cfg import cfg
from ..base_class import BaseClass
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_instance_changes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.bad.bad_inherit_instance import cfg

cfg = CN(cfg)
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_subclass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CL
from cfg import CL

from ..base_cfg import cfg
from ..base_class import BaseClass
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_subclass_changes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.bad.bad_inherit_subclass import cfg

cfg = CN(cfg)
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_subclass_class_changes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.bad.bad_inherit_subclass import cfg

cfg = CN(cfg)
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_subclass_instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CL
from cfg import CL

from ..base_cfg import cfg
from ..base_class import BaseClass
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_inherit_subclass_instance_changes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.bad.bad_inherit_subclass_instance import cfg

cfg = CN(cfg)
2 changes: 1 addition & 1 deletion tests/data/bad/bad_init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

cfg = CN("Bad")
2 changes: 1 addition & 1 deletion tests/data/bad/bad_node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_node_instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.base_class import BaseClass

from ..good.good import cfg
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_node_nested_subclass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_node_required_subclass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_node_subclass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/bad_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN

from ..good.good import cfg

Expand Down
2 changes: 1 addition & 1 deletion tests/data/bad/inheritance_changes_bad.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.good.inheritance import cfg

cfg = CN(cfg)
Expand Down
2 changes: 1 addition & 1 deletion tests/data/base_cfg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CL, CN
from cfg import CL, CN

from .base_class import BaseClass

Expand Down
2 changes: 1 addition & 1 deletion tests/data/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime as dt

from ntc import CfgSavable
from cfg import CfgSavable


class BaseClass:
Expand Down
2 changes: 1 addition & 1 deletion tests/data/description/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CL, CN
from cfg import CL, CN
from tests.data.base_cfg import cfg

cfg = cfg.inherit()
Expand Down
2 changes: 1 addition & 1 deletion tests/data/description/description.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.description.base import cfg

cfg = CN(cfg)
2 changes: 1 addition & 1 deletion tests/data/description/description_bad.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.description.base import cfg

cfg = CN(cfg)
Expand Down
2 changes: 1 addition & 1 deletion tests/data/description/description_inherited.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CL, CN
from cfg import CL, CN
from tests.data.description.base import cfg

cfg = CN(cfg)
Expand Down
2 changes: 1 addition & 1 deletion tests/data/description/description_value_overriding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ntc import CN
from cfg import CN
from tests.data.description.base import cfg

cfg = CN(cfg)
Expand Down
Loading

0 comments on commit 86d47d5

Please sign in to comment.