envstack 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.1
2
+ Name: envstack
3
+ Version: 0.1.0
4
+ Summary: Stacked environment variable management system.
5
+ Home-page: http://github.com/rsgalloway/envstack
6
+ Author: Ryan Galloway
7
+ Author-email: ryan@rsgalloway.com
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: PyYAML==6.0.2
10
+
11
+ envstack
12
+ ========
13
+
14
+ Stacked environment variable management system.
15
+
16
+ Environment variables are declared in namespaced .env files using yaml syntax.
17
+ The default namespace is `stack` and variables are declared in `stack.env`
18
+ files.
19
+
20
+ ## Quickstart
21
+
22
+ To create a new environment stack, create a new namespaced .env file.
23
+ For example, here is a simple `thing.env` file (namespace is "thing"):
24
+
25
+ ```yaml
26
+ all: &default
27
+ FOO: bar
28
+ ```
29
+
30
+ To see the resolved environment for the `thing` stack, run:
31
+
32
+ ```bash
33
+ $ envstack thing
34
+ FOO 'bar'
35
+ ```
36
+
37
+ Environment stacks are hierarchical, so values for `$FOO` defined in .env files lower
38
+ in the filesystem (lower in scope) override those defined higher up (higher in scope):
39
+
40
+ ```
41
+ /show/thing.env
42
+ /show/seq/thing.env
43
+ /show/seq/shot/thing.env
44
+ /show/seq/shot/task/thing.env
45
+ ```
46
+
47
+ Variables can reference other variables defined elsewhere (but cannot be circular):
48
+
49
+ ```yaml
50
+ all: &default
51
+ BAR: $FOO
52
+ ```
53
+
54
+ Variables can be platform specific (and inherit the defaults):
55
+
56
+ ```yaml
57
+ linux:
58
+ <<: *default
59
+ HELLO: world
60
+ ```
61
+
62
+ Environment files can include other namespaced environments:
63
+ ```yaml
64
+ include: ['other']
65
+ ```
66
+
67
+ Installation
68
+ ------------
69
+
70
+ The easiest way to install:
71
+
72
+ ```bash
73
+ $ pip install envstack
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ To see the default resolved environment for any given scope (directory):
79
+
80
+ ```bash
81
+ $ envstack
82
+ ```
83
+
84
+ To see the resolved environment for a given namespace.
85
+
86
+ ```bash
87
+ $ envstack <namespace> [OPTIONS]
88
+ ```
89
+
90
+ To resolve a $VAR declaration for a given namespace:
91
+
92
+ ```bash
93
+ $ envstack <namespace> -r <VAR>
94
+ ```
95
+
96
+ To trace where a $VAR declaration is being set:
97
+
98
+ ```bash
99
+ $ envstack <namespace> -t <VAR>
100
+ ```
101
+
102
+ To see an environment stack on another platform:
103
+
104
+ ```bash
105
+ $ envstack <namespace> -p <platform>
106
+ ```
@@ -0,0 +1,96 @@
1
+ envstack
2
+ ========
3
+
4
+ Stacked environment variable management system.
5
+
6
+ Environment variables are declared in namespaced .env files using yaml syntax.
7
+ The default namespace is `stack` and variables are declared in `stack.env`
8
+ files.
9
+
10
+ ## Quickstart
11
+
12
+ To create a new environment stack, create a new namespaced .env file.
13
+ For example, here is a simple `thing.env` file (namespace is "thing"):
14
+
15
+ ```yaml
16
+ all: &default
17
+ FOO: bar
18
+ ```
19
+
20
+ To see the resolved environment for the `thing` stack, run:
21
+
22
+ ```bash
23
+ $ envstack thing
24
+ FOO 'bar'
25
+ ```
26
+
27
+ Environment stacks are hierarchical, so values for `$FOO` defined in .env files lower
28
+ in the filesystem (lower in scope) override those defined higher up (higher in scope):
29
+
30
+ ```
31
+ /show/thing.env
32
+ /show/seq/thing.env
33
+ /show/seq/shot/thing.env
34
+ /show/seq/shot/task/thing.env
35
+ ```
36
+
37
+ Variables can reference other variables defined elsewhere (but cannot be circular):
38
+
39
+ ```yaml
40
+ all: &default
41
+ BAR: $FOO
42
+ ```
43
+
44
+ Variables can be platform specific (and inherit the defaults):
45
+
46
+ ```yaml
47
+ linux:
48
+ <<: *default
49
+ HELLO: world
50
+ ```
51
+
52
+ Environment files can include other namespaced environments:
53
+ ```yaml
54
+ include: ['other']
55
+ ```
56
+
57
+ Installation
58
+ ------------
59
+
60
+ The easiest way to install:
61
+
62
+ ```bash
63
+ $ pip install envstack
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ To see the default resolved environment for any given scope (directory):
69
+
70
+ ```bash
71
+ $ envstack
72
+ ```
73
+
74
+ To see the resolved environment for a given namespace.
75
+
76
+ ```bash
77
+ $ envstack <namespace> [OPTIONS]
78
+ ```
79
+
80
+ To resolve a $VAR declaration for a given namespace:
81
+
82
+ ```bash
83
+ $ envstack <namespace> -r <VAR>
84
+ ```
85
+
86
+ To trace where a $VAR declaration is being set:
87
+
88
+ ```bash
89
+ $ envstack <namespace> -t <VAR>
90
+ ```
91
+
92
+ To see an environment stack on another platform:
93
+
94
+ ```bash
95
+ $ envstack <namespace> -p <platform>
96
+ ```
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # Copyright (c) 2024, Ryan Galloway (ryan@rsgalloway.com)
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # - Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # - Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # - Neither the name of the software nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software
17
+ # without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+
32
+ __doc__ = """
33
+ Stacked environment variable management system.
34
+ """
35
+
36
+ __prog__ = "envstack"
37
+ __version__ = "0.1.0"
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # Copyright (c) 2024, Ryan Galloway (ryan@rsgalloway.com)
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # - Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # - Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # - Neither the name of the software nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software
17
+ # without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+
32
+ __doc__ = """
33
+ Contains command line interface for envstack.
34
+ """
35
+
36
+ import os
37
+ import sys
38
+ import pprint
39
+ import traceback
40
+
41
+ from envstack import __version__
42
+ from envstack import config
43
+ from envstack.env import expandvars, load_environ, trace_var
44
+
45
+
46
+ def parse_args():
47
+ """Command line argument parser."""
48
+
49
+ import argparse
50
+
51
+ parser = argparse.ArgumentParser(
52
+ description=__doc__, formatter_class=argparse.RawTextHelpFormatter
53
+ )
54
+ parser.add_argument(
55
+ "-v",
56
+ "--version",
57
+ action="version",
58
+ version=f"envstack {__version__}",
59
+ )
60
+ parser.add_argument(
61
+ "namespace",
62
+ metavar="NAMESPACE",
63
+ nargs="?",
64
+ default=config.DEFAULT_NAMESPACE,
65
+ help="the namespace to use",
66
+ )
67
+ parser.add_argument(
68
+ "-p",
69
+ "--platform",
70
+ default=config.PLATFORM,
71
+ metavar="PLATFORM",
72
+ help="specify the platform to resolve variables for",
73
+ )
74
+ parser.add_argument(
75
+ "-r",
76
+ "--resolve",
77
+ metavar="VAR",
78
+ help="resolve an environment variable",
79
+ )
80
+ parser.add_argument(
81
+ "-t",
82
+ "--trace",
83
+ metavar="VAR",
84
+ help="trace where a variable is getting set",
85
+ )
86
+
87
+ args = parser.parse_args()
88
+
89
+ return args, parser
90
+
91
+
92
+ def main():
93
+ """Main thread."""
94
+ args, _ = parse_args()
95
+
96
+ try:
97
+ if args.resolve:
98
+ env = load_environ(
99
+ args.namespace, environ=os.environ, platform=args.platform
100
+ )
101
+ var = env.get(args.resolve)
102
+ print(pprint.pformat(expandvars(var, env, recursive=True)))
103
+ elif args.trace:
104
+ path = trace_var(args.namespace, args.trace)
105
+ print("{0}: {1}".format(args.trace, path))
106
+ else:
107
+ env = load_environ(args.namespace, platform=args.platform, includes=True)
108
+ for k, v in env.items():
109
+ print(f"{k} {pprint.pformat(v)}")
110
+
111
+ except KeyboardInterrupt:
112
+ print("Stopping...")
113
+ return 2
114
+
115
+ except Exception:
116
+ traceback.print_exc()
117
+ return 1
118
+
119
+
120
+ if __name__ == "__main__":
121
+ sys.exit(main())
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # Copyright (c) 2024, Ryan Galloway (ryan@rsgalloway.com)
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # - Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # - Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # - Neither the name of the software nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software
17
+ # without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+
32
+ __doc__ = """
33
+ Contains default configs and settings.
34
+ """
35
+
36
+ import os
37
+ import sys
38
+ import platform
39
+
40
+ DEBUG = os.getenv("DEBUG")
41
+ DEFAULT_NAMESPACE = "stack"
42
+ LOG_LEVEL = int(os.environ.get("LOG_LEVEL", 20))
43
+ ON_POSIX = "posix" in sys.builtin_module_names
44
+ PLATFORM = platform.system().lower()
45
+ PYTHON_VERSION = sys.version_info[0]
46
+ USERNAME = os.getenv("USERNAME", os.getenv("USER"))
47
+
48
+ # default location of the global environment directory by platform
49
+ DEFAULT_ENV_DIR = os.getenv(
50
+ "DEFAULT_ENV_DIR",
51
+ {
52
+ "darwin": f"/etc/{DEFAULT_NAMESPACE}",
53
+ "linux": f"/etc/{DEFAULT_NAMESPACE}",
54
+ "windows": f"C:/ProgramData/{DEFAULT_NAMESPACE}",
55
+ }.get(PLATFORM),
56
+ )