Doug Hellmann avatar Doug Hellmann committed 2625df9

pep8 cleanup

Comments (0)

Files changed (4)

 [tox]
-envlist = py27,py26,py32
+envlist = py27,py26,py32,pep8
 
 [testenv]
 commands = bash ./tests/run_tests {envdir} []
 setenv =
     TOXIC = true
 
+[testenv:pep8]
+deps = pep8==1.1
+commands = pep8 --ignore=E501 --repeat --show-source virtualenvwrapper
+
+
 # Not sure why this is needed, but on my system if it isn't included then
 # the python version picked up for 2.6 is actually 2.7.
 # IF THIS CAUSES YOU A PROBLEM COMMENT IT OUT BEFORE RUNNING THE TESTS.

virtualenvwrapper/hook_loader.py

 from stevedore import ExtensionManager
 from stevedore import NamedExtensionManager
 
+LOG_FORMAT = '%(asctime)s %(levelname)s %(name)s %(message)s'
+
 
 class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
-    """Taken from http://stackoverflow.com/questions/1407474/does-python-logging-handlers-rotatingfilehandler-allow-creation-of-a-group-writa
+    """Taken from http://stackoverflow.com/questions/1407474
     """
     def _open(self):
         prevumask = os.umask(0o002)
         description='Manage hooks for virtualenvwrapper',
         )
 
-    parser.add_option('-S', '--script',
-                      help='Runs "hook" then "<hook>_source", writing the ' +
-                           'result to <file>',
-                      dest='script_filename',
-                      default=None,
-                      )
-    parser.add_option('-s', '--source',
-                      help='Print the shell commands to be run in the current shell',
-                      action='store_true',
-                      dest='sourcing',
-                      default=False,
-                      )
-    parser.add_option('-l', '--list',
-                      help='Print a list of the plugins available for the given hook',
-                      action='store_true',
-                      default=False,
-                      dest='listing',
-                      )
-    parser.add_option('-v', '--verbose',
-                      help='Show more information on the console',
-                      action='store_const',
-                      const=2,
-                      default=1,
-                      dest='verbose_level',
-                      )
-    parser.add_option('-q', '--quiet',
-                      help='Show less information on the console',
-                      action='store_const',
-                      const=0,
-                      dest='verbose_level',
-                      )
-    parser.add_option('-n', '--name',
-                      help='Only run the hook from the named plugin',
-                      action='append',
-                      dest='names',
-                      default=[],
-                      )
-    parser.disable_interspersed_args()  # stop when we hit an option without an '-'
+    parser.add_option(
+        '-S', '--script',
+        help='Runs "hook" then "<hook>_source", writing the ' +
+        'result to <file>',
+        dest='script_filename',
+        default=None,
+        )
+    parser.add_option(
+        '-s', '--source',
+        help='Print the shell commands to be run in the current shell',
+        action='store_true',
+        dest='sourcing',
+        default=False,
+        )
+    parser.add_option(
+        '-l', '--list',
+        help='Print a list of the plugins available for the given hook',
+        action='store_true',
+        default=False,
+        dest='listing',
+        )
+    parser.add_option(
+        '-v', '--verbose',
+        help='Show more information on the console',
+        action='store_const',
+        const=2,
+        default=1,
+        dest='verbose_level',
+        )
+    parser.add_option(
+        '-q', '--quiet',
+        help='Show less information on the console',
+        action='store_const',
+        const=0,
+        dest='verbose_level',
+        )
+    parser.add_option(
+        '-n', '--name',
+        help='Only run the hook from the named plugin',
+        action='append',
+        dest='names',
+        default=[],
+        )
+    parser.disable_interspersed_args()  # stop when on option without an '-'
     options, args = parser.parse_args()
 
     root_logger = logging.getLogger('')
     # Set up logging to a file
     root_logger.setLevel(logging.DEBUG)
     file_handler = GroupWriteRotatingFileHandler(
-        os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR', 'hook.log')),
+        os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR',
+                                        'hook.log')),
         maxBytes=10240,
         backupCount=1,
         )
-    formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
+    formatter = logging.Formatter(LOG_FORMAT)
     file_handler.setFormatter(formatter)
     root_logger.addHandler(file_handler)
 
     run_hooks(hook, options, args)
 
     if options.script_filename:
-        log.debug('Saving sourcable %s hooks to %s', hook, options.script_filename)
+        log.debug('Saving sourcable %s hooks to %s',
+                  hook, options.script_filename)
         options.sourcing = True
         output = open(options.script_filename, "w")
         try:
 
     if options.listing:
         def show(ext):
-            output.write('  %-10s -- %s\n' % (ext.name, inspect.getdoc(ext.plugin) or ''))
+            output.write('  %-10s -- %s\n' %
+                         (ext.name, inspect.getdoc(ext.plugin) or ''))
         hook_mgr.map(show)
 
     elif options.sourcing:

virtualenvwrapper/project.py

 import logging
 import os
 
-import pkg_resources
-
 from virtualenvwrapper.user_scripts import make_hook, run_global
 
 log = logging.getLogger(__name__)
      "This hook is run after a project is deleted."),
     ]
 
+
 def initialize(args):
     """Set up user hooks
     """
 
 def pre_mkproject(args):
     log.debug('pre_mkproject %s', str(args))
-    envname=args[0]
+    envname = args[0]
     run_global('premkproject', *args)
     return
 
+
 def post_mkproject_source(args):
     return """
 #
 [ -f "$WORKON_HOME/postmkproject" ] && source "$WORKON_HOME/postmkproject"
 """
 
+
 def post_activate_source(args):
     return """
 #

virtualenvwrapper/user_scripts.py

 import subprocess
 import sys
 
-import pkg_resources
 
 log = logging.getLogger(__name__)
 
-    
 # Are we running under msys
-if sys.platform == 'win32' and os.environ.get('OS') == 'Windows_NT' and os.environ.get('MSYSTEM') == 'MINGW32':
+if (sys.platform == 'win32'
+    and
+    os.environ.get('OS') == 'Windows_NT'
+    and
+    os.environ.get('MSYSTEM') == 'MINGW32'):
     is_msys = True
     script_folder = 'Scripts'
 else:
     if os.path.exists(script_path):
         cmd = [script_path] + list(args)
         if is_msys:
-            cmd = [get_path(os.environ['MSYS_HOME'],'bin','sh.exe')] + cmd
+            cmd = [get_path(os.environ['MSYS_HOME'], 'bin', 'sh.exe')] + cmd
         log.debug('running %s', str(cmd))
         try:
-            return_code = subprocess.call(cmd)
+            subprocess.call(cmd)
         except OSError:
-            _,  msg, _ = sys.exc_info()
+            _, msg, _ = sys.exc_info()
             log.error('could not run "%s": %s', script_path, str(msg))
         #log.debug('Returned %s', return_code)
     return
 
     # get_env_details
     ("get_env_details",
-     "This hook is run when the list of virtualenvs is printed so each name can include details."),
+     "This hook is run when the list of virtualenvs is printed "
+     "so each name can include details."),
     ]
 
 
 
     # get_env_details
     ("get_env_details",
-     "This hook is run when the list of virtualenvs is printed in 'long' mode so each name can include details."),
+     "This hook is run when the list of virtualenvs is printed "
+     "in 'long' mode so each name can include details."),
     ]
 
 
 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.
     """
             f.write("""#!%(shell)s
 # %(comment)s
 
-""" % {'comment':comment, 'shell':os.environ.get('SHELL', '/bin/sh')})
+""" % {'comment': comment,
+       'shell': os.environ.get('SHELL', '/bin/sh'),
+       })
         finally:
             f.close()
         os.chmod(filename, PERMISSIONS)
     return
 
 
-
 # HOOKS
 
 
 [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
 """
 
+
 def pre_mkvirtualenv(args):
     log.debug('pre_mkvirtualenv %s', str(args))
-    envname=args[0]
+    envname = args[0]
     for filename, comment in LOCAL_HOOKS:
         make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
     run_global('premkvirtualenv', *args)
 [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
 """
 
+
 def pre_cpvirtualenv(args):
     log.debug('pre_cpvirtualenv %s', str(args))
-    envname=args[0]
+    envname = args[0]
     for filename, comment in LOCAL_HOOKS:
         make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
     run_global('precpvirtualenv', *args)
 [ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
 [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
 unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
-""" % { 'env_name':args[0] }
+""" % {'env_name': args[0]}
 
 
 def get_env_details(args):
     run_script(script_path, *args)
     return
 
+
 def get_path(*args):
     '''
     Get a full path from args.
-    Path separator is determined according to the os and the shell and allow to use is_msys.
+
+    Path separator is determined according to the os and the shell and
+    allow to use is_msys.
+
     Variables and user are expanded during the process.
     '''
     path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
         # MSYS accept unix or Win32 and sometimes it drives to mixed style paths
         if re.match(r'^/[a-zA-Z](/|^)', path):
             # msys path could starts with '/c/'-form drive letter
-            path = ''.join((path[1],':',path[2:]))
+            path = ''.join((path[1], ':', path[2:]))
         path = path.replace('/', os.sep)
-        
+
     return os.path.abspath(path)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.