Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
William Fong
Configurables
Commits
57848949
Commit
57848949
authored
2 years ago
by
William Fong
Browse files
Options
Browse Files
Download
Plain Diff
resolving merge conflicts
parents
8b022919
0867800e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
configurables/configurable.py
configurables/configurable.py
+6
-0
configurables/core.py
configurables/core.py
+7
-2
No files found.
configurables/configurable.py
View file @
57848949
...
...
@@ -2,10 +2,13 @@ import os
import
pathlib
import
typing
import
deal
from
configurables.core
import
ConfigurationBuilder
,
ConfigurationFactory
from
configurables.parse
import
PARSING_REGISTRY
,
autoparse_config
@
deal
.
pre
(
lambda
_
:
pathlib
.
Path
(
_
.
config_path
).
exists
())
def
configure
(
target
:
typing
.
Callable
,
config_path
:
typing
.
Union
[
str
,
bytes
,
os
.
PathLike
],
...
...
@@ -41,6 +44,7 @@ def configure(
return
target
(
**
config
)
@
deal
.
pre
(
lambda
_
:
len
(
_
.
name
)
>
0
)
def
define_param
(
name
,
type
=
str
):
"""
A decorator to add a required parameter to a ConfigurationBuilder. This
...
...
@@ -79,6 +83,7 @@ def define_param(name, type=str):
return
_internal
@
deal
.
pre
(
lambda
_
:
len
(
_
.
name
)
>
0
)
def
define_option
(
name
,
type
,
default
=
None
):
"""
A decorator to add an optional parameter to a ConfigurationBuilder. This
...
...
@@ -123,6 +128,7 @@ def define_option(name, type, default=None):
return
_internal
@
deal
.
pre
(
lambda
_
:
len
(
_
.
config_section
)
>
0
)
def
configurable
(
config_section
):
"""
The top-level decorator to fully bind a callable.
...
...
This diff is collapsed.
Click to expand it.
configurables/core.py
View file @
57848949
...
...
@@ -97,12 +97,14 @@ class ConfigurationBuilder:
options
:
typing
.
Dict
[
str
,
Option
]
function
:
CastLike
def
add_parameter
(
self
,
name
:
str
,
type
:
typing
.
Callable
):
@
deal
.
pre
(
lambda
_
:
len
(
_
.
name
)
>
0
)
def
add_parameter
(
self
,
name
:
str
,
type
:
CastLike
):
parameter
=
Parameter
(
name
=
name
,
type
=
type
)
self
.
parameters
[
name
]
=
parameter
@
deal
.
pre
(
lambda
_
:
len
(
_
.
name
)
>
0
)
def
add_option
(
self
,
name
:
str
,
type
:
typing
.
Callabl
e
,
default
:
typing
.
Any
=
None
self
,
name
:
str
,
type
:
CastLik
e
,
default
:
typing
.
Any
=
None
):
option
=
Option
(
name
=
name
,
type
=
type
,
default
=
default
)
self
.
options
[
name
]
=
option
...
...
@@ -135,12 +137,14 @@ class ConfigurationFactory:
self
.
builder
=
config_builder
self
.
section
=
section
@
deal
.
pure
def
_resolve_param
(
self
,
key
:
str
,
file_opts
:
ConfigLike
,
overrides
:
ConfigLike
):
_type
=
self
.
builder
.
parameters
[
key
].
type
return
_type
(
overrides
.
get
(
key
,
os
.
environ
.
get
(
key
,
file_opts
[
key
])))
@
deal
.
pure
def
_resolve_option
(
self
,
key
:
str
,
file_opts
:
ConfigLike
,
overrides
:
ConfigLike
):
...
...
@@ -154,6 +158,7 @@ class ConfigurationFactory:
)
)
@
deal
.
pre
(
lambda
_
:
pathlib
.
Path
(
_
.
filepath
).
exists
())
def
parse
(
self
,
filepath
:
PathLike
,
**
overrides
):
kwargs
=
{}
file_opts
=
parse_ini
(
filepath
,
self
.
section
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment