Skip to content

Commit 62eb6b5

Browse files
committed
pep8 cleanup
1 parent 3eb6ba8 commit 62eb6b5

File tree

4 files changed

+92
-64
lines changed

4 files changed

+92
-64
lines changed

tox.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27,py26,py32
2+
envlist = py27,py26,py32,pep8
33

44
[testenv]
55
commands = bash ./tests/run_tests {envdir} []
@@ -9,6 +9,11 @@ deps = virtualenv
99
setenv =
1010
TOXIC = true
1111

12+
[testenv:pep8]
13+
deps = pep8==1.1
14+
commands = pep8 --ignore=E501 --repeat --show-source virtualenvwrapper
15+
16+
1217
# Not sure why this is needed, but on my system if it isn't included then
1318
# the python version picked up for 2.6 is actually 2.7.
1419
# IF THIS CAUSES YOU A PROBLEM COMMENT IT OUT BEFORE RUNNING THE TESTS.

virtualenvwrapper/hook_loader.py

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
from stevedore import ExtensionManager
1717
from stevedore import NamedExtensionManager
1818

19+
LOG_FORMAT = '%(asctime)s %(levelname)s %(name)s %(message)s'
20+
1921

2022
class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
21-
"""Taken from http://stackoverflow.com/questions/1407474/does-python-logging-handlers-rotatingfilehandler-allow-creation-of-a-group-writa
23+
"""Taken from http://stackoverflow.com/questions/1407474
2224
"""
2325
def _open(self):
2426
prevumask = os.umask(0o002)
@@ -34,56 +36,63 @@ def main():
3436
description='Manage hooks for virtualenvwrapper',
3537
)
3638

37-
parser.add_option('-S', '--script',
38-
help='Runs "hook" then "<hook>_source", writing the ' +
39-
'result to <file>',
40-
dest='script_filename',
41-
default=None,
42-
)
43-
parser.add_option('-s', '--source',
44-
help='Print the shell commands to be run in the current shell',
45-
action='store_true',
46-
dest='sourcing',
47-
default=False,
48-
)
49-
parser.add_option('-l', '--list',
50-
help='Print a list of the plugins available for the given hook',
51-
action='store_true',
52-
default=False,
53-
dest='listing',
54-
)
55-
parser.add_option('-v', '--verbose',
56-
help='Show more information on the console',
57-
action='store_const',
58-
const=2,
59-
default=1,
60-
dest='verbose_level',
61-
)
62-
parser.add_option('-q', '--quiet',
63-
help='Show less information on the console',
64-
action='store_const',
65-
const=0,
66-
dest='verbose_level',
67-
)
68-
parser.add_option('-n', '--name',
69-
help='Only run the hook from the named plugin',
70-
action='append',
71-
dest='names',
72-
default=[],
73-
)
74-
parser.disable_interspersed_args() # stop when we hit an option without an '-'
39+
parser.add_option(
40+
'-S', '--script',
41+
help='Runs "hook" then "<hook>_source", writing the ' +
42+
'result to <file>',
43+
dest='script_filename',
44+
default=None,
45+
)
46+
parser.add_option(
47+
'-s', '--source',
48+
help='Print the shell commands to be run in the current shell',
49+
action='store_true',
50+
dest='sourcing',
51+
default=False,
52+
)
53+
parser.add_option(
54+
'-l', '--list',
55+
help='Print a list of the plugins available for the given hook',
56+
action='store_true',
57+
default=False,
58+
dest='listing',
59+
)
60+
parser.add_option(
61+
'-v', '--verbose',
62+
help='Show more information on the console',
63+
action='store_const',
64+
const=2,
65+
default=1,
66+
dest='verbose_level',
67+
)
68+
parser.add_option(
69+
'-q', '--quiet',
70+
help='Show less information on the console',
71+
action='store_const',
72+
const=0,
73+
dest='verbose_level',
74+
)
75+
parser.add_option(
76+
'-n', '--name',
77+
help='Only run the hook from the named plugin',
78+
action='append',
79+
dest='names',
80+
default=[],
81+
)
82+
parser.disable_interspersed_args() # stop when on option without an '-'
7583
options, args = parser.parse_args()
7684

7785
root_logger = logging.getLogger('')
7886

7987
# Set up logging to a file
8088
root_logger.setLevel(logging.DEBUG)
8189
file_handler = GroupWriteRotatingFileHandler(
82-
os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR', 'hook.log')),
90+
os.path.expandvars(os.path.join('$VIRTUALENVWRAPPER_LOG_DIR',
91+
'hook.log')),
8392
maxBytes=10240,
8493
backupCount=1,
8594
)
86-
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
95+
formatter = logging.Formatter(LOG_FORMAT)
8796
file_handler.setFormatter(formatter)
8897
root_logger.addHandler(file_handler)
8998

@@ -121,7 +130,8 @@ def main():
121130
run_hooks(hook, options, args)
122131

123132
if options.script_filename:
124-
log.debug('Saving sourcable %s hooks to %s', hook, options.script_filename)
133+
log.debug('Saving sourcable %s hooks to %s',
134+
hook, options.script_filename)
125135
options.sourcing = True
126136
output = open(options.script_filename, "w")
127137
try:
@@ -147,7 +157,8 @@ def run_hooks(hook, options, args, output=None):
147157

148158
if options.listing:
149159
def show(ext):
150-
output.write(' %-10s -- %s\n' % (ext.name, inspect.getdoc(ext.plugin) or ''))
160+
output.write(' %-10s -- %s\n' %
161+
(ext.name, inspect.getdoc(ext.plugin) or ''))
151162
hook_mgr.map(show)
152163

153164
elif options.sourcing:

virtualenvwrapper/project.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import logging
99
import os
1010

11-
import pkg_resources
12-
1311
from virtualenvwrapper.user_scripts import make_hook, run_global
1412

1513
log = logging.getLogger(__name__)
@@ -28,6 +26,7 @@
2826
"This hook is run after a project is deleted."),
2927
]
3028

29+
3130
def initialize(args):
3231
"""Set up user hooks
3332
"""
@@ -38,10 +37,11 @@ def initialize(args):
3837

3938
def pre_mkproject(args):
4039
log.debug('pre_mkproject %s', str(args))
41-
envname=args[0]
40+
envname = args[0]
4241
run_global('premkproject', *args)
4342
return
4443

44+
4545
def post_mkproject_source(args):
4646
return """
4747
#
@@ -50,6 +50,7 @@ def post_mkproject_source(args):
5050
[ -f "$WORKON_HOME/postmkproject" ] && source "$WORKON_HOME/postmkproject"
5151
"""
5252

53+
5354
def post_activate_source(args):
5455
return """
5556
#

virtualenvwrapper/user_scripts.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import subprocess
1313
import sys
1414

15-
import pkg_resources
1615

1716
log = logging.getLogger(__name__)
1817

19-
2018
# Are we running under msys
21-
if sys.platform == 'win32' and os.environ.get('OS') == 'Windows_NT' and os.environ.get('MSYSTEM') == 'MINGW32':
19+
if (sys.platform == 'win32'
20+
and
21+
os.environ.get('OS') == 'Windows_NT'
22+
and
23+
os.environ.get('MSYSTEM') == 'MINGW32'):
2224
is_msys = True
2325
script_folder = 'Scripts'
2426
else:
@@ -32,12 +34,12 @@ def run_script(script_path, *args):
3234
if os.path.exists(script_path):
3335
cmd = [script_path] + list(args)
3436
if is_msys:
35-
cmd = [get_path(os.environ['MSYS_HOME'],'bin','sh.exe')] + cmd
37+
cmd = [get_path(os.environ['MSYS_HOME'], 'bin', 'sh.exe')] + cmd
3638
log.debug('running %s', str(cmd))
3739
try:
38-
return_code = subprocess.call(cmd)
40+
subprocess.call(cmd)
3941
except OSError:
40-
_, msg, _ = sys.exc_info()
42+
_, msg, _ = sys.exc_info()
4143
log.error('could not run "%s": %s', script_path, str(msg))
4244
#log.debug('Returned %s', return_code)
4345
return
@@ -85,7 +87,8 @@ def run_global(script_name, *args):
8587

8688
# get_env_details
8789
("get_env_details",
88-
"This hook is run when the list of virtualenvs is printed so each name can include details."),
90+
"This hook is run when the list of virtualenvs is printed "
91+
"so each name can include details."),
8992
]
9093

9194

@@ -104,13 +107,14 @@ def run_global(script_name, *args):
104107

105108
# get_env_details
106109
("get_env_details",
107-
"This hook is run when the list of virtualenvs is printed in 'long' mode so each name can include details."),
110+
"This hook is run when the list of virtualenvs is printed "
111+
"in 'long' mode so each name can include details."),
108112
]
109113

110114

111115
def make_hook(filename, comment):
112116
"""Create a hook script.
113-
117+
114118
:param filename: The name of the file to write.
115119
:param comment: The comment to insert into the file.
116120
"""
@@ -122,14 +126,15 @@ def make_hook(filename, comment):
122126
f.write("""#!%(shell)s
123127
# %(comment)s
124128
125-
""" % {'comment':comment, 'shell':os.environ.get('SHELL', '/bin/sh')})
129+
""" % {'comment': comment,
130+
'shell': os.environ.get('SHELL', '/bin/sh'),
131+
})
126132
finally:
127133
f.close()
128134
os.chmod(filename, PERMISSIONS)
129135
return
130136

131137

132-
133138
# HOOKS
134139

135140

@@ -147,9 +152,10 @@ def initialize_source(args):
147152
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
148153
"""
149154

155+
150156
def pre_mkvirtualenv(args):
151157
log.debug('pre_mkvirtualenv %s', str(args))
152-
envname=args[0]
158+
envname = args[0]
153159
for filename, comment in LOCAL_HOOKS:
154160
make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
155161
run_global('premkvirtualenv', *args)
@@ -164,9 +170,10 @@ def post_mkvirtualenv_source(args):
164170
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
165171
"""
166172

173+
167174
def pre_cpvirtualenv(args):
168175
log.debug('pre_cpvirtualenv %s', str(args))
169-
envname=args[0]
176+
envname = args[0]
170177
for filename, comment in LOCAL_HOOKS:
171178
make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
172179
run_global('precpvirtualenv', *args)
@@ -234,7 +241,7 @@ def post_deactivate_source(args):
234241
[ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
235242
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
236243
unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
237-
""" % { 'env_name':args[0] }
244+
""" % {'env_name': args[0]}
238245

239246

240247
def get_env_details(args):
@@ -244,18 +251,22 @@ def get_env_details(args):
244251
run_script(script_path, *args)
245252
return
246253

254+
247255
def get_path(*args):
248256
'''
249257
Get a full path from args.
250-
Path separator is determined according to the os and the shell and allow to use is_msys.
258+
259+
Path separator is determined according to the os and the shell and
260+
allow to use is_msys.
261+
251262
Variables and user are expanded during the process.
252263
'''
253264
path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
254265
if is_msys:
255266
# MSYS accept unix or Win32 and sometimes it drives to mixed style paths
256267
if re.match(r'^/[a-zA-Z](/|^)', path):
257268
# msys path could starts with '/c/'-form drive letter
258-
path = ''.join((path[1],':',path[2:]))
269+
path = ''.join((path[1], ':', path[2:]))
259270
path = path.replace('/', os.sep)
260-
271+
261272
return os.path.abspath(path)

0 commit comments

Comments
 (0)