Adding support for Python3 virtual environments and DelpoyConfig json formatting
2 files changed, 74 insertions(+), 8 deletions(-)

M djeploy/__init__.py
M djeploy/deploy.py
M djeploy/__init__.py +59 -2
@@ 1,10 1,12 @@ 
 import sys
-from djeploy.globals import set_env, djeploy_require, get_env, command
+import json
+from fabric.api import env
+from .globals import set_env, djeploy_require, get_env, command
 
 
 __version__ = '0.2.5-dev'
 
-__all__ = ['set_env', 'djeploy_require', 'get_env', 'command',]
+__all__ = ['set_env', 'djeploy_require', 'get_env', 'command', 'DeployConfig']
 
 
 default_configs = {

          
@@ 17,6 19,10 @@ default_configs = {
     'releases_dirname': 'releases', # directory name to store the releases
     'num_releases': 5, # number of old deploys to leave on server
 
+    # Virtual Environment options
+    'venv_type': 'virtualenv', # Other option is 'python3' (uses -m venv)
+    'python3_bin': 'python3', # ie, python3.6, /crazy/path/to/python3.6
+
     # Ops module settings
     'space_options': {
         'default': lambda: command.abort('No space option was provided.'),

          
@@ 46,3 52,54 @@ default_configs = {
     'initd_use_pty': False,
 }
 set_env(**default_configs)
+
+
+class DeployConfig(object):
+    _data = {}
+
+    def __init__(self, config_file='fabconfig.json'):
+        self.config_file = config_file
+        self.load_config()
+        self._global_vars()
+
+    def load_config(self):
+        self._data = json.load(open(self.config_file))
+
+    def _global_vars(self):
+        if 'global' in self._data:
+            self.load_global(self._data['global'])
+
+        if 'fab' in self._data:
+            self.load_fab(self._data['fab'])
+
+        if 'djeploy' in self._data:
+            self.load_djeploy(self._data['djeploy'])
+
+    def load_global(self, data):
+        for k, v in data.items():
+            setattr(self, k, v)
+
+    def load_fab(self, data):
+        for k, v in data.items():
+            setattr(env, k, v)
+
+    def load_djeploy(self, data):
+        set_env(**data)
+
+    def load_space(self, space):
+        if 'spaces' not in self._data:
+            raise ValueError(
+                'Invalid json config provided. No spaces element.'
+            )
+
+        if space not in self._data['spaces']:
+            raise ValueError(
+                'No {0} element in spaces.'.format(space)
+            )
+
+        # Load all space section overrides. Options are global, fab, & djeploy
+        for key in self._data['spaces'][space].keys():
+            key_data = self._data['spaces'][space][key]
+            if key_data and hasattr(self, 'load_{0}'.format(key)):
+                func = getattr(self, 'load_{0}'.format(key))
+                func(key_data)

          
M djeploy/deploy.py +15 -6
@@ 141,8 141,10 @@ def make_virtual_environment(extra_path=
                              python=None, env_dir='env'):
     ''' Create the virtual environment
     '''
-    opts = get_env('release_path')
+    opts = get_env('release_path', 'venv_type', 'python3_bin')
     release_path = opts['release_path']
+    venv_type = opts['venv_type']
+    python3_bin = opts['python3_bin']
 
     if extra_path is not None:
         release_path = os.path.join(release_path, extra_path)

          
@@ 151,11 153,18 @@ def make_virtual_environment(extra_path=
         # Sanity check
         env_dir = '.'
 
-    cmd = 'virtualenv '
-    if not site_pkgs:
-        cmd += '--no-site-packages '
-    if python is not None:
-        cmd += '-p %s ' % python
+    if venv_type == 'virtualenv':
+        cmd = 'virtualenv '
+        if not site_pkgs:
+            cmd += '--no-site-packages '
+        if python is not None:
+            cmd += '-p {0} '.format(python)
+    else:
+        # Pass in custom path by using the python variable
+        cmd = '{0} -m venv '.format(python or python3_bin)
+        if site_pkgs:
+            cmd += '--system-site-packages '
+
     cmd += env_dir
 
     if not command.exists(release_path):