Commits

Doug Hellmann committed eab3675

use flake8 instead of pep8 for style checking

Comments (0)

Files changed (5)

docs/source/history.rst

     caused by that rotating behavior, especially when the wrappers are
     being used by users with different permissions and
     umasks. (:bbissue:`152`)
+  - Use flake8 for style checking.
 
 3.6.1
 
 [tox]
-envlist = py27,py26,py32,pep8
+envlist = py27,py26,py32,style
 
 [testenv]
 commands = bash ./tests/run_tests {envdir} []
 setenv =
     TOXIC = true
 
-[testenv:pep8]
-deps = pep8==1.1
-commands = pep8 --ignore=E501 --repeat --show-source virtualenvwrapper
+[testenv:style]
+deps = flake8
+commands = flake8 virtualenvwrapper
 
 
 # Not sure why this is needed, but on my system if it isn't included then

virtualenvwrapper/hook_loader.py

         usage='usage: %prog [options] <hook> [<arguments>]',
         prog='virtualenvwrapper.hook_loader',
         description='Manage hooks for virtualenvwrapper',
-        )
+    )
 
     parser.add_option(
         '-S', '--script',
         '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',
         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()
 
             logfile,
             maxBytes=10240,
             backupCount=1,
-            )
+        )
         formatter = logging.Formatter(LOG_FORMAT)
         file_handler.setFormatter(formatter)
         root_logger.addHandler(file_handler)
 def list_hooks(output=None):
     if output is None:
         output = sys.stdout
-    for hook in itertools.chain(
-        ('_'.join(h)
-         for h in itertools.product(['pre', 'post'],
-                                    ['mkvirtualenv',
-                                     'rmvirtualenv',
-                                     'activate',
-                                     'deactivate',
-                                     'cpvirtualenv',
-                                     ])
-         ),
-        ['initialize',
-         'get_env_details',
-         'project.pre_mkproject',
-         'project.post_mkproject',
-         'project.template',
-         ]
-        ):
+    static_names = [
+        'initialize',
+        'get_env_details',
+        'project.pre_mkproject',
+        'project.post_mkproject',
+        'project.template',
+    ]
+    pre_post_hooks = (
+        '_'.join(h)
+        for h in itertools.product(['pre', 'post'],
+                                   ['mkvirtualenv',
+                                    'rmvirtualenv',
+                                    'activate',
+                                    'deactivate',
+                                    'cpvirtualenv',
+                                    ])
+    )
+    for hook in itertools.chain(static_names, pre_post_hooks):
         output.write(hook + '\n')
 
 

virtualenvwrapper/project.py

 GLOBAL_HOOKS = [
     # mkproject
     ("premkproject",
-     "This hook is run after a new project is created and before it is activated."),
+     "This hook is run after a new project is created "
+     "and before it is activated."),
     ("postmkproject",
      "This hook is run after a new project is activated."),
 
      "This hook is run before a project is deleted."),
     ("postrmproject",
      "This hook is run after a project is deleted."),
-    ]
+]
 
 
 def initialize(args):
     """Set up user hooks
     """
     for filename, comment in GLOBAL_HOOKS:
-        make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
+        make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename),
+                  comment)
     return
 
 
 def pre_mkproject(args):
     log.debug('pre_mkproject %s', str(args))
-    envname = args[0]
     run_global('premkproject', *args)
     return
 
 #
 # Change to the project directory
 #
-[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] && cd "$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")"
+[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] && \
+    cd "$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")"
 """

virtualenvwrapper/user_scripts.py

 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:
 GLOBAL_HOOKS = [
     # initialize
     ("initialize",
-     "This hook is run during the startup phase when loading virtualenvwrapper.sh."),
+     "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."),
+     "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."),
 
     ("get_env_details",
      "This hook is run when the list of virtualenvs is printed "
      "so each name can include details."),
-    ]
+]
 
 
 LOCAL_HOOKS = [
     ("get_env_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):
 #
 # Run user-provided scripts
 #
-[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && \
+    source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
 """
 
 
     log.debug('pre_mkvirtualenv %s', str(args))
     envname = args[0]
     for filename, comment in LOCAL_HOOKS:
-        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
+        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename),
+                  comment)
     run_global('premkvirtualenv', *args)
     return
 
 #
 # Run user-provided scripts
 #
-[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && \
+    source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
 """
 
 
     log.debug('pre_cpvirtualenv %s', str(args))
     envname = args[0]
     for filename, comment in LOCAL_HOOKS:
-        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
+        make_hook(get_path('$WORKON_HOME', envname, script_folder, filename),
+                  comment)
     run_global('precpvirtualenv', *args)
     return
 
 #
 # Run user-provided scripts
 #
-[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && \
+    source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
 """
 
 
 def pre_activate(args):
     log.debug('pre_activate')
     run_global('preactivate', *args)
-    script_path = get_path('$WORKON_HOME', args[0], script_folder, 'preactivate')
+    script_path = get_path('$WORKON_HOME', args[0],
+                           script_folder, 'preactivate')
     run_script(script_path, *args)
     return
 
 #
 # Run user-provided scripts
 #
-[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
-[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && \
+    source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
+[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && \
+    source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
 """
 
 
 #
 # Run user-provided scripts
 #
-[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
-[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
+[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && \
+    source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
+[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && \
+    source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
 """
 
 
 # Run user-provided scripts
 #
 VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV="$WORKON_HOME/%(env_name)s"
-[ -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"
+[ -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]}
 
 def get_env_details(args):
     log.debug('get_env_details')
     run_global('get_env_details', *args)
-    script_path = get_path('$WORKON_HOME', args[0], script_folder, 'get_env_details')
+    script_path = get_path('$WORKON_HOME', args[0],
+                           script_folder, 'get_env_details')
     run_script(script_path, *args)
     return
 
     '''
     path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
     if is_msys:
-        # MSYS accept unix or Win32 and sometimes it drives to mixed style paths
+        # 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:]))