FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
feast/sdk/python/feast/loaders/yaml.py at swapyaml · feast-dev/feast · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
feast-dev
/
feast
Public
Notifications
You must be signed in to change notification settings
Fork
1.4k
Star
7.2k
Code
Issues
218
Pull requests
191
Discussions
Actions
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
feast
/
sdk
/
python
/
feast
/
loaders
/
yaml.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
77 lines (59 loc) · 2.03 KB
Breadcrumbs
feast
/
sdk
/
python
/
feast
/
loaders
/
yaml.py
Copy path
File metadata and controls
77 lines (59 loc) · 2.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import
yaml
def
yaml_loader
(
yml
,
load_single
=
False
):
"""
Loads one or more Feast resources from a YAML path or string. Multiple resources
can be divided by three hyphens '---'
Args:
yml: A path ending in .yaml or .yml, or a YAML string
load_single: Expect only a single YAML resource, fail otherwise
Returns:
Either a single YAML dictionary or a list of YAML dictionaries
"""
yml_content
=
_get_yaml_contents
(
yml
)
yaml_strings
=
yml_content
.
strip
(
"---"
).
split
(
"---"
)
# Return a single resource dict
if
load_single
:
if
len
(
yaml_strings
)
>
1
:
raise
Exception
(
f"More than one YAML file is being loaded when only a single file is supported: $
{
yaml_strings
}
"
)
return
_yaml_to_dict
(
yaml_strings
[
0
])
# Return a list of resource dicts
resources
=
[]
for
yaml_string
in
yaml_strings
:
resources
.
append
(
_yaml_to_dict
(
yaml_string
))
return
resources
def
_get_yaml_contents
(
yml
:
str
)
->
str
:
"""
Returns the YAML contents from an object. If a path ending with .yaml or
.yml is passed, it will be read for its contents. If a string containing
YAML is passed, that will be returned.
Args:
yml: Path of YAML file or string containing YAML
Returns:
String object containing YAML
"""
if
(
isinstance
(
yml
,
str
)
and
yml
.
count
(
"
\n
"
)
==
0
and
(
".yaml"
in
yml
.
lower
()
or
".yml"
in
yml
.
lower
())
):
with
open
(
yml
,
"r"
)
as
f
:
yml_content
=
f
.
read
()
elif
isinstance
(
yml
,
str
):
yml_content
=
yml
else
:
raise
Exception
(
f"Invalid YAML provided. Please provide either a file path or YAML string.
\n
"
f"Provided YAML:
{
yml
}
"
)
return
yml_content
def
_yaml_to_dict
(
yaml_string
):
"""
Converts a yaml string to dictionary
Args:
yaml_string: String containing YAML
Returns:
Dictionary containing the same object
"""
return
yaml
.
safe_load
(
yaml_string
)
Back
|
FazBrowse Home
|
New Git URL