envstack 0.1.1__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,26 +1,31 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: envstack
3
- Version: 0.1.1
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
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
@@ -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
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
  ```
@@ -1,16 +1,20 @@
1
1
  envstack
2
2
  ========
3
3
 
4
- Stacked environment variable management system.
4
+ Stacked environment variable management system. The lightweight, easy to use
5
+ "rez" alternative for production pipelines.
5
6
 
6
7
  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.
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).
9
13
 
10
14
  ## Quickstart
11
15
 
12
16
  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"):
17
+ For example, here is a simple `thing.env` file (the stack namespace is "thing"):
14
18
 
15
19
  ```yaml
16
20
  all: &default
@@ -74,23 +78,47 @@ $ envstack
74
78
  To see the resolved environment for a given namespace.
75
79
 
76
80
  ```bash
77
- $ envstack <namespace> [OPTIONS]
81
+ $ envstack <stack> [OPTIONS]
78
82
  ```
79
83
 
80
- To resolve a `$VAR` declaration for a given namespace:
84
+ To resolve a `$VAR` declaration for a given environment stack:
81
85
 
82
86
  ```bash
83
- $ envstack <namespace> -r <VAR>
87
+ $ envstack <stack> -r <VAR>
84
88
  ```
85
89
 
86
90
  To trace where a `$VAR` declaration is being set:
87
91
 
88
92
  ```bash
89
- $ envstack <namespace> -t <VAR>
93
+ $ envstack <stack> -t <VAR>
90
94
  ```
91
95
 
92
96
  To see an environment stack on another platform:
93
97
 
94
98
  ```bash
95
- $ envstack <namespace> -p <platform>
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
96
124
  ```
@@ -34,4 +34,4 @@ Stacked environment variable management system.
34
34
  """
35
35
 
36
36
  __prog__ = "envstack"
37
- __version__ = "0.1.1"
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,26 +1,31 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: envstack
3
- Version: 0.1.1
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
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
@@ -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
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.1",
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>=5.1.2",
57
- ],
55
+ install_requires=open("requirements.txt").readlines(),
58
56
  zip_safe=False,
59
57
  )
@@ -1 +0,0 @@
1
- PyYAML>=5.1.2
File without changes
File without changes
File without changes