Skip to content

Commit 6c2cadc

Browse files
authored
Environment Variable Resolver (#254)
* Functionality for env resolver and crypto functionality. also added all currently installed packages to the info dump (in comments) such that a minimal python env should be able to be re-constructed * added unit tests. cleaned up bugs found when creating unit tests * added docs for resolvers * updated README
1 parent a14fb43 commit 6c2cadc

27 files changed

+1624
-102
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ A clear and concise description of what you expected to happen.
2323
**Screenshots**
2424
If applicable, add screenshots to help explain your problem.
2525

26-
**Desktop (please complete the following information):**
27-
- OS: [e.g. iOS]
28-
- Browser [e.g. chrome, safari]
29-
- Version [e.g. 22]
30-
31-
**Smartphone (please complete the following information):**
32-
- Device: [e.g. iPhone6]
33-
- OS: [e.g. iOS8.1]
34-
- Browser [e.g. stock browser, safari]
35-
- Version [e.g. 22]
26+
**Environment (please complete the following information):**
27+
- OS: [e.g. Ubuntu 16.04, Windows, etc.]
28+
- Python version [e.g. 3.6.3, 3.7.5]:
29+
- Other installed packages [e.g. torch, scipy, etc.]
3630

3731
**Additional context**
3832
Add any other context about the problem here.

.github/pull_request_template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ E.g. Describe the added feature or what issue it fixes #(issue)...
1212
- [ ] Did you run black and isort prior to submitting your PR?
1313
- [ ] Does your PR pass all existing unit tests?
1414
- [ ] Did you add associated unit tests for any additional functionality?
15-
- [ ] Did you provide documentation ([Google Docstring format](https://google.github.io/styleguide/pyguide.html)) whenever possible, even for simple functions or classes?
15+
- [ ] Did you provide code documentation ([Google Docstring format](https://google.github.io/styleguide/pyguide.html)) whenever possible, even for simple functions or classes?
16+
- [ ] Did you add necessary documentation to the website?
1617

1718
## Review
1819
Request will go to reviewers to approve for merge.

NOTICE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ FMR LLC (https://www.fidelity.com/).
1111

1212
This product relies on the following works (and the dependencies thereof), installed separately:
1313
- attrs | https://github.com/python-attrs/attrs | MIT License
14+
- cryptography | https://github.com/pyca/cryptography | Apache License 2.0 + BSD License
1415
- GitPython | https://github.com/gitpython-developers/GitPython | BSD 3-Clause License
1516
- pytomlpp | https://github.com/bobfang1992/pytomlpp | MIT License
1617
- PyYAML | https://github.com/yaml/pyyaml | MIT License
18+
- setuptools | https://github.com/pypa/setuptools | MIT License
1719

1820

1921
Optional extensions rely on the following works (and the dependencies thereof), installed separately:

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ generating CLI arguments, and hierarchical configuration by composition.
5252
* Automatic type checked CLI generation w/o argparser boilerplate (i.e click and/or typer for free!)
5353
* Easily maintain parity between CLIs and Python APIs (i.e. single line changes between CLI and Python API definitions)
5454
* Unified hyper-parameter definitions and interface (i.e. don't write different definitions for Ax or Optuna)
55+
* Resolver that supports value definitions from environmental variables, dynamic template re-injection, and
56+
encryption of sensitive values
5557

5658
## Key Features
5759

@@ -101,6 +103,13 @@ See [Releases](https://github.com/fidelity/spock/releases) for more information.
101103

102104
<details>
103105

106+
#### May 17th, 2022
107+
* Added support for resolving value definitions from environmental variables with the following syntax,
108+
`${spock.env:name, default}`
109+
* Added `.inject` annotation that will write back the original env notation to the saved output
110+
* Added the `.crypto` annotation which provides a simple way to hide sensitive environmental
111+
variables while still maintaining the written/loadable state of the spock config
112+
104113
#### March 17th, 2022
105114
* Added support for `typing.Callable` types (includes advanced types such as `List[List[Callable]]`)
106115
* Added support for `typing.Dict` types with type checking for types of both keys and values (includes advanced types

REQUIREMENTS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
attrs~=21.4
2+
cryptography~=37.0
23
GitPython~=3.1
34
pytomlpp~=1.0
45
pyYAML~=5.4
6+
setuptools~=59.6

spock/addons/tune/payload.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
"""Handles the tuner payload backend"""
77

8+
from typing import Optional
9+
810
from spock.backend.payload import BasePayload
9-
from spock.backend.utils import get_attr_fields
11+
from spock.backend.utils import _T, get_attr_fields
1012

1113

1214
class TunerPayload(BasePayload):
@@ -20,7 +22,7 @@ class TunerPayload(BasePayload):
2022
2123
"""
2224

23-
def __init__(self, s3_config=None):
25+
def __init__(self, s3_config: Optional[_T] = None):
2426
"""Init for TunerPayload
2527
2628
Args:

spock/backend/builder.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import argparse
88
from abc import ABC, abstractmethod
99
from enum import EnumMeta
10-
from typing import Dict, List
10+
from typing import ByteString, Dict, List
1111

1212
import attr
1313

@@ -34,22 +34,36 @@ class BaseBuilder(ABC): # pylint: disable=too-few-public-methods
3434
_module_name: module name to register in the spock module space
3535
save_path: list of path(s) to save the configs to
3636
_lazy: attempts to lazily find @spock decorated classes registered within sys.modules["spock"].backend.config
37+
_salt: salt use for crypto purposes
38+
_key: key used for crypto purposes
3739
3840
"""
3941

4042
def __init__(
41-
self, *args, max_indent: int = 4, module_name: str, lazy: bool, **kwargs
43+
self,
44+
*args,
45+
max_indent: int = 4,
46+
module_name: str,
47+
lazy: bool,
48+
salt: str,
49+
key: ByteString,
50+
**kwargs,
4251
):
4352
"""Init call for BaseBuilder
4453
4554
Args:
4655
*args: iterable of @spock decorated classes
4756
max_indent: max indent for pretty print of help
4857
module_name: module name to register in the spock module space
58+
lazy: lazily find @spock decorated classes
59+
salt: cryptographic salt
60+
key: cryptographic key
4961
**kwargs: keyword args
5062
"""
5163
self._input_classes = args
5264
self._lazy = lazy
65+
self._salt = salt
66+
self._key = key
5367
self._graph = Graph(input_classes=self.input_classes, lazy=self._lazy)
5468
# Make sure the input classes are updated -- lazy evaluation
5569
self._input_classes = self._graph.nodes
@@ -144,7 +158,7 @@ def resolve_spock_space_kwargs(self, graph: Graph, dict_args: Dict) -> Dict:
144158
for spock_cls in graph.roots:
145159
# Initial call to the RegisterSpockCls generate function (which will handle recursing if needed)
146160
spock_instance, special_keys = RegisterSpockCls.recurse_generate(
147-
spock_cls, builder_space
161+
spock_cls, builder_space, self._salt, self._key
148162
)
149163
builder_space.spock_space[spock_cls.__name__] = spock_instance
150164

0 commit comments

Comments
 (0)