envstack 0.5.0__tar.gz → 0.5.2__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.
- {envstack-0.5.0 → envstack-0.5.2}/PKG-INFO +54 -45
- {envstack-0.5.0 → envstack-0.5.2}/README.md +53 -44
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/__init__.py +1 -1
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/config.py +3 -1
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/env.py +70 -44
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/wrapper.py +1 -1
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/PKG-INFO +54 -45
- {envstack-0.5.0 → envstack-0.5.2}/setup.py +1 -1
- {envstack-0.5.0 → envstack-0.5.2}/stack.env +1 -1
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/cli.py +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/exceptions.py +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/logger.py +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack/path.py +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/SOURCES.txt +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/dependency_links.txt +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/entry_points.txt +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/not-zip-safe +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/requires.txt +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/lib/envstack.egg-info/top_level.txt +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/setup.cfg +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/tests/test_env.py +0 -0
- {envstack-0.5.0 → envstack-0.5.2}/tests/test_path.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: envstack
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: Stacked environment variable management system.
|
|
5
5
|
Home-page: http://github.com/rsgalloway/envstack
|
|
6
6
|
Author: Ryan Galloway
|
|
@@ -15,9 +15,9 @@ Stacked environment variable management system. The lightweight, easy to use
|
|
|
15
15
|
"rez" alternative for production pipelines.
|
|
16
16
|
|
|
17
17
|
Environment variables are declared in namespaced .env files using yaml syntax.
|
|
18
|
-
The default stack declares env variables in `stack.env` files. You can create
|
|
19
|
-
new stack by creating new `.env` files, e.g. to create a new `thing` stack
|
|
20
|
-
create `thing.env` files in any given context.
|
|
18
|
+
The default stack declares env variables in `stack.env` files. You can create
|
|
19
|
+
any new stack by creating new `.env` files, e.g. to create a new `thing` stack
|
|
20
|
+
just create `thing.env` files in any given context.
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
23
23
|
|
|
@@ -35,11 +35,15 @@ $ cd envstack
|
|
|
35
35
|
$ python setup.py install
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
The install process will automatically attempt to install the default
|
|
39
|
-
|
|
38
|
+
The install process will automatically attempt to install the default
|
|
39
|
+
`stack.env` file to the default env file directory defined `$DEFAULT_ENV_DIR`.
|
|
40
|
+
**Note:** The [siteconf](https://github.com/rsgalloway/siteconf)
|
|
41
|
+
sitecustomize.py module may override `$DEFAULT_ENV_DIR`.
|
|
40
42
|
|
|
41
|
-
If installing from source, you can use
|
|
42
|
-
|
|
43
|
+
If installing from source, you can use
|
|
44
|
+
[distman](https://github.com/rsgalloway/distman) to
|
|
45
|
+
install envstack and the default `stack.env` file using the provided
|
|
46
|
+
`dist.json` file:
|
|
43
47
|
|
|
44
48
|
```bash
|
|
45
49
|
$ distman
|
|
@@ -47,8 +51,8 @@ $ distman
|
|
|
47
51
|
|
|
48
52
|
## Quickstart
|
|
49
53
|
|
|
50
|
-
The `stack` namespace is the default environment stack. Running the `envstack`
|
|
51
|
-
should show you the default environment stack:
|
|
54
|
+
The `stack` namespace is the default environment stack. Running the `envstack`
|
|
55
|
+
command should show you the default environment stack:
|
|
52
56
|
|
|
53
57
|
```bash
|
|
54
58
|
$ envstack
|
|
@@ -60,30 +64,18 @@ DEPLOY_ROOT=${ROOT}/${ENV}
|
|
|
60
64
|
ROOT=${HOME}/.local/envstack
|
|
61
65
|
```
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
You can execute any command inside the default stacked environment like this:
|
|
67
|
+
You can override anything in the environment stack by setting values in the
|
|
68
|
+
local environment first:
|
|
67
69
|
|
|
68
70
|
```bash
|
|
69
|
-
$ envstack --
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
have to escape it first to it's not pre-expanded in the shell):
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
$ envstack -- echo \$HELLO
|
|
77
|
-
world
|
|
71
|
+
$ envstack -- echo \$ENV
|
|
72
|
+
prod
|
|
73
|
+
$ ENV=dev envstack -- echo \$ENV
|
|
74
|
+
dev
|
|
78
75
|
```
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
$ envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
85
|
-
world
|
|
86
|
-
```
|
|
77
|
+
Modify the environment stack by editing `stack.env` or by creating new
|
|
78
|
+
contextual `stack.env` files up on the filesystem.
|
|
87
79
|
|
|
88
80
|
## Creating Stacks
|
|
89
81
|
|
|
@@ -102,7 +94,8 @@ $ envstack thing
|
|
|
102
94
|
FOO 'bar'
|
|
103
95
|
```
|
|
104
96
|
|
|
105
|
-
Variables can reference other variables defined elsewhere (but cannot be
|
|
97
|
+
Variables can reference other variables defined elsewhere (but cannot be
|
|
98
|
+
circular):
|
|
106
99
|
|
|
107
100
|
```yaml
|
|
108
101
|
all: &default
|
|
@@ -117,7 +110,8 @@ linux:
|
|
|
117
110
|
HELLO: world
|
|
118
111
|
```
|
|
119
112
|
|
|
120
|
-
Environment files can include other namespaced environments (all stacks inherit
|
|
113
|
+
Environment files can include other namespaced environments (all stacks inherit
|
|
114
|
+
the default stack.env automatically).
|
|
121
115
|
|
|
122
116
|
```yaml
|
|
123
117
|
include: ['other']
|
|
@@ -125,8 +119,9 @@ include: ['other']
|
|
|
125
119
|
|
|
126
120
|
## Context
|
|
127
121
|
|
|
128
|
-
Environment stacks are hierarchical, so values for `$FOO` defined in .env files
|
|
129
|
-
in the filesystem (lower in scope) override those defined higher up
|
|
122
|
+
Environment stacks are hierarchical, so values for `$FOO` defined in .env files
|
|
123
|
+
lower in the filesystem (lower in scope) override those defined higher up
|
|
124
|
+
(higher in scope):
|
|
130
125
|
|
|
131
126
|
```
|
|
132
127
|
${DEFAULT_ENV_DIR}
|
|
@@ -140,7 +135,6 @@ ${DEFAULT_ENV_DIR}
|
|
|
140
135
|
If you are working in the task directory, those envstack $VARs will override the
|
|
141
136
|
$VARs defined in the shot, seq, show and root directories.
|
|
142
137
|
|
|
143
|
-
|
|
144
138
|
## Usage
|
|
145
139
|
|
|
146
140
|
To see the default environment for any given stack:
|
|
@@ -177,8 +171,8 @@ To init the environment stack, use the `init` function:
|
|
|
177
171
|
'bar'
|
|
178
172
|
```
|
|
179
173
|
|
|
180
|
-
Alternatively, `envstack.getenv` uses the default environment stack `stack` and
|
|
181
|
-
a drop-in replacement for `os.getenv`
|
|
174
|
+
Alternatively, `envstack.getenv` uses the default environment stack `stack` and
|
|
175
|
+
can be a drop-in replacement for `os.getenv`
|
|
182
176
|
|
|
183
177
|
```python
|
|
184
178
|
>>> import envstack
|
|
@@ -188,20 +182,34 @@ a drop-in replacement for `os.getenv`
|
|
|
188
182
|
|
|
189
183
|
## Running Commands
|
|
190
184
|
|
|
191
|
-
To run any command line executable inside of an environment stack, where
|
|
192
|
-
is the command to run:
|
|
185
|
+
To run any command line executable inside of an environment stack, where
|
|
186
|
+
`[COMMAND]` is the command to run:
|
|
193
187
|
|
|
194
188
|
```bash
|
|
195
189
|
$ envstack [STACK] -- [COMMAND]
|
|
196
190
|
```
|
|
197
191
|
|
|
198
|
-
For example
|
|
192
|
+
For example:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
$ envstack -- echo \$HELLO
|
|
196
|
+
world
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Running Python commands in the default stack:
|
|
199
200
|
|
|
200
201
|
```bash
|
|
201
202
|
$ envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
202
203
|
world
|
|
203
204
|
```
|
|
204
205
|
|
|
206
|
+
Overriding values in the stack:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
$ HELLO=goodbye envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
210
|
+
goodbye
|
|
211
|
+
```
|
|
212
|
+
|
|
205
213
|
Same command but using the "thing" stack"
|
|
206
214
|
|
|
207
215
|
```bash
|
|
@@ -209,12 +217,12 @@ $ envstack thing -- python -c "import os; print(os.environ['FOO'])"
|
|
|
209
217
|
bar
|
|
210
218
|
```
|
|
211
219
|
|
|
212
|
-
To source the environment in your current shell, source the output of --export
|
|
213
|
-
an alias for convenience):
|
|
220
|
+
To source the environment in your current shell, source the output of --export
|
|
221
|
+
(and create an alias for convenience):
|
|
214
222
|
|
|
215
223
|
```bash
|
|
216
224
|
$ source <(envstack --export)
|
|
217
|
-
$ alias
|
|
225
|
+
$ alias stack='source <(envstack $ARG --export)'
|
|
218
226
|
```
|
|
219
227
|
|
|
220
228
|
In Windows command prompt:
|
|
@@ -225,9 +233,10 @@ for /f "usebackq" %i in (`envstack --export`) do %i
|
|
|
225
233
|
|
|
226
234
|
## Config
|
|
227
235
|
|
|
228
|
-
Default config settings are in the config.py module. The following environment
|
|
236
|
+
Default config settings are in the config.py module. The following environment
|
|
237
|
+
variables are supported:
|
|
229
238
|
|
|
230
239
|
| Variable | Description |
|
|
231
240
|
|---------------------|-------------|
|
|
232
241
|
| $DEFAULT_ENV_DIR | the folder containing the default env stack files |
|
|
233
|
-
| $DEFAULT_ENV_STACK | the name of the default env stack namespace
|
|
242
|
+
| $DEFAULT_ENV_STACK | the name of the default env stack namespace |
|
|
@@ -5,9 +5,9 @@ Stacked environment variable management system. The lightweight, easy to use
|
|
|
5
5
|
"rez" alternative for production pipelines.
|
|
6
6
|
|
|
7
7
|
Environment variables are declared in namespaced .env files using yaml syntax.
|
|
8
|
-
The default stack declares env variables in `stack.env` files. You can create
|
|
9
|
-
new stack by creating new `.env` files, e.g. to create a new `thing` stack
|
|
10
|
-
create `thing.env` files in any given context.
|
|
8
|
+
The default stack declares env variables in `stack.env` files. You can create
|
|
9
|
+
any new stack by creating new `.env` files, e.g. to create a new `thing` stack
|
|
10
|
+
just create `thing.env` files in any given context.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -25,11 +25,15 @@ $ cd envstack
|
|
|
25
25
|
$ python setup.py install
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
The install process will automatically attempt to install the default
|
|
29
|
-
|
|
28
|
+
The install process will automatically attempt to install the default
|
|
29
|
+
`stack.env` file to the default env file directory defined `$DEFAULT_ENV_DIR`.
|
|
30
|
+
**Note:** The [siteconf](https://github.com/rsgalloway/siteconf)
|
|
31
|
+
sitecustomize.py module may override `$DEFAULT_ENV_DIR`.
|
|
30
32
|
|
|
31
|
-
If installing from source, you can use
|
|
32
|
-
|
|
33
|
+
If installing from source, you can use
|
|
34
|
+
[distman](https://github.com/rsgalloway/distman) to
|
|
35
|
+
install envstack and the default `stack.env` file using the provided
|
|
36
|
+
`dist.json` file:
|
|
33
37
|
|
|
34
38
|
```bash
|
|
35
39
|
$ distman
|
|
@@ -37,8 +41,8 @@ $ distman
|
|
|
37
41
|
|
|
38
42
|
## Quickstart
|
|
39
43
|
|
|
40
|
-
The `stack` namespace is the default environment stack. Running the `envstack`
|
|
41
|
-
should show you the default environment stack:
|
|
44
|
+
The `stack` namespace is the default environment stack. Running the `envstack`
|
|
45
|
+
command should show you the default environment stack:
|
|
42
46
|
|
|
43
47
|
```bash
|
|
44
48
|
$ envstack
|
|
@@ -50,30 +54,18 @@ DEPLOY_ROOT=${ROOT}/${ENV}
|
|
|
50
54
|
ROOT=${HOME}/.local/envstack
|
|
51
55
|
```
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
You can execute any command inside the default stacked environment like this:
|
|
57
|
+
You can override anything in the environment stack by setting values in the
|
|
58
|
+
local environment first:
|
|
57
59
|
|
|
58
60
|
```bash
|
|
59
|
-
$ envstack --
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
have to escape it first to it's not pre-expanded in the shell):
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
$ envstack -- echo \$HELLO
|
|
67
|
-
world
|
|
61
|
+
$ envstack -- echo \$ENV
|
|
62
|
+
prod
|
|
63
|
+
$ ENV=dev envstack -- echo \$ENV
|
|
64
|
+
dev
|
|
68
65
|
```
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
$ envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
75
|
-
world
|
|
76
|
-
```
|
|
67
|
+
Modify the environment stack by editing `stack.env` or by creating new
|
|
68
|
+
contextual `stack.env` files up on the filesystem.
|
|
77
69
|
|
|
78
70
|
## Creating Stacks
|
|
79
71
|
|
|
@@ -92,7 +84,8 @@ $ envstack thing
|
|
|
92
84
|
FOO 'bar'
|
|
93
85
|
```
|
|
94
86
|
|
|
95
|
-
Variables can reference other variables defined elsewhere (but cannot be
|
|
87
|
+
Variables can reference other variables defined elsewhere (but cannot be
|
|
88
|
+
circular):
|
|
96
89
|
|
|
97
90
|
```yaml
|
|
98
91
|
all: &default
|
|
@@ -107,7 +100,8 @@ linux:
|
|
|
107
100
|
HELLO: world
|
|
108
101
|
```
|
|
109
102
|
|
|
110
|
-
Environment files can include other namespaced environments (all stacks inherit
|
|
103
|
+
Environment files can include other namespaced environments (all stacks inherit
|
|
104
|
+
the default stack.env automatically).
|
|
111
105
|
|
|
112
106
|
```yaml
|
|
113
107
|
include: ['other']
|
|
@@ -115,8 +109,9 @@ include: ['other']
|
|
|
115
109
|
|
|
116
110
|
## Context
|
|
117
111
|
|
|
118
|
-
Environment stacks are hierarchical, so values for `$FOO` defined in .env files
|
|
119
|
-
in the filesystem (lower in scope) override those defined higher up
|
|
112
|
+
Environment stacks are hierarchical, so values for `$FOO` defined in .env files
|
|
113
|
+
lower in the filesystem (lower in scope) override those defined higher up
|
|
114
|
+
(higher in scope):
|
|
120
115
|
|
|
121
116
|
```
|
|
122
117
|
${DEFAULT_ENV_DIR}
|
|
@@ -130,7 +125,6 @@ ${DEFAULT_ENV_DIR}
|
|
|
130
125
|
If you are working in the task directory, those envstack $VARs will override the
|
|
131
126
|
$VARs defined in the shot, seq, show and root directories.
|
|
132
127
|
|
|
133
|
-
|
|
134
128
|
## Usage
|
|
135
129
|
|
|
136
130
|
To see the default environment for any given stack:
|
|
@@ -167,8 +161,8 @@ To init the environment stack, use the `init` function:
|
|
|
167
161
|
'bar'
|
|
168
162
|
```
|
|
169
163
|
|
|
170
|
-
Alternatively, `envstack.getenv` uses the default environment stack `stack` and
|
|
171
|
-
a drop-in replacement for `os.getenv`
|
|
164
|
+
Alternatively, `envstack.getenv` uses the default environment stack `stack` and
|
|
165
|
+
can be a drop-in replacement for `os.getenv`
|
|
172
166
|
|
|
173
167
|
```python
|
|
174
168
|
>>> import envstack
|
|
@@ -178,20 +172,34 @@ a drop-in replacement for `os.getenv`
|
|
|
178
172
|
|
|
179
173
|
## Running Commands
|
|
180
174
|
|
|
181
|
-
To run any command line executable inside of an environment stack, where
|
|
182
|
-
is the command to run:
|
|
175
|
+
To run any command line executable inside of an environment stack, where
|
|
176
|
+
`[COMMAND]` is the command to run:
|
|
183
177
|
|
|
184
178
|
```bash
|
|
185
179
|
$ envstack [STACK] -- [COMMAND]
|
|
186
180
|
```
|
|
187
181
|
|
|
188
|
-
For example
|
|
182
|
+
For example:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
$ envstack -- echo \$HELLO
|
|
186
|
+
world
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Running Python commands in the default stack:
|
|
189
190
|
|
|
190
191
|
```bash
|
|
191
192
|
$ envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
192
193
|
world
|
|
193
194
|
```
|
|
194
195
|
|
|
196
|
+
Overriding values in the stack:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
$ HELLO=goodbye envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
200
|
+
goodbye
|
|
201
|
+
```
|
|
202
|
+
|
|
195
203
|
Same command but using the "thing" stack"
|
|
196
204
|
|
|
197
205
|
```bash
|
|
@@ -199,12 +207,12 @@ $ envstack thing -- python -c "import os; print(os.environ['FOO'])"
|
|
|
199
207
|
bar
|
|
200
208
|
```
|
|
201
209
|
|
|
202
|
-
To source the environment in your current shell, source the output of --export
|
|
203
|
-
an alias for convenience):
|
|
210
|
+
To source the environment in your current shell, source the output of --export
|
|
211
|
+
(and create an alias for convenience):
|
|
204
212
|
|
|
205
213
|
```bash
|
|
206
214
|
$ source <(envstack --export)
|
|
207
|
-
$ alias
|
|
215
|
+
$ alias stack='source <(envstack $ARG --export)'
|
|
208
216
|
```
|
|
209
217
|
|
|
210
218
|
In Windows command prompt:
|
|
@@ -215,9 +223,10 @@ for /f "usebackq" %i in (`envstack --export`) do %i
|
|
|
215
223
|
|
|
216
224
|
## Config
|
|
217
225
|
|
|
218
|
-
Default config settings are in the config.py module. The following environment
|
|
226
|
+
Default config settings are in the config.py module. The following environment
|
|
227
|
+
variables are supported:
|
|
219
228
|
|
|
220
229
|
| Variable | Description |
|
|
221
230
|
|---------------------|-------------|
|
|
222
231
|
| $DEFAULT_ENV_DIR | the folder containing the default env stack files |
|
|
223
|
-
| $DEFAULT_ENV_STACK | the name of the default env stack namespace
|
|
232
|
+
| $DEFAULT_ENV_STACK | the name of the default env stack namespace |
|
|
@@ -84,5 +84,7 @@ DEFAULT_ENV_DIR = os.getenv(
|
|
|
84
84
|
"darwin": "{HOME}/Library/Application Support/envstack",
|
|
85
85
|
"linux": "{HOME}/.local/envstack",
|
|
86
86
|
"windows": "C:\\ProgramData\\envstack",
|
|
87
|
-
}
|
|
87
|
+
}
|
|
88
|
+
.get(PLATFORM)
|
|
89
|
+
.format(**DEFAULT_ENV),
|
|
88
90
|
)
|
|
@@ -261,21 +261,12 @@ class Env(dict):
|
|
|
261
261
|
return self.get(key, resolved=False).template
|
|
262
262
|
|
|
263
263
|
def merge(self, env):
|
|
264
|
-
"""Merges another
|
|
264
|
+
"""Merges another env into this one, i.e. env[k] will replace self[k].
|
|
265
265
|
|
|
266
266
|
:param env: env to merge into this one
|
|
267
267
|
"""
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if isinstance(value, str):
|
|
271
|
-
# replace ${KEY} vars with values from env
|
|
272
|
-
value = re.sub(
|
|
273
|
-
r"\${(\w+)}",
|
|
274
|
-
lambda match: env.get(match.group(1), match.group(0)),
|
|
275
|
-
value,
|
|
276
|
-
)
|
|
277
|
-
merged[key] = value
|
|
278
|
-
return merged
|
|
268
|
+
for k, v in env.items():
|
|
269
|
+
self[k] = v
|
|
279
270
|
|
|
280
271
|
def set_namespace(self, name):
|
|
281
272
|
"""Stores the namespace for this environment.
|
|
@@ -406,16 +397,17 @@ def build_sources(
|
|
|
406
397
|
includes=True,
|
|
407
398
|
default=config.DEFAULT_NAMESPACE,
|
|
408
399
|
):
|
|
409
|
-
"""Builds the list of env source files for a given name.
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
/
|
|
416
|
-
/show/
|
|
417
|
-
/show/seq/
|
|
418
|
-
/show/seq/shot/
|
|
400
|
+
"""Builds the list of env source files for a given name. Where the source
|
|
401
|
+
is in the list of sources depends on its position in the directory tree.
|
|
402
|
+
Lower scope sources will override higher scope sources, with the default
|
|
403
|
+
source at the lowest scope position:
|
|
404
|
+
|
|
405
|
+
$DEFAULT_ENV_DIR/stack.env
|
|
406
|
+
/stack.env
|
|
407
|
+
/show/stack.env
|
|
408
|
+
/show/seq/stack.env
|
|
409
|
+
/show/seq/shot/stack.env
|
|
410
|
+
/show/seq/shot/task/stack.env
|
|
419
411
|
|
|
420
412
|
:param name: namespace (base name of .env file).
|
|
421
413
|
:param scope: environment scope (default: cwd).
|
|
@@ -424,37 +416,47 @@ def build_sources(
|
|
|
424
416
|
:returns: list of source files sorted by scope.
|
|
425
417
|
"""
|
|
426
418
|
|
|
427
|
-
#
|
|
419
|
+
# list of source .env files
|
|
428
420
|
sources = []
|
|
429
421
|
|
|
422
|
+
# list of included .env files
|
|
423
|
+
include_sources = []
|
|
424
|
+
|
|
430
425
|
# scope, or root, of env tree
|
|
431
426
|
path = scope or os.getcwd()
|
|
432
427
|
scope = Scope(scope)
|
|
433
428
|
level, levels = 0, len(scope.levels())
|
|
434
429
|
|
|
435
|
-
# the namespaced and default env file names
|
|
430
|
+
# the namespaced and default .env file names
|
|
436
431
|
named_env = f"{name}.env"
|
|
437
432
|
default_env = f"{default}.env"
|
|
438
433
|
|
|
439
434
|
def add_source(path):
|
|
435
|
+
"""Adds a source to the list of sources."""
|
|
440
436
|
if not os.path.exists(path):
|
|
441
437
|
return
|
|
442
438
|
if not sources or (sources[0].path != path):
|
|
443
|
-
|
|
444
|
-
sources.insert(0,
|
|
445
|
-
return
|
|
439
|
+
this_source = Source(path)
|
|
440
|
+
sources.insert(0, this_source)
|
|
441
|
+
return this_source
|
|
446
442
|
|
|
447
|
-
|
|
443
|
+
def add_includes(src):
|
|
444
|
+
"""Adds included sources to the list of sources and includes."""
|
|
445
|
+
included = [f"{i}.env" for i in src.includes()]
|
|
446
|
+
for include_env in included:
|
|
447
|
+
include_file = os.path.join(config.DEFAULT_ENV_DIR, include_env)
|
|
448
|
+
if include_env not in include_sources:
|
|
449
|
+
include_sources.append(include_env)
|
|
450
|
+
add_source(include_file)
|
|
451
|
+
|
|
452
|
+
# walk up the directory tree looking for .env files
|
|
448
453
|
while level < levels:
|
|
449
454
|
named_file = os.path.join(path, named_env)
|
|
450
455
|
src = add_source(named_file)
|
|
451
456
|
if src and includes:
|
|
452
|
-
|
|
453
|
-
for include_env in included:
|
|
454
|
-
include_file = os.path.join(path, include_env)
|
|
455
|
-
add_source(include_file)
|
|
457
|
+
add_includes(src)
|
|
456
458
|
|
|
457
|
-
# look for a default env file in this scope
|
|
459
|
+
# look for a default .env file in this scope
|
|
458
460
|
default_file = os.path.join(path, default_env)
|
|
459
461
|
add_source(default_file)
|
|
460
462
|
|
|
@@ -464,18 +466,22 @@ def build_sources(
|
|
|
464
466
|
|
|
465
467
|
level += 1
|
|
466
468
|
|
|
467
|
-
#
|
|
468
|
-
|
|
469
|
-
|
|
469
|
+
# look for default include .env files (and their includes)
|
|
470
|
+
for include_source in include_sources:
|
|
471
|
+
default_inc_src = add_source(
|
|
472
|
+
os.path.join(config.DEFAULT_ENV_DIR, include_source)
|
|
473
|
+
)
|
|
474
|
+
if default_inc_src and includes:
|
|
475
|
+
add_includes(default_inc_src)
|
|
476
|
+
|
|
477
|
+
# check for default .env file
|
|
478
|
+
default_src = add_source(os.path.join(config.DEFAULT_ENV_DIR, named_env))
|
|
470
479
|
|
|
471
480
|
# add included sources
|
|
472
|
-
if
|
|
473
|
-
|
|
474
|
-
for include_env in included:
|
|
475
|
-
include_file = os.path.join(config.DEFAULT_ENV_DIR, include_env)
|
|
476
|
-
add_source(include_file)
|
|
481
|
+
if default_src and includes:
|
|
482
|
+
add_includes(default_src)
|
|
477
483
|
|
|
478
|
-
# check for global default env file
|
|
484
|
+
# check for global default .env file
|
|
479
485
|
global_default = os.path.join(config.DEFAULT_ENV_DIR, default_env)
|
|
480
486
|
add_source(global_default)
|
|
481
487
|
|
|
@@ -583,7 +589,7 @@ def load_environ(
|
|
|
583
589
|
|
|
584
590
|
# merge values from given environment
|
|
585
591
|
if environ:
|
|
586
|
-
|
|
592
|
+
return merge(env, environ)
|
|
587
593
|
|
|
588
594
|
return env
|
|
589
595
|
|
|
@@ -620,11 +626,31 @@ def load_file(path):
|
|
|
620
626
|
return data
|
|
621
627
|
|
|
622
628
|
|
|
629
|
+
def merge(env, other):
|
|
630
|
+
"""Merges values from other into env. For example, to merge values from
|
|
631
|
+
the local environment into an env instance:
|
|
632
|
+
|
|
633
|
+
>>> merge(env, os.environ)
|
|
634
|
+
|
|
635
|
+
To merge values from env into the local environment:
|
|
636
|
+
|
|
637
|
+
>>> merge(os.environ, env)
|
|
638
|
+
|
|
639
|
+
:param env: source env
|
|
640
|
+
:param other: env to merge
|
|
641
|
+
:returns: merged env
|
|
642
|
+
"""
|
|
643
|
+
merged = env.copy()
|
|
644
|
+
for key in merged:
|
|
645
|
+
if key in other:
|
|
646
|
+
merged[key] = other.get(key)
|
|
647
|
+
return merged
|
|
648
|
+
|
|
649
|
+
|
|
623
650
|
def safe_eval(value):
|
|
624
651
|
"""Returns template value preserving original class.
|
|
625
652
|
Useful for preserving nested values in wrappers.
|
|
626
653
|
"""
|
|
627
|
-
|
|
628
654
|
try:
|
|
629
655
|
from ast import literal_eval
|
|
630
656
|
|
|
@@ -95,7 +95,7 @@ class Wrapper(object):
|
|
|
95
95
|
# get subprocess env, cmd and args
|
|
96
96
|
env = self.get_subprocess_env()
|
|
97
97
|
cmd = expandvars(self.executable(), env, recursive=True)
|
|
98
|
-
args = " ".join(["
|
|
98
|
+
args = " ".join(['"%s"' % arg for arg in to_args(cmd) + self.args])
|
|
99
99
|
|
|
100
100
|
# run command in subprocess
|
|
101
101
|
try:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: envstack
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: Stacked environment variable management system.
|
|
5
5
|
Home-page: http://github.com/rsgalloway/envstack
|
|
6
6
|
Author: Ryan Galloway
|
|
@@ -15,9 +15,9 @@ Stacked environment variable management system. The lightweight, easy to use
|
|
|
15
15
|
"rez" alternative for production pipelines.
|
|
16
16
|
|
|
17
17
|
Environment variables are declared in namespaced .env files using yaml syntax.
|
|
18
|
-
The default stack declares env variables in `stack.env` files. You can create
|
|
19
|
-
new stack by creating new `.env` files, e.g. to create a new `thing` stack
|
|
20
|
-
create `thing.env` files in any given context.
|
|
18
|
+
The default stack declares env variables in `stack.env` files. You can create
|
|
19
|
+
any new stack by creating new `.env` files, e.g. to create a new `thing` stack
|
|
20
|
+
just create `thing.env` files in any given context.
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
23
23
|
|
|
@@ -35,11 +35,15 @@ $ cd envstack
|
|
|
35
35
|
$ python setup.py install
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
The install process will automatically attempt to install the default
|
|
39
|
-
|
|
38
|
+
The install process will automatically attempt to install the default
|
|
39
|
+
`stack.env` file to the default env file directory defined `$DEFAULT_ENV_DIR`.
|
|
40
|
+
**Note:** The [siteconf](https://github.com/rsgalloway/siteconf)
|
|
41
|
+
sitecustomize.py module may override `$DEFAULT_ENV_DIR`.
|
|
40
42
|
|
|
41
|
-
If installing from source, you can use
|
|
42
|
-
|
|
43
|
+
If installing from source, you can use
|
|
44
|
+
[distman](https://github.com/rsgalloway/distman) to
|
|
45
|
+
install envstack and the default `stack.env` file using the provided
|
|
46
|
+
`dist.json` file:
|
|
43
47
|
|
|
44
48
|
```bash
|
|
45
49
|
$ distman
|
|
@@ -47,8 +51,8 @@ $ distman
|
|
|
47
51
|
|
|
48
52
|
## Quickstart
|
|
49
53
|
|
|
50
|
-
The `stack` namespace is the default environment stack. Running the `envstack`
|
|
51
|
-
should show you the default environment stack:
|
|
54
|
+
The `stack` namespace is the default environment stack. Running the `envstack`
|
|
55
|
+
command should show you the default environment stack:
|
|
52
56
|
|
|
53
57
|
```bash
|
|
54
58
|
$ envstack
|
|
@@ -60,30 +64,18 @@ DEPLOY_ROOT=${ROOT}/${ENV}
|
|
|
60
64
|
ROOT=${HOME}/.local/envstack
|
|
61
65
|
```
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
You can execute any command inside the default stacked environment like this:
|
|
67
|
+
You can override anything in the environment stack by setting values in the
|
|
68
|
+
local environment first:
|
|
67
69
|
|
|
68
70
|
```bash
|
|
69
|
-
$ envstack --
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
have to escape it first to it's not pre-expanded in the shell):
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
$ envstack -- echo \$HELLO
|
|
77
|
-
world
|
|
71
|
+
$ envstack -- echo \$ENV
|
|
72
|
+
prod
|
|
73
|
+
$ ENV=dev envstack -- echo \$ENV
|
|
74
|
+
dev
|
|
78
75
|
```
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
$ envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
85
|
-
world
|
|
86
|
-
```
|
|
77
|
+
Modify the environment stack by editing `stack.env` or by creating new
|
|
78
|
+
contextual `stack.env` files up on the filesystem.
|
|
87
79
|
|
|
88
80
|
## Creating Stacks
|
|
89
81
|
|
|
@@ -102,7 +94,8 @@ $ envstack thing
|
|
|
102
94
|
FOO 'bar'
|
|
103
95
|
```
|
|
104
96
|
|
|
105
|
-
Variables can reference other variables defined elsewhere (but cannot be
|
|
97
|
+
Variables can reference other variables defined elsewhere (but cannot be
|
|
98
|
+
circular):
|
|
106
99
|
|
|
107
100
|
```yaml
|
|
108
101
|
all: &default
|
|
@@ -117,7 +110,8 @@ linux:
|
|
|
117
110
|
HELLO: world
|
|
118
111
|
```
|
|
119
112
|
|
|
120
|
-
Environment files can include other namespaced environments (all stacks inherit
|
|
113
|
+
Environment files can include other namespaced environments (all stacks inherit
|
|
114
|
+
the default stack.env automatically).
|
|
121
115
|
|
|
122
116
|
```yaml
|
|
123
117
|
include: ['other']
|
|
@@ -125,8 +119,9 @@ include: ['other']
|
|
|
125
119
|
|
|
126
120
|
## Context
|
|
127
121
|
|
|
128
|
-
Environment stacks are hierarchical, so values for `$FOO` defined in .env files
|
|
129
|
-
in the filesystem (lower in scope) override those defined higher up
|
|
122
|
+
Environment stacks are hierarchical, so values for `$FOO` defined in .env files
|
|
123
|
+
lower in the filesystem (lower in scope) override those defined higher up
|
|
124
|
+
(higher in scope):
|
|
130
125
|
|
|
131
126
|
```
|
|
132
127
|
${DEFAULT_ENV_DIR}
|
|
@@ -140,7 +135,6 @@ ${DEFAULT_ENV_DIR}
|
|
|
140
135
|
If you are working in the task directory, those envstack $VARs will override the
|
|
141
136
|
$VARs defined in the shot, seq, show and root directories.
|
|
142
137
|
|
|
143
|
-
|
|
144
138
|
## Usage
|
|
145
139
|
|
|
146
140
|
To see the default environment for any given stack:
|
|
@@ -177,8 +171,8 @@ To init the environment stack, use the `init` function:
|
|
|
177
171
|
'bar'
|
|
178
172
|
```
|
|
179
173
|
|
|
180
|
-
Alternatively, `envstack.getenv` uses the default environment stack `stack` and
|
|
181
|
-
a drop-in replacement for `os.getenv`
|
|
174
|
+
Alternatively, `envstack.getenv` uses the default environment stack `stack` and
|
|
175
|
+
can be a drop-in replacement for `os.getenv`
|
|
182
176
|
|
|
183
177
|
```python
|
|
184
178
|
>>> import envstack
|
|
@@ -188,20 +182,34 @@ a drop-in replacement for `os.getenv`
|
|
|
188
182
|
|
|
189
183
|
## Running Commands
|
|
190
184
|
|
|
191
|
-
To run any command line executable inside of an environment stack, where
|
|
192
|
-
is the command to run:
|
|
185
|
+
To run any command line executable inside of an environment stack, where
|
|
186
|
+
`[COMMAND]` is the command to run:
|
|
193
187
|
|
|
194
188
|
```bash
|
|
195
189
|
$ envstack [STACK] -- [COMMAND]
|
|
196
190
|
```
|
|
197
191
|
|
|
198
|
-
For example
|
|
192
|
+
For example:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
$ envstack -- echo \$HELLO
|
|
196
|
+
world
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Running Python commands in the default stack:
|
|
199
200
|
|
|
200
201
|
```bash
|
|
201
202
|
$ envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
202
203
|
world
|
|
203
204
|
```
|
|
204
205
|
|
|
206
|
+
Overriding values in the stack:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
$ HELLO=goodbye envstack -- python -c "import os; print(os.environ['HELLO'])"
|
|
210
|
+
goodbye
|
|
211
|
+
```
|
|
212
|
+
|
|
205
213
|
Same command but using the "thing" stack"
|
|
206
214
|
|
|
207
215
|
```bash
|
|
@@ -209,12 +217,12 @@ $ envstack thing -- python -c "import os; print(os.environ['FOO'])"
|
|
|
209
217
|
bar
|
|
210
218
|
```
|
|
211
219
|
|
|
212
|
-
To source the environment in your current shell, source the output of --export
|
|
213
|
-
an alias for convenience):
|
|
220
|
+
To source the environment in your current shell, source the output of --export
|
|
221
|
+
(and create an alias for convenience):
|
|
214
222
|
|
|
215
223
|
```bash
|
|
216
224
|
$ source <(envstack --export)
|
|
217
|
-
$ alias
|
|
225
|
+
$ alias stack='source <(envstack $ARG --export)'
|
|
218
226
|
```
|
|
219
227
|
|
|
220
228
|
In Windows command prompt:
|
|
@@ -225,9 +233,10 @@ for /f "usebackq" %i in (`envstack --export`) do %i
|
|
|
225
233
|
|
|
226
234
|
## Config
|
|
227
235
|
|
|
228
|
-
Default config settings are in the config.py module. The following environment
|
|
236
|
+
Default config settings are in the config.py module. The following environment
|
|
237
|
+
variables are supported:
|
|
229
238
|
|
|
230
239
|
| Variable | Description |
|
|
231
240
|
|---------------------|-------------|
|
|
232
241
|
| $DEFAULT_ENV_DIR | the folder containing the default env stack files |
|
|
233
|
-
| $DEFAULT_ENV_STACK | the name of the default env stack namespace
|
|
242
|
+
| $DEFAULT_ENV_STACK | the name of the default env stack namespace |
|
|
@@ -74,7 +74,7 @@ class PostInstallCommand(install):
|
|
|
74
74
|
|
|
75
75
|
setup(
|
|
76
76
|
name="envstack",
|
|
77
|
-
version="0.5.
|
|
77
|
+
version="0.5.2",
|
|
78
78
|
description="Stacked environment variable management system.",
|
|
79
79
|
long_description=long_description,
|
|
80
80
|
long_description_content_type="text/markdown",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|