envstack 0.1.0__tar.gz → 0.2.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.
@@ -1,33 +1,38 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: envstack
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Stacked environment variable management system.
5
5
  Home-page: http://github.com/rsgalloway/envstack
6
6
  Author: Ryan Galloway
7
7
  Author-email: ryan@rsgalloway.com
8
8
  Description-Content-Type: text/markdown
9
- Requires-Dist: PyYAML==6.0.2
9
+ Requires-Dist: PyYAML>=5.1.2
10
+ Requires-Dist: siteconf>=0.1.3
10
11
 
11
12
  envstack
12
13
  ========
13
14
 
14
- Stacked environment variable management system.
15
+ Stacked environment variable management system. The lightweight, easy to use
16
+ "rez" alternative for production pipelines.
15
17
 
16
18
  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
+ The default stack is `stack` and variables are declared in `stack.env`
20
+ files. You can create any new stack by creating new `.env` files, e.g. creating
21
+ a new `test` stack just create `test.env` files.
22
+
23
+ Envstack works best combined with [siteconf](https://github.com/rsgalloway/siteconf).
19
24
 
20
25
  ## Quickstart
21
26
 
22
27
  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"):
28
+ For example, here is a simple `thing.env` file (the stack namespace is "thing"):
24
29
 
25
30
  ```yaml
26
31
  all: &default
27
32
  FOO: bar
28
33
  ```
29
34
 
30
- To see the resolved environment for the `thing` stack, run:
35
+ To see the resolved environment for the `thing` environment stack, run:
31
36
 
32
37
  ```bash
33
38
  $ envstack thing
@@ -84,23 +89,47 @@ $ envstack
84
89
  To see the resolved environment for a given namespace.
85
90
 
86
91
  ```bash
87
- $ envstack <namespace> [OPTIONS]
92
+ $ envstack <stack> [OPTIONS]
88
93
  ```
89
94
 
90
- To resolve a $VAR declaration for a given namespace:
95
+ To resolve a `$VAR` declaration for a given environment stack:
91
96
 
92
97
  ```bash
93
- $ envstack <namespace> -r <VAR>
98
+ $ envstack <stack> -r <VAR>
94
99
  ```
95
100
 
96
- To trace where a $VAR declaration is being set:
101
+ To trace where a `$VAR` declaration is being set:
97
102
 
98
103
  ```bash
99
- $ envstack <namespace> -t <VAR>
104
+ $ envstack <stack> -t <VAR>
100
105
  ```
101
106
 
102
107
  To see an environment stack on another platform:
103
108
 
104
109
  ```bash
105
- $ envstack <namespace> -p <platform>
110
+ $ envstack <stack> -p <platform>
111
+ ```
112
+
113
+ Running Commands
114
+ ----------------
115
+
116
+ To run any command line executable inside of an environment stack, where `<command>`
117
+ is the command to run:
118
+
119
+ ```bash
120
+ $ enstack <stack> -- <command>
121
+ ```
122
+
123
+ For example, running python in the default stack (reading from the default `stack.env` file):
124
+
125
+ ```bash
126
+ $ envstack -- python -c "from envstack.env import environ; print(environ['HELLO'])"
127
+ world
128
+ ```
129
+
130
+ Same command but using the "thing" stack"
131
+
132
+ ```bash
133
+ $ envstack thing -- python -c "from envstack.env import environ; print(environ['FOO'])"
134
+ bar
106
135
  ```
@@ -0,0 +1,124 @@
1
+ envstack
2
+ ========
3
+
4
+ Stacked environment variable management system. The lightweight, easy to use
5
+ "rez" alternative for production pipelines.
6
+
7
+ Environment variables are declared in namespaced .env files using yaml syntax.
8
+ The default stack is `stack` and variables are declared in `stack.env`
9
+ files. You can create any new stack by creating new `.env` files, e.g. creating
10
+ a new `test` stack just create `test.env` files.
11
+
12
+ Envstack works best combined with [siteconf](https://github.com/rsgalloway/siteconf).
13
+
14
+ ## Quickstart
15
+
16
+ To create a new environment stack, create a new namespaced .env file.
17
+ For example, here is a simple `thing.env` file (the stack namespace is "thing"):
18
+
19
+ ```yaml
20
+ all: &default
21
+ FOO: bar
22
+ ```
23
+
24
+ To see the resolved environment for the `thing` environment stack, run:
25
+
26
+ ```bash
27
+ $ envstack thing
28
+ FOO 'bar'
29
+ ```
30
+
31
+ Environment stacks are hierarchical, so values for `$FOO` defined in .env files lower
32
+ in the filesystem (lower in scope) override those defined higher up (higher in scope):
33
+
34
+ ```
35
+ /show/thing.env
36
+ /show/seq/thing.env
37
+ /show/seq/shot/thing.env
38
+ /show/seq/shot/task/thing.env
39
+ ```
40
+
41
+ Variables can reference other variables defined elsewhere (but cannot be circular):
42
+
43
+ ```yaml
44
+ all: &default
45
+ BAR: $FOO
46
+ ```
47
+
48
+ Variables can be platform specific (and inherit the defaults):
49
+
50
+ ```yaml
51
+ linux:
52
+ <<: *default
53
+ HELLO: world
54
+ ```
55
+
56
+ Environment files can include other namespaced environments:
57
+ ```yaml
58
+ include: ['other']
59
+ ```
60
+
61
+ Installation
62
+ ------------
63
+
64
+ The easiest way to install:
65
+
66
+ ```bash
67
+ $ pip install envstack
68
+ ```
69
+
70
+ ## Usage
71
+
72
+ To see the default resolved environment for any given scope (directory):
73
+
74
+ ```bash
75
+ $ envstack
76
+ ```
77
+
78
+ To see the resolved environment for a given namespace.
79
+
80
+ ```bash
81
+ $ envstack <stack> [OPTIONS]
82
+ ```
83
+
84
+ To resolve a `$VAR` declaration for a given environment stack:
85
+
86
+ ```bash
87
+ $ envstack <stack> -r <VAR>
88
+ ```
89
+
90
+ To trace where a `$VAR` declaration is being set:
91
+
92
+ ```bash
93
+ $ envstack <stack> -t <VAR>
94
+ ```
95
+
96
+ To see an environment stack on another platform:
97
+
98
+ ```bash
99
+ $ envstack <stack> -p <platform>
100
+ ```
101
+
102
+ Running Commands
103
+ ----------------
104
+
105
+ To run any command line executable inside of an environment stack, where `<command>`
106
+ is the command to run:
107
+
108
+ ```bash
109
+ $ enstack <stack> -- <command>
110
+ ```
111
+
112
+ For example, running python in the default stack (reading from the default `stack.env` file):
113
+
114
+ ```bash
115
+ $ envstack -- python -c "from envstack.env import environ; print(environ['HELLO'])"
116
+ world
117
+ ```
118
+
119
+ Same command but using the "thing" stack"
120
+
121
+ ```bash
122
+ $ envstack thing -- python -c "from envstack.env import environ; print(environ['FOO'])"
123
+ bar
124
+ ```
@@ -34,4 +34,4 @@ Stacked environment variable management system.
34
34
  """
35
35
 
36
36
  __prog__ = "envstack"
37
- __version__ = "0.1.0"
37
+ __version__ = "0.2.0"
@@ -33,6 +33,7 @@ __doc__ = """
33
33
  Contains command line interface for envstack.
34
34
  """
35
35
 
36
+ import argparse
36
37
  import os
37
38
  import sys
38
39
  import pprint
@@ -40,13 +41,24 @@ import traceback
40
41
 
41
42
  from envstack import __version__
42
43
  from envstack import config
43
- from envstack.env import expandvars, load_environ, trace_var
44
+ from envstack.env import expandvars, load_environ, trace_var, build_sources
45
+ from envstack.wrapper import run_command
44
46
 
45
47
 
46
48
  def parse_args():
47
- """Command line argument parser."""
49
+ """Command line argument parser.
48
50
 
49
- import argparse
51
+ Returns:
52
+ tuple: (args, command)
53
+ """
54
+
55
+ if "--" in sys.argv:
56
+ dash_index = sys.argv.index("--")
57
+ args_after_dash = sys.argv[dash_index + 1 :]
58
+ args_before_dash = sys.argv[1:dash_index]
59
+ else:
60
+ args_after_dash = []
61
+ args_before_dash = sys.argv[1:]
50
62
 
51
63
  parser = argparse.ArgumentParser(
52
64
  description=__doc__, formatter_class=argparse.RawTextHelpFormatter
@@ -59,10 +71,10 @@ def parse_args():
59
71
  )
60
72
  parser.add_argument(
61
73
  "namespace",
62
- metavar="NAMESPACE",
74
+ metavar="STACK",
63
75
  nargs="?",
64
76
  default=config.DEFAULT_NAMESPACE,
65
- help="the namespace to use",
77
+ help="the environment stack to use (default '%s')" % config.DEFAULT_NAMESPACE,
66
78
  )
67
79
  parser.add_argument(
68
80
  "-p",
@@ -77,6 +89,11 @@ def parse_args():
77
89
  metavar="VAR",
78
90
  help="resolve an environment variable",
79
91
  )
92
+ parser.add_argument(
93
+ "--sources",
94
+ action="store_true",
95
+ help="list the sources for a stack",
96
+ )
80
97
  parser.add_argument(
81
98
  "-t",
82
99
  "--trace",
@@ -84,14 +101,14 @@ def parse_args():
84
101
  help="trace where a variable is getting set",
85
102
  )
86
103
 
87
- args = parser.parse_args()
104
+ args = parser.parse_args(args_before_dash)
88
105
 
89
- return args, parser
106
+ return args, args_after_dash
90
107
 
91
108
 
92
109
  def main():
93
110
  """Main thread."""
94
- args, _ = parse_args()
111
+ args, command = parse_args()
95
112
 
96
113
  try:
97
114
  if args.resolve:
@@ -103,6 +120,12 @@ def main():
103
120
  elif args.trace:
104
121
  path = trace_var(args.namespace, args.trace)
105
122
  print("{0}: {1}".format(args.trace, path))
123
+ elif args.sources:
124
+ sources = build_sources(args.namespace)
125
+ for source in sources:
126
+ print(source)
127
+ elif command:
128
+ return run_command(args.namespace, command)
106
129
  else:
107
130
  env = load_environ(args.namespace, platform=args.platform, includes=True)
108
131
  for k, v in env.items():
@@ -35,6 +35,7 @@ Contains executable wrapper classes and functions.
35
35
 
36
36
  import os
37
37
  import subprocess
38
+ import traceback
38
39
 
39
40
  from envstack import logger
40
41
  from envstack.env import load_environ, expandvars
@@ -126,20 +127,19 @@ class Wrapper(object):
126
127
  """Launches the wrapped tool in a subprocess with env."""
127
128
  exitcode = 0
128
129
 
129
- # expand command vars before passing to subprocess
130
+ # expand and resolve command and environment vars
130
131
  cmd = expandvars(self.executable(), self.env, recursive=True)
132
+ env = encode(self.get_subprocess_env())
131
133
 
132
134
  # run command in subprocess
133
135
  try:
134
136
  process = subprocess.Popen(
135
137
  args=to_args(cmd) + self.args,
136
138
  bufsize=0,
137
- env=encode(self.get_subprocess_env()),
139
+ env=env,
138
140
  )
139
141
 
140
142
  except Exception as err:
141
- import traceback
142
-
143
143
  traceback.print_exc()
144
144
  exitcode = 1
145
145
 
@@ -157,3 +157,29 @@ class Wrapper(object):
157
157
  is called on the wrapper.
158
158
  """
159
159
  return self.env
160
+
161
+
162
+ class CommandWrapper(Wrapper):
163
+ """Wrapper class for running wrapped commands from the command-line."""
164
+
165
+ def __init__(self, name, args=[]):
166
+ super(CommandWrapper, self).__init__(name, args)
167
+ self.log.debug("running command [stack: %s] %s", name, args)
168
+ self.cmd = args[0]
169
+ self.args = args[1:]
170
+
171
+ def executable(self):
172
+ return self.cmd
173
+
174
+
175
+ def run_command(namespace, command):
176
+ """
177
+ Runs a given command with the given stack namespace.
178
+
179
+ :param namespace: stack namespace
180
+ :param command: command to run as arg list
181
+ :returns: exit code
182
+ """
183
+ logger.setup_stream_handler()
184
+ cmd = CommandWrapper(namespace, command)
185
+ return cmd.launch()
@@ -1,33 +1,38 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: envstack
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Stacked environment variable management system.
5
5
  Home-page: http://github.com/rsgalloway/envstack
6
6
  Author: Ryan Galloway
7
7
  Author-email: ryan@rsgalloway.com
8
8
  Description-Content-Type: text/markdown
9
- Requires-Dist: PyYAML==6.0.2
9
+ Requires-Dist: PyYAML>=5.1.2
10
+ Requires-Dist: siteconf>=0.1.3
10
11
 
11
12
  envstack
12
13
  ========
13
14
 
14
- Stacked environment variable management system.
15
+ Stacked environment variable management system. The lightweight, easy to use
16
+ "rez" alternative for production pipelines.
15
17
 
16
18
  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
+ The default stack is `stack` and variables are declared in `stack.env`
20
+ files. You can create any new stack by creating new `.env` files, e.g. creating
21
+ a new `test` stack just create `test.env` files.
22
+
23
+ Envstack works best combined with [siteconf](https://github.com/rsgalloway/siteconf).
19
24
 
20
25
  ## Quickstart
21
26
 
22
27
  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"):
28
+ For example, here is a simple `thing.env` file (the stack namespace is "thing"):
24
29
 
25
30
  ```yaml
26
31
  all: &default
27
32
  FOO: bar
28
33
  ```
29
34
 
30
- To see the resolved environment for the `thing` stack, run:
35
+ To see the resolved environment for the `thing` environment stack, run:
31
36
 
32
37
  ```bash
33
38
  $ envstack thing
@@ -84,23 +89,47 @@ $ envstack
84
89
  To see the resolved environment for a given namespace.
85
90
 
86
91
  ```bash
87
- $ envstack <namespace> [OPTIONS]
92
+ $ envstack <stack> [OPTIONS]
88
93
  ```
89
94
 
90
- To resolve a $VAR declaration for a given namespace:
95
+ To resolve a `$VAR` declaration for a given environment stack:
91
96
 
92
97
  ```bash
93
- $ envstack <namespace> -r <VAR>
98
+ $ envstack <stack> -r <VAR>
94
99
  ```
95
100
 
96
- To trace where a $VAR declaration is being set:
101
+ To trace where a `$VAR` declaration is being set:
97
102
 
98
103
  ```bash
99
- $ envstack <namespace> -t <VAR>
104
+ $ envstack <stack> -t <VAR>
100
105
  ```
101
106
 
102
107
  To see an environment stack on another platform:
103
108
 
104
109
  ```bash
105
- $ envstack <namespace> -p <platform>
110
+ $ envstack <stack> -p <platform>
111
+ ```
112
+
113
+ Running Commands
114
+ ----------------
115
+
116
+ To run any command line executable inside of an environment stack, where `<command>`
117
+ is the command to run:
118
+
119
+ ```bash
120
+ $ enstack <stack> -- <command>
121
+ ```
122
+
123
+ For example, running python in the default stack (reading from the default `stack.env` file):
124
+
125
+ ```bash
126
+ $ envstack -- python -c "from envstack.env import environ; print(environ['HELLO'])"
127
+ world
128
+ ```
129
+
130
+ Same command but using the "thing" stack"
131
+
132
+ ```bash
133
+ $ envstack thing -- python -c "from envstack.env import environ; print(environ['FOO'])"
134
+ bar
106
135
  ```
@@ -0,0 +1,2 @@
1
+ PyYAML>=5.1.2
2
+ siteconf>=0.1.3
@@ -38,7 +38,7 @@ with open(os.path.join(here, "README.md")) as f:
38
38
 
39
39
  setup(
40
40
  name="envstack",
41
- version="0.1.0",
41
+ version="0.2.0",
42
42
  description="Stacked environment variable management system.",
43
43
  long_description=long_description,
44
44
  long_description_content_type="text/markdown",
@@ -52,8 +52,6 @@ setup(
52
52
  "envstack = envstack.cli:main",
53
53
  ],
54
54
  },
55
- install_requires=[
56
- "PyYAML==6.0.2",
57
- ],
55
+ install_requires=open("requirements.txt").readlines(),
58
56
  zip_safe=False,
59
57
  )
envstack-0.1.0/README.md DELETED
@@ -1,96 +0,0 @@
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
- ```
@@ -1 +0,0 @@
1
- PyYAML==6.0.2
File without changes
File without changes
File without changes