Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
796c5cc4
Commit
796c5cc4
authored
11 months ago
by
Joscha Schmiedt
Browse files
Options
Downloads
Patches
Plain Diff
Add type hints to configuration.py
parent
b05dcfc4
No related branches found
No related tags found
2 merge requests
!143
Release 0.15.0
,
!135
Add and fix more type hints
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/linkahead/configuration.py
+10
-8
10 additions, 8 deletions
src/linkahead/configuration.py
with
10 additions
and
8 deletions
src/linkahead/configuration.py
+
10
−
8
View file @
796c5cc4
...
...
@@ -21,14 +21,14 @@
#
# ** end header
#
from
__future__
import
annotations
import
os
import
warnings
import
yaml
try
:
optional_jsonschema_validate
=
None
optional_jsonschema_validate
:
Optional
[
Callable
]
=
None
from
jsonschema
import
validate
as
optional_jsonschema_validate
except
ImportError
:
pass
...
...
@@ -37,13 +37,15 @@ from configparser import ConfigParser
from
os
import
environ
,
getcwd
from
os.path
import
expanduser
,
isfile
,
join
from
typing
import
Dict
,
Union
,
Callable
,
Optional
def
_reset_config
():
global
_pycaosdbconf
_pycaosdbconf
=
ConfigParser
(
allow_no_value
=
False
)
def
configure
(
inifile
)
:
def
configure
(
inifile
:
str
)
->
list
[
str
]
:
"""
read config from file.
Return a list of files which have successfully been parsed.
...
...
@@ -61,15 +63,15 @@ def configure(inifile):
return
read_config
def
get_config
():
def
get_config
()
->
ConfigParser
:
global
_pycaosdbconf
if
(
"
_pycaosdbconf
"
not
in
globals
()
or
_pycaosdbconf
is
None
):
_reset_config
()
return
_pycaosdbconf
def
config_to_yaml
(
config
)
:
valobj
=
{}
def
config_to_yaml
(
config
:
ConfigParser
)
->
Dict
[
str
,
Dict
[
str
,
Union
[
int
,
str
,
bool
]]]
:
valobj
:
Dict
[
str
,
Dict
[
str
,
Union
[
int
,
str
,
bool
]]]
=
{}
for
s
in
config
.
sections
():
valobj
[
s
]
=
{}
for
key
,
value
in
config
[
s
].
items
():
...
...
@@ -84,7 +86,7 @@ def config_to_yaml(config):
return
valobj
def
validate_yaml_schema
(
valobj
):
def
validate_yaml_schema
(
valobj
:
Dict
[
str
,
Dict
[
str
,
Union
[
int
,
str
,
bool
]]]
):
if
optional_jsonschema_validate
:
with
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"
schema-pycaosdb-ini.yml
"
))
as
f
:
schema
=
yaml
.
load
(
f
,
Loader
=
yaml
.
SafeLoader
)
...
...
@@ -95,7 +97,7 @@ def validate_yaml_schema(valobj):
"""
)
def
_read_config_files
():
def
_read_config_files
()
->
list
[
str
]
:
"""
Read config files from different paths.
Read the config from either ``$PYCAOSDBINI`` or home directory (``~/.pylinkahead.ini``), and
...
...
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