envstack 0.3.0__tar.gz → 0.4.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.
- {envstack-0.3.0 → envstack-0.4.0}/PKG-INFO +32 -11
- {envstack-0.3.0 → envstack-0.4.0}/README.md +31 -10
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/__init__.py +1 -1
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/cli.py +8 -1
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/config.py +22 -1
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/env.py +32 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/PKG-INFO +32 -11
- {envstack-0.3.0 → envstack-0.4.0}/setup.py +1 -1
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/exceptions.py +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/logger.py +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/path.py +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack/wrapper.py +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/SOURCES.txt +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/dependency_links.txt +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/entry_points.txt +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/not-zip-safe +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/requires.txt +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/lib/envstack.egg-info/top_level.txt +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/setup.cfg +0 -0
- {envstack-0.3.0 → envstack-0.4.0}/stack.env +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: envstack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Stacked environment variable management system.
|
|
5
5
|
Home-page: http://github.com/rsgalloway/envstack
|
|
6
6
|
Author: Ryan Galloway
|
|
@@ -22,8 +22,7 @@ a new `test` stack just create `test.env` files.
|
|
|
22
22
|
|
|
23
23
|
> **Note:** envstack works best combined with [siteconf](https://github.com/rsgalloway/siteconf).
|
|
24
24
|
|
|
25
|
-
Installation
|
|
26
|
-
------------
|
|
25
|
+
## Installation
|
|
27
26
|
|
|
28
27
|
The easiest way to install:
|
|
29
28
|
|
|
@@ -35,7 +34,7 @@ $ pip install envstack
|
|
|
35
34
|
|
|
36
35
|
Copy the default stack file
|
|
37
36
|
[`stack.env`](https://github.com/rsgalloway/envstack/blob/master/stack.env)
|
|
38
|
-
to your current working directory, the root of your project or
|
|
37
|
+
to your current working directory, the root of your project or `/etc/envstack` (the default location for envstack files, or `C:/ProgramData/envstack` on Windows).
|
|
39
38
|
|
|
40
39
|
|
|
41
40
|
```bach
|
|
@@ -62,7 +61,7 @@ Modify the environment stack by updating `stack.env` or by creating new contextu
|
|
|
62
61
|
You can execute any command inside the default stacked environment like this:
|
|
63
62
|
|
|
64
63
|
```bash
|
|
65
|
-
$
|
|
64
|
+
$ envstack -- <command>
|
|
66
65
|
```
|
|
67
66
|
|
|
68
67
|
For example:
|
|
@@ -112,7 +111,8 @@ linux:
|
|
|
112
111
|
HELLO: world
|
|
113
112
|
```
|
|
114
113
|
|
|
115
|
-
Environment files can include other namespaced environments
|
|
114
|
+
Environment files can include other namespaced environments (all stacks inherit the default stack.env automatically).
|
|
115
|
+
|
|
116
116
|
```yaml
|
|
117
117
|
include: ['other']
|
|
118
118
|
```
|
|
@@ -149,8 +149,7 @@ To see an environment stack on another platform:
|
|
|
149
149
|
$ envstack <stack> -p <platform>
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
Python API
|
|
153
|
-
----------
|
|
152
|
+
## Python API
|
|
154
153
|
|
|
155
154
|
By default, `envstack.getenv` uses the resolved default env stack `stack` and can be
|
|
156
155
|
a drop-in replacement for `os.getenv`
|
|
@@ -176,14 +175,13 @@ The `init` function also updates the current environment for code that is not us
|
|
|
176
175
|
'bar'
|
|
177
176
|
```
|
|
178
177
|
|
|
179
|
-
Running Commands
|
|
180
|
-
----------------
|
|
178
|
+
## Running Commands
|
|
181
179
|
|
|
182
180
|
To run any command line executable inside of an environment stack, where `<command>`
|
|
183
181
|
is the command to run:
|
|
184
182
|
|
|
185
183
|
```bash
|
|
186
|
-
$
|
|
184
|
+
$ envstack <stack> -- <command>
|
|
187
185
|
```
|
|
188
186
|
|
|
189
187
|
For example, running python in the default stack (reading from the default `stack.env` file):
|
|
@@ -199,3 +197,26 @@ Same command but using the "thing" stack"
|
|
|
199
197
|
$ envstack thing -- python -c "import os; print(os.environ['FOO'])"
|
|
200
198
|
bar
|
|
201
199
|
```
|
|
200
|
+
|
|
201
|
+
To source the environment in your current shell, source the output of --export (and create
|
|
202
|
+
an alias for convenience):
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
$ source <(envstack --export)
|
|
206
|
+
$ alias esinit='source <(envstack $ARG --export)'
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
In Windows command prompt:
|
|
210
|
+
|
|
211
|
+
```cmd
|
|
212
|
+
for /f "usebackq" %i in (`envstack --export`) do %i
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Config
|
|
216
|
+
|
|
217
|
+
Default config settings are in the config.py module. The following environment variables are supported:
|
|
218
|
+
|
|
219
|
+
| Variable | Description |
|
|
220
|
+
|---------------------|-------------|
|
|
221
|
+
| $DEFAULT_ENV_DIR | the folder containing the default env stack files |
|
|
222
|
+
| $DEFAULT_ENV_STACK | the name of the default env stack namespace (default "stack") |
|
|
@@ -11,8 +11,7 @@ a new `test` stack just create `test.env` files.
|
|
|
11
11
|
|
|
12
12
|
> **Note:** envstack works best combined with [siteconf](https://github.com/rsgalloway/siteconf).
|
|
13
13
|
|
|
14
|
-
Installation
|
|
15
|
-
------------
|
|
14
|
+
## Installation
|
|
16
15
|
|
|
17
16
|
The easiest way to install:
|
|
18
17
|
|
|
@@ -24,7 +23,7 @@ $ pip install envstack
|
|
|
24
23
|
|
|
25
24
|
Copy the default stack file
|
|
26
25
|
[`stack.env`](https://github.com/rsgalloway/envstack/blob/master/stack.env)
|
|
27
|
-
to your current working directory, the root of your project or
|
|
26
|
+
to your current working directory, the root of your project or `/etc/envstack` (the default location for envstack files, or `C:/ProgramData/envstack` on Windows).
|
|
28
27
|
|
|
29
28
|
|
|
30
29
|
```bach
|
|
@@ -51,7 +50,7 @@ Modify the environment stack by updating `stack.env` or by creating new contextu
|
|
|
51
50
|
You can execute any command inside the default stacked environment like this:
|
|
52
51
|
|
|
53
52
|
```bash
|
|
54
|
-
$
|
|
53
|
+
$ envstack -- <command>
|
|
55
54
|
```
|
|
56
55
|
|
|
57
56
|
For example:
|
|
@@ -101,7 +100,8 @@ linux:
|
|
|
101
100
|
HELLO: world
|
|
102
101
|
```
|
|
103
102
|
|
|
104
|
-
Environment files can include other namespaced environments
|
|
103
|
+
Environment files can include other namespaced environments (all stacks inherit the default stack.env automatically).
|
|
104
|
+
|
|
105
105
|
```yaml
|
|
106
106
|
include: ['other']
|
|
107
107
|
```
|
|
@@ -138,8 +138,7 @@ To see an environment stack on another platform:
|
|
|
138
138
|
$ envstack <stack> -p <platform>
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
Python API
|
|
142
|
-
----------
|
|
141
|
+
## Python API
|
|
143
142
|
|
|
144
143
|
By default, `envstack.getenv` uses the resolved default env stack `stack` and can be
|
|
145
144
|
a drop-in replacement for `os.getenv`
|
|
@@ -165,14 +164,13 @@ The `init` function also updates the current environment for code that is not us
|
|
|
165
164
|
'bar'
|
|
166
165
|
```
|
|
167
166
|
|
|
168
|
-
Running Commands
|
|
169
|
-
----------------
|
|
167
|
+
## Running Commands
|
|
170
168
|
|
|
171
169
|
To run any command line executable inside of an environment stack, where `<command>`
|
|
172
170
|
is the command to run:
|
|
173
171
|
|
|
174
172
|
```bash
|
|
175
|
-
$
|
|
173
|
+
$ envstack <stack> -- <command>
|
|
176
174
|
```
|
|
177
175
|
|
|
178
176
|
For example, running python in the default stack (reading from the default `stack.env` file):
|
|
@@ -188,3 +186,26 @@ Same command but using the "thing" stack"
|
|
|
188
186
|
$ envstack thing -- python -c "import os; print(os.environ['FOO'])"
|
|
189
187
|
bar
|
|
190
188
|
```
|
|
189
|
+
|
|
190
|
+
To source the environment in your current shell, source the output of --export (and create
|
|
191
|
+
an alias for convenience):
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
$ source <(envstack --export)
|
|
195
|
+
$ alias esinit='source <(envstack $ARG --export)'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
In Windows command prompt:
|
|
199
|
+
|
|
200
|
+
```cmd
|
|
201
|
+
for /f "usebackq" %i in (`envstack --export`) do %i
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Config
|
|
205
|
+
|
|
206
|
+
Default config settings are in the config.py module. The following environment variables are supported:
|
|
207
|
+
|
|
208
|
+
| Variable | Description |
|
|
209
|
+
|---------------------|-------------|
|
|
210
|
+
| $DEFAULT_ENV_DIR | the folder containing the default env stack files |
|
|
211
|
+
| $DEFAULT_ENV_STACK | the name of the default env stack namespace (default "stack") |
|
|
@@ -40,7 +40,7 @@ import sys
|
|
|
40
40
|
import traceback
|
|
41
41
|
|
|
42
42
|
from envstack import __version__, config
|
|
43
|
-
from envstack.env import build_sources, expandvars, load_environ, trace_var
|
|
43
|
+
from envstack.env import build_sources, expandvars, export, load_environ, trace_var
|
|
44
44
|
from envstack.wrapper import run_command
|
|
45
45
|
|
|
46
46
|
|
|
@@ -75,6 +75,11 @@ def parse_args():
|
|
|
75
75
|
default=config.DEFAULT_NAMESPACE,
|
|
76
76
|
help="the environment stack to use (default '%s')" % config.DEFAULT_NAMESPACE,
|
|
77
77
|
)
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"--export",
|
|
80
|
+
action="store_true",
|
|
81
|
+
help="generate export commands for the current shell",
|
|
82
|
+
)
|
|
78
83
|
parser.add_argument(
|
|
79
84
|
"-p",
|
|
80
85
|
"--platform",
|
|
@@ -123,6 +128,8 @@ def main():
|
|
|
123
128
|
sources = build_sources(args.namespace)
|
|
124
129
|
for source in sources:
|
|
125
130
|
print(source)
|
|
131
|
+
elif args.export:
|
|
132
|
+
print(export(args.namespace, config.SHELL))
|
|
126
133
|
elif command:
|
|
127
134
|
return run_command(args.namespace, command)
|
|
128
135
|
else:
|
|
@@ -37,12 +37,33 @@ import os
|
|
|
37
37
|
import platform
|
|
38
38
|
import sys
|
|
39
39
|
|
|
40
|
+
|
|
41
|
+
def detect_shell():
|
|
42
|
+
"""Detect the current shell."""
|
|
43
|
+
if PLATFORM == "windows":
|
|
44
|
+
comspec = os.environ.get("ComSpec")
|
|
45
|
+
if comspec:
|
|
46
|
+
if "cmd.exe" in comspec:
|
|
47
|
+
return "cmd"
|
|
48
|
+
elif "powershell.exe" in comspec:
|
|
49
|
+
return "pwsh"
|
|
50
|
+
else:
|
|
51
|
+
return "unknown"
|
|
52
|
+
else:
|
|
53
|
+
shell = os.environ.get("SHELL")
|
|
54
|
+
if shell:
|
|
55
|
+
return shell.split("/")[-1]
|
|
56
|
+
else:
|
|
57
|
+
return "unknown"
|
|
58
|
+
|
|
59
|
+
|
|
40
60
|
DEBUG = os.getenv("DEBUG")
|
|
41
|
-
DEFAULT_NAMESPACE = "stack"
|
|
61
|
+
DEFAULT_NAMESPACE = os.getenv("DEFAULT_ENV_STACK", "stack")
|
|
42
62
|
LOG_LEVEL = int(os.environ.get("LOG_LEVEL", 20))
|
|
43
63
|
ON_POSIX = "posix" in sys.builtin_module_names
|
|
44
64
|
PLATFORM = platform.system().lower()
|
|
45
65
|
PYTHON_VERSION = sys.version_info[0]
|
|
66
|
+
SHELL = detect_shell()
|
|
46
67
|
USERNAME = os.getenv("USERNAME", os.getenv("USER"))
|
|
47
68
|
|
|
48
69
|
# default location of the global env stacks
|
|
@@ -494,6 +494,38 @@ def expandvars(var, env=None, recursive=False):
|
|
|
494
494
|
return EnvVar(var).expand(env, recursive=recursive)
|
|
495
495
|
|
|
496
496
|
|
|
497
|
+
def export(name, shell="bash", resolve=False, scope=None):
|
|
498
|
+
"""Returns environment commands that can be sourced.
|
|
499
|
+
|
|
500
|
+
$ source <(envstack --export)
|
|
501
|
+
|
|
502
|
+
List of shell names: bash, tcsh, cmd, pwsh
|
|
503
|
+
(see output of config.detect_shell()).
|
|
504
|
+
|
|
505
|
+
:param name: stack namespace
|
|
506
|
+
:param shell: name of shell (default: bash)
|
|
507
|
+
:param resolve: resolve values (default: True)
|
|
508
|
+
:param scope: environment scope (default: cwd)
|
|
509
|
+
:returns: shell commands as string
|
|
510
|
+
"""
|
|
511
|
+
env = load_environ(name, scope=scope)
|
|
512
|
+
expList = list()
|
|
513
|
+
for k, v in env.items():
|
|
514
|
+
if resolve:
|
|
515
|
+
v = expandvars(v, env, recursive=False)
|
|
516
|
+
if shell == "bash":
|
|
517
|
+
expList.append('export {0}="{1}"'.format(k, v))
|
|
518
|
+
elif shell == "tcsh":
|
|
519
|
+
expList.append('setenv {0}:"{1}"'.format(k, v))
|
|
520
|
+
elif shell == "cmd":
|
|
521
|
+
expList.append('set {0}="{1}"'.format(k, v))
|
|
522
|
+
elif shell == "pwsh":
|
|
523
|
+
expList.append('$env:{0}="{1}"'.format(k, v))
|
|
524
|
+
expList.sort()
|
|
525
|
+
exp = "\n".join(expList)
|
|
526
|
+
return exp
|
|
527
|
+
|
|
528
|
+
|
|
497
529
|
def init(name=config.DEFAULT_NAMESPACE):
|
|
498
530
|
"""Initializes the environment for a given namespace.
|
|
499
531
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: envstack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Stacked environment variable management system.
|
|
5
5
|
Home-page: http://github.com/rsgalloway/envstack
|
|
6
6
|
Author: Ryan Galloway
|
|
@@ -22,8 +22,7 @@ a new `test` stack just create `test.env` files.
|
|
|
22
22
|
|
|
23
23
|
> **Note:** envstack works best combined with [siteconf](https://github.com/rsgalloway/siteconf).
|
|
24
24
|
|
|
25
|
-
Installation
|
|
26
|
-
------------
|
|
25
|
+
## Installation
|
|
27
26
|
|
|
28
27
|
The easiest way to install:
|
|
29
28
|
|
|
@@ -35,7 +34,7 @@ $ pip install envstack
|
|
|
35
34
|
|
|
36
35
|
Copy the default stack file
|
|
37
36
|
[`stack.env`](https://github.com/rsgalloway/envstack/blob/master/stack.env)
|
|
38
|
-
to your current working directory, the root of your project or
|
|
37
|
+
to your current working directory, the root of your project or `/etc/envstack` (the default location for envstack files, or `C:/ProgramData/envstack` on Windows).
|
|
39
38
|
|
|
40
39
|
|
|
41
40
|
```bach
|
|
@@ -62,7 +61,7 @@ Modify the environment stack by updating `stack.env` or by creating new contextu
|
|
|
62
61
|
You can execute any command inside the default stacked environment like this:
|
|
63
62
|
|
|
64
63
|
```bash
|
|
65
|
-
$
|
|
64
|
+
$ envstack -- <command>
|
|
66
65
|
```
|
|
67
66
|
|
|
68
67
|
For example:
|
|
@@ -112,7 +111,8 @@ linux:
|
|
|
112
111
|
HELLO: world
|
|
113
112
|
```
|
|
114
113
|
|
|
115
|
-
Environment files can include other namespaced environments
|
|
114
|
+
Environment files can include other namespaced environments (all stacks inherit the default stack.env automatically).
|
|
115
|
+
|
|
116
116
|
```yaml
|
|
117
117
|
include: ['other']
|
|
118
118
|
```
|
|
@@ -149,8 +149,7 @@ To see an environment stack on another platform:
|
|
|
149
149
|
$ envstack <stack> -p <platform>
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
Python API
|
|
153
|
-
----------
|
|
152
|
+
## Python API
|
|
154
153
|
|
|
155
154
|
By default, `envstack.getenv` uses the resolved default env stack `stack` and can be
|
|
156
155
|
a drop-in replacement for `os.getenv`
|
|
@@ -176,14 +175,13 @@ The `init` function also updates the current environment for code that is not us
|
|
|
176
175
|
'bar'
|
|
177
176
|
```
|
|
178
177
|
|
|
179
|
-
Running Commands
|
|
180
|
-
----------------
|
|
178
|
+
## Running Commands
|
|
181
179
|
|
|
182
180
|
To run any command line executable inside of an environment stack, where `<command>`
|
|
183
181
|
is the command to run:
|
|
184
182
|
|
|
185
183
|
```bash
|
|
186
|
-
$
|
|
184
|
+
$ envstack <stack> -- <command>
|
|
187
185
|
```
|
|
188
186
|
|
|
189
187
|
For example, running python in the default stack (reading from the default `stack.env` file):
|
|
@@ -199,3 +197,26 @@ Same command but using the "thing" stack"
|
|
|
199
197
|
$ envstack thing -- python -c "import os; print(os.environ['FOO'])"
|
|
200
198
|
bar
|
|
201
199
|
```
|
|
200
|
+
|
|
201
|
+
To source the environment in your current shell, source the output of --export (and create
|
|
202
|
+
an alias for convenience):
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
$ source <(envstack --export)
|
|
206
|
+
$ alias esinit='source <(envstack $ARG --export)'
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
In Windows command prompt:
|
|
210
|
+
|
|
211
|
+
```cmd
|
|
212
|
+
for /f "usebackq" %i in (`envstack --export`) do %i
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Config
|
|
216
|
+
|
|
217
|
+
Default config settings are in the config.py module. The following environment variables are supported:
|
|
218
|
+
|
|
219
|
+
| Variable | Description |
|
|
220
|
+
|---------------------|-------------|
|
|
221
|
+
| $DEFAULT_ENV_DIR | the folder containing the default env stack files |
|
|
222
|
+
| $DEFAULT_ENV_STACK | the name of the default env stack namespace (default "stack") |
|
|
@@ -71,7 +71,7 @@ class PostInstallCommand(install):
|
|
|
71
71
|
|
|
72
72
|
setup(
|
|
73
73
|
name="envstack",
|
|
74
|
-
version="0.
|
|
74
|
+
version="0.4.0",
|
|
75
75
|
description="Stacked environment variable management system.",
|
|
76
76
|
long_description=long_description,
|
|
77
77
|
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
|