Commits

Doug Hellmann committed a257f73

move make_hooks functionality into user_scripts, since they are related

  • Participants
  • Parent commits 2c46edf

Comments (0)

Files changed (3)

     entry_points = {
         #'console_scripts': [ 'venvw_hook = virtualenvwrapper.hook_loader:main' ],
         'virtualenvwrapper.initialize': [
-            'make_hooks = virtualenvwrapper.make_hooks:initialize',
+            'user_scripts = virtualenvwrapper.user_scripts:initialize',
             ],
         'virtualenvwrapper.initialize_source': [
             'user_scripts = virtualenvwrapper.user_scripts:initialize_source',
 
         'virtualenvwrapper.pre_mkvirtualenv': [
             'user_scripts = virtualenvwrapper.user_scripts:pre_mkvirtualenv',
-            'make_hooks = virtualenvwrapper.make_hooks:pre_mkvirtualenv',
             ],
         'virtualenvwrapper.post_mkvirtualenv_source': [
             'user_scripts = virtualenvwrapper.user_scripts:post_mkvirtualenv_source',

File virtualenvwrapper/make_hooks.py

-#!/usr/bin/env python
-# encoding: utf-8
-#
-# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
-#
-"""Plugin to create hooks during initialization phase.
-"""
-
-import logging
-import os
-import stat
-
-log = logging.getLogger(__name__)
-
-import pkg_resources
-
-PERMISSIONS = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
-
-GLOBAL_HOOKS = [
-    # initialize
-    ("initialize",
-     "This hook is run during the startup phase when loading virtualenvwrapper.sh."),
-
-    # mkvirtualenv
-    ("premkvirtualenv",
-     "This hook is run after a new virtualenv is created and before it is activated."),
-    ("postmkvirtualenv",
-     "This hook is run after a new virtualenv is activated."),
-
-    # rmvirtualenv
-    ("prermvirtualenv",
-     "This hook is run before a virtualenv is deleted."),
-    ("postrmvirtualenv",
-     "This hook is run after a virtualenv is deleted."),
-
-    # deactivate
-    ("predeactivate",
-     "This hook is run before every virtualenv is deactivated."),
-    ("postdeactivate",
-     "This hook is run after every virtualenv is deactivated."),
-
-    # activate
-    ("preactivate",
-     "This hook is run before every virtualenv is activated."),
-    ("postactivate",
-     "This hook is run after every virtualenv is activated."),
-    ]
-
-LOCAL_HOOKS = [
-    # deactivate
-    ("predeactivate",
-     "This hook is run before this virtualenv is deactivated."),
-    ("postdeactivate",
-     "This hook is run after this virtualenv is deactivated."),
-
-    # activate
-    ("preactivate",
-     "This hook is run before this virtualenv is activated."),
-    ("postactivate",
-     "This hook is run after this virtualenv is activated."),
-    ]
-
-def make_hook(filename, comment):
-    """Create a hook script.
-    
-    :param filename: The name of the file to write.
-    :param comment: The comment to insert into the file.
-    """
-    filename = os.path.expanduser(os.path.expandvars(filename))
-    if not os.path.exists(filename):
-        log.info('Creating %s', filename)
-        with open(filename, 'wt') as f:
-            f.write("""#!%(shell)s
-# %(comment)s
-
-""" % {'comment':comment, 'shell':os.environ.get('SHELL', '/bin/sh')})
-        os.chmod(filename, PERMISSIONS)
-    return
-
-
-def initialize(args):
-    for filename, comment in GLOBAL_HOOKS:
-        make_hook(os.path.join('$WORKON_HOME', filename), comment)
-    return
-
-def pre_mkvirtualenv(args):
-    envname=args[0]
-    for filename, comment in LOCAL_HOOKS:
-        make_hook(os.path.join('$WORKON_HOME', envname, 'bin', filename), comment)
-    return
-

File virtualenvwrapper/user_scripts.py

 
 import logging
 import os
+import stat
 import subprocess
 
 import pkg_resources
     return
 
 
+PERMISSIONS = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
+
+
+GLOBAL_HOOKS = [
+    # initialize
+    ("initialize",
+     "This hook is run during the startup phase when loading virtualenvwrapper.sh."),
+
+    # mkvirtualenv
+    ("premkvirtualenv",
+     "This hook is run after a new virtualenv is created and before it is activated."),
+    ("postmkvirtualenv",
+     "This hook is run after a new virtualenv is activated."),
+
+    # rmvirtualenv
+    ("prermvirtualenv",
+     "This hook is run before a virtualenv is deleted."),
+    ("postrmvirtualenv",
+     "This hook is run after a virtualenv is deleted."),
+
+    # deactivate
+    ("predeactivate",
+     "This hook is run before every virtualenv is deactivated."),
+    ("postdeactivate",
+     "This hook is run after every virtualenv is deactivated."),
+
+    # activate
+    ("preactivate",
+     "This hook is run before every virtualenv is activated."),
+    ("postactivate",
+     "This hook is run after every virtualenv is activated."),
+    ]
+
+
+LOCAL_HOOKS = [
+    # deactivate
+    ("predeactivate",
+     "This hook is run before this virtualenv is deactivated."),
+    ("postdeactivate",
+     "This hook is run after this virtualenv is deactivated."),
+
+    # activate
+    ("preactivate",
+     "This hook is run before this virtualenv is activated."),
+    ("postactivate",
+     "This hook is run after this virtualenv is activated."),
+    ]
+
+
+def make_hook(filename, comment):
+    """Create a hook script.
+    
+    :param filename: The name of the file to write.
+    :param comment: The comment to insert into the file.
+    """
+    filename = os.path.expanduser(os.path.expandvars(filename))
+    if not os.path.exists(filename):
+        log.info('Creating %s', filename)
+        with open(filename, 'wt') as f:
+            f.write("""#!%(shell)s
+# %(comment)s
+
+""" % {'comment':comment, 'shell':os.environ.get('SHELL', '/bin/sh')})
+        os.chmod(filename, PERMISSIONS)
+    return
+
+
 
 # HOOKS
 
+
+def initialize(args):
+    for filename, comment in GLOBAL_HOOKS:
+        make_hook(os.path.join('$WORKON_HOME', filename), comment)
+    return
+
+
 def initialize_source(args):
     return """
 #
 
 def pre_mkvirtualenv(args):
     log.debug('pre_mkvirtualenv %s', str(args))
+    envname=args[0]
+    for filename, comment in LOCAL_HOOKS:
+        make_hook(os.path.join('$WORKON_HOME', envname, 'bin', filename), comment)
     run_global('premkvirtualenv', *args)
     return