Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
octobus
Poulpe
Commits
80b4ae39
Commit
80b4ae39
authored
2 years ago
by
Raphaël Gomès
Browse files
Options
Downloads
Patches
Plain Diff
WIP config
parent
a1631d29
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
python-libs/poulpe/config.py
+55
-0
55 additions, 0 deletions
python-libs/poulpe/config.py
python-libs/poulpe/errors.py
+4
-0
4 additions, 0 deletions
python-libs/poulpe/errors.py
setup.cfg
+1
-0
1 addition, 0 deletions
setup.cfg
with
60 additions
and
0 deletions
python-libs/poulpe/config.py
0 → 100644
+
55
−
0
View file @
80b4ae39
# User config for poulpe and its components
import
pathlib
import
toml
import
platformdirs
from
poulpe
import
errors
APP_NAME
=
"
poulpe
"
AUTHOR
=
"
poulpe-developers
"
# needed for Windows
def
validate_config
(
config_data
):
"""
Make sure the user config is like we expect
"""
hints
=
[]
# For now this is quite manual. There are no facilities for validating
# declarative schemas in Python. We'll probably write this in Rust shortly,
# and add Python bindings.
folders
=
config_data
.
get
(
"
folders
"
)
if
folders
is
not
None
:
if
isinstance
(
folders
,
dict
):
expected_keys
=
{
"
bin-envs
"
,
"
data-envs
"
,
"
results
"
,
"
repos
"
}
for
key
,
path
in
folders
:
if
key
not
in
expected_keys
:
hints
.
append
(
f
"
Unexpected key
'
{
key
}
'
in [folders] section
"
)
else
:
wrong_path_msg
=
f
"
folders.
{
key
}
should be an absolute path
"
try
:
path
=
pathlib
.
Path
(
path
)
except
TypeError
:
hints
.
append
(
wrong_path_msg
)
else
:
if
not
path
.
is_absolute
():
hints
.
append
(
wrong_path_msg
)
else
:
hints
.
append
(
"
[folders] should be a mapping of name to path
"
)
else
:
hints
.
append
(
"
Missing top-level [folders] section
"
)
return
hints
def
user_config
():
"""
Returns the validated user config
"""
config_dir
=
platformdirs
.
user_config_path
(
APP_NAME
,
AUTHOR
)
config_file
=
config_dir
/
"
config.toml
"
if
not
config_file
.
exists
():
msg
=
f
"
Please define a valid `config.toml` in `
{
config_dir
}
`
"
raise
errors
.
ConfigError
(
msg
)
config_data
=
toml
.
loads
(
config_file
.
read_text
())
errors
=
validate_config
(
config_data
)
if
hints
:
hints
=
"
\n
-
"
.
join
(
hints
)
raise
errors
.
ConfigError
(
f
"
Invalid config file:
\n
{
hints
}
"
)
return
config_data
This diff is collapsed.
Click to expand it.
python-libs/poulpe/errors.py
+
4
−
0
View file @
80b4ae39
...
...
@@ -20,3 +20,7 @@
class
MissingDataEnvInputVars
(
KeyError
):
pass
class
ConfigError
(
RuntimeError
):
pass
This diff is collapsed.
Click to expand it.
setup.cfg
+
1
−
0
View file @
80b4ae39
...
...
@@ -5,6 +5,7 @@
[options]
install_requires
=
click
=
= 8.1
platformdirs
importlib-resources
toml
packages
=
find_namespace:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment