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

New Types + Variable Resolver #272

Merged
merged 7 commits into from
Jan 17, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/python-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
deploy:

runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
run_lint:

runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-manual-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on: workflow_dispatch
jobs:
deploy:

runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
deploy:

runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-pytest-s3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-pytest-tune.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-test-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:
deploy:

runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
name: black (python)
language_version: python3.10
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
language_version: python3.10
19 changes: 0 additions & 19 deletions .pylintrc

This file was deleted.

22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ generating CLI arguments, and hierarchical configuration by composition.
* Automatic type checked CLI generation w/o argparser boilerplate (i.e click and/or typer for free!)
* Easily maintain parity between CLIs and Python APIs (i.e. single line changes between CLI and Python API definitions)
* Unified hyper-parameter definitions and interface (i.e. don't write different definitions for Ax or Optuna)
* Resolver that supports value definitions from environmental variables, dynamic template re-injection, and
encryption of sensitive values
* Resolver that supports value definitions from reference to other defined variables, environmental variables, dynamic template re-injection, and encryption of sensitive values

## Key Features

Expand Down Expand Up @@ -103,6 +102,12 @@ See [Releases](https://github.com/fidelity/spock/releases) for more information.

<details>

### Jan 12th, 2023
* Added support for resolving value definitions from references to other defined variables with the following syntax,`${spock.var:SpockClass.defined_variable}`
* Added support for new fundamental types: (1) file: this is an overload of a str that verifies file existence and (r/w) access (2) directory: this is an overload of a str that verifies directory existence, creation if not existing, and (r/w) access
* Deprecated support for `List` of repeated `@spock` decorated classes.
* Collection of bugfixes

#### May 17th, 2022
* Added support for resolving value definitions from environmental variables with the following syntax,
`${spock.env:name, default}`
Expand All @@ -119,17 +124,8 @@ Additionally, added some common validation check to utils (within, greater than,
* Updated unit tests to support Python 3.10

#### January 26th, 2022
* Added `evolve` support to the underlying `SpockBuilder` class. This provides functionality similar to the underlying
attrs library ([attrs.evolve](https://www.attrs.org/en/stable/api.html#attrs.evolve)). `evolve()` creates a new
`Spockspace` instance based on differences between the underlying declared state and any passed in instantiated
`@spock` decorated classes.

#### January 18th, 2022
* Support for lazy evaluation: (1) inherited classes do not need to be `@spock` decorated, (2) dependencies/references
between `spock` classes can be lazily handled thus preventing the need for every `@spock` decorated classes to be
passed into `*args` within the main `SpockBuilder` API
* Updated main API interface for better top-level imports (backwards compatible): `ConfigArgBuilder`->`SpockBuilder`
* Added stubs to the underlying decorator that should help with type hinting in VSCode (pylance/pyright)
* Added `evolve` support to the underlying `SpockBuilder` class. This provides functionality similar to the underlying attrs library ([attrs.evolve](https://www.attrs.org/en/stable/api.html#attrs.evolve)). `evolve()` creates a new `Spockspace` instance based on differences between the underlying declared state and any passed
in instantiated `@spock` decorated classes.

</details>

Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[tool.isort]
profile = "black"
extend_skip = ["debug", "tests", "examples"]
extend_skip = ["debug", "tests", "examples", "versioneer.py", "_version.py"]

[tool.black]
target-version = ['py36', 'py37', 'py38', 'py39']
target-version = ['py36', 'py37', 'py38', 'py39', 'py310']
exclude = '''
/(
| debug
| docs
| examples
| tests
| versioneer.py
| _version.py
)/
'''
2 changes: 2 additions & 0 deletions requirements/DEV_REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ coveralls~=3.3
coverage[toml]~=6.1
isort~=5.10
moto~=3.1
pre-commit~=2.20 ; python_version >= '3.7'
pre-commit~=2.17 ; python_version == '3.6'
pydoc-markdown~=4.3, < 4.6.* ; python_version >= '3.7'
pydoc-markdown~=3.13 ; python_version == '3.6'
pytest~=7.0
Expand Down
12 changes: 11 additions & 1 deletion spock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@
"""

from spock._version import get_versions
from spock.backend.custom import directory, file
from spock.backend.typed import SavePath
from spock.builder import ConfigArgBuilder
from spock.config import spock

SpockBuilder = ConfigArgBuilder

__all__ = ["args", "builder", "config", "SavePath", "spock", "SpockBuilder"]
__all__ = [
"args",
"builder",
"config",
"directory",
"file",
"SavePath",
"spock",
"SpockBuilder",
]

__version__ = get_versions()["version"]
del get_versions
27 changes: 25 additions & 2 deletions spock/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
from typing import Any, Callable, List, Optional, Tuple, TypeVar, Union, overload
# -*- coding: utf-8 -*-

# Copyright FMR LLC <[email protected]>
# SPDX-License-Identifier: Apache-2.0

"""Stubs"""

from typing import Any, Callable, Tuple, TypeVar, Union, overload

from attr import attrib, field

# from spock.backend.typed import SavePath
from spock._version import get_versions
from spock.backend.custom import directory, file
from spock.backend.typed import SavePath
from spock.builder import ConfigArgBuilder
from spock.config import spock

# SpockBuilder = ConfigArgBuilder

__all__ = [
"args",
"builder",
"config",
"directory",
"file",
"SavePath",
"spock",
"SpockBuilder",
]

_T = TypeVar("_T")
_C = TypeVar("_C", bound=type)
Expand Down
7 changes: 4 additions & 3 deletions spock/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def values(self):

@staticmethod
def _get_general_arguments(arguments: Dict, config_dag: Graph) -> Dict:
"""Creates a dictionary of config file parameters that are defined at the general level (not class specific)
"""Creates a dictionary of config file parameters that are defined at the
general level (not class specific)

Args:
arguments: dictionary of parameters from the config file(s)
Expand Down Expand Up @@ -148,8 +149,8 @@ def _is_duplicated_key(
def _assign_general_arguments_to_config(
self, general_arguments: Dict, attribute_name_to_config_name_mapping: Dict
) -> None:
"""Assigns the values from general definitions to values within specific classes if the specific definition
doesn't exist
"""Assigns the values from general definitions to values within specific
classes if the specific definition doesn't exist

Args:
general_arguments:
Expand Down
Loading