Skip to content

Commit 4a72dc9

Browse files
committed
use flake8 instead of pep8 for style checking
1 parent 71aa555 commit 4a72dc9

File tree

5 files changed

+75
-57
lines changed

5 files changed

+75
-57
lines changed

docs/source/history.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dev
1515
caused by that rotating behavior, especially when the wrappers are
1616
being used by users with different permissions and
1717
umasks. (:bbissue:`152`)
18+
- Use flake8 for style checking.
1819

1920
3.6.1
2021

tox.ini

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

44
[testenv]
55
commands = bash ./tests/run_tests {envdir} []
@@ -9,9 +9,9 @@ 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
12+
[testenv:style]
13+
deps = flake8
14+
commands = flake8 virtualenvwrapper
1515

1616

1717
# Not sure why this is needed, but on my system if it isn't included then

virtualenvwrapper/hook_loader.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,51 @@ def main():
3434
usage='usage: %prog [options] <hook> [<arguments>]',
3535
prog='virtualenvwrapper.hook_loader',
3636
description='Manage hooks for virtualenvwrapper',
37-
)
37+
)
3838

3939
parser.add_option(
4040
'-S', '--script',
4141
help='Runs "hook" then "<hook>_source", writing the ' +
4242
'result to <file>',
4343
dest='script_filename',
4444
default=None,
45-
)
45+
)
4646
parser.add_option(
4747
'-s', '--source',
4848
help='Print the shell commands to be run in the current shell',
4949
action='store_true',
5050
dest='sourcing',
5151
default=False,
52-
)
52+
)
5353
parser.add_option(
5454
'-l', '--list',
5555
help='Print a list of the plugins available for the given hook',
5656
action='store_true',
5757
default=False,
5858
dest='listing',
59-
)
59+
)
6060
parser.add_option(
6161
'-v', '--verbose',
6262
help='Show more information on the console',
6363
action='store_const',
6464
const=2,
6565
default=1,
6666
dest='verbose_level',
67-
)
67+
)
6868
parser.add_option(
6969
'-q', '--quiet',
7070
help='Show less information on the console',
7171
action='store_const',
7272
const=0,
7373
dest='verbose_level',
74-
)
74+
)
7575
parser.add_option(
7676
'-n', '--name',
7777
help='Only run the hook from the named plugin',
7878
action='append',
7979
dest='names',
8080
default=[],
81-
)
81+
)
8282
parser.disable_interspersed_args() # stop when on option without an '-'
8383
options, args = parser.parse_args()
8484

@@ -92,7 +92,7 @@ def main():
9292
logfile,
9393
maxBytes=10240,
9494
backupCount=1,
95-
)
95+
)
9696
formatter = logging.Formatter(LOG_FORMAT)
9797
file_handler.setFormatter(formatter)
9898
root_logger.addHandler(file_handler)
@@ -189,23 +189,24 @@ def invoke(ext, args):
189189
def list_hooks(output=None):
190190
if output is None:
191191
output = sys.stdout
192-
for hook in itertools.chain(
193-
('_'.join(h)
194-
for h in itertools.product(['pre', 'post'],
195-
['mkvirtualenv',
196-
'rmvirtualenv',
197-
'activate',
198-
'deactivate',
199-
'cpvirtualenv',
200-
])
201-
),
202-
['initialize',
203-
'get_env_details',
204-
'project.pre_mkproject',
205-
'project.post_mkproject',
206-
'project.template',
207-
]
208-
):
192+
static_names = [
193+
'initialize',
194+
'get_env_details',
195+
'project.pre_mkproject',
196+
'project.post_mkproject',
197+
'project.template',
198+
]
199+
pre_post_hooks = (
200+
'_'.join(h)
201+
for h in itertools.product(['pre', 'post'],
202+
['mkvirtualenv',
203+
'rmvirtualenv',
204+
'activate',
205+
'deactivate',
206+
'cpvirtualenv',
207+
])
208+
)
209+
for hook in itertools.chain(static_names, pre_post_hooks):
209210
output.write(hook + '\n')
210211

211212

virtualenvwrapper/project.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
GLOBAL_HOOKS = [
1616
# mkproject
1717
("premkproject",
18-
"This hook is run after a new project is created and before it is activated."),
18+
"This hook is run after a new project is created "
19+
"and before it is activated."),
1920
("postmkproject",
2021
"This hook is run after a new project is activated."),
2122

@@ -24,20 +25,20 @@
2425
"This hook is run before a project is deleted."),
2526
("postrmproject",
2627
"This hook is run after a project is deleted."),
27-
]
28+
]
2829

2930

3031
def initialize(args):
3132
"""Set up user hooks
3233
"""
3334
for filename, comment in GLOBAL_HOOKS:
34-
make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment)
35+
make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename),
36+
comment)
3537
return
3638

3739

3840
def pre_mkproject(args):
3941
log.debug('pre_mkproject %s', str(args))
40-
envname = args[0]
4142
run_global('premkproject', *args)
4243
return
4344

@@ -56,5 +57,6 @@ def post_activate_source(args):
5657
#
5758
# Change to the project directory
5859
#
59-
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] && cd "$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")"
60+
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] && \
61+
cd "$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")"
6062
"""

virtualenvwrapper/user_scripts.py

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
log = logging.getLogger(__name__)
1717

1818
# Are we running under msys
19-
if (sys.platform == 'win32'
20-
and
21-
os.environ.get('OS') == 'Windows_NT'
22-
and
23-
os.environ.get('MSYSTEM') == 'MINGW32'):
19+
if sys.platform == 'win32' and \
20+
os.environ.get('OS') == 'Windows_NT' and \
21+
os.environ.get('MSYSTEM') == 'MINGW32':
2422
is_msys = True
2523
script_folder = 'Scripts'
2624
else:
@@ -59,11 +57,13 @@ def run_global(script_name, *args):
5957
GLOBAL_HOOKS = [
6058
# initialize
6159
("initialize",
62-
"This hook is run during the startup phase when loading virtualenvwrapper.sh."),
60+
"This hook is run during the startup phase "
61+
"when loading virtualenvwrapper.sh."),
6362

6463
# mkvirtualenv
6564
("premkvirtualenv",
66-
"This hook is run after a new virtualenv is created and before it is activated."),
65+
"This hook is run after a new virtualenv is created "
66+
"and before it is activated."),
6767
("postmkvirtualenv",
6868
"This hook is run after a new virtualenv is activated."),
6969

@@ -89,7 +89,7 @@ def run_global(script_name, *args):
8989
("get_env_details",
9090
"This hook is run when the list of virtualenvs is printed "
9191
"so each name can include details."),
92-
]
92+
]
9393

9494

9595
LOCAL_HOOKS = [
@@ -109,7 +109,7 @@ def run_global(script_name, *args):
109109
("get_env_details",
110110
"This hook is run when the list of virtualenvs is printed "
111111
"in 'long' mode so each name can include details."),
112-
]
112+
]
113113

114114

115115
def make_hook(filename, comment):
@@ -149,15 +149,17 @@ def initialize_source(args):
149149
#
150150
# Run user-provided scripts
151151
#
152-
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
152+
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && \
153+
source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
153154
"""
154155

155156

156157
def pre_mkvirtualenv(args):
157158
log.debug('pre_mkvirtualenv %s', str(args))
158159
envname = args[0]
159160
for filename, comment in LOCAL_HOOKS:
160-
make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
161+
make_hook(get_path('$WORKON_HOME', envname, script_folder, filename),
162+
comment)
161163
run_global('premkvirtualenv', *args)
162164
return
163165

@@ -167,15 +169,17 @@ def post_mkvirtualenv_source(args):
167169
#
168170
# Run user-provided scripts
169171
#
170-
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
172+
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && \
173+
source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
171174
"""
172175

173176

174177
def pre_cpvirtualenv(args):
175178
log.debug('pre_cpvirtualenv %s', str(args))
176179
envname = args[0]
177180
for filename, comment in LOCAL_HOOKS:
178-
make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment)
181+
make_hook(get_path('$WORKON_HOME', envname, script_folder, filename),
182+
comment)
179183
run_global('precpvirtualenv', *args)
180184
return
181185

@@ -185,7 +189,8 @@ def post_cpvirtualenv_source(args):
185189
#
186190
# Run user-provided scripts
187191
#
188-
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
192+
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && \
193+
source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
189194
"""
190195

191196

@@ -204,7 +209,8 @@ def post_rmvirtualenv(args):
204209
def pre_activate(args):
205210
log.debug('pre_activate')
206211
run_global('preactivate', *args)
207-
script_path = get_path('$WORKON_HOME', args[0], script_folder, 'preactivate')
212+
script_path = get_path('$WORKON_HOME', args[0],
213+
script_folder, 'preactivate')
208214
run_script(script_path, *args)
209215
return
210216

@@ -215,8 +221,10 @@ def post_activate_source(args):
215221
#
216222
# Run user-provided scripts
217223
#
218-
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
219-
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
224+
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && \
225+
source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
226+
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && \
227+
source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
220228
"""
221229

222230

@@ -226,8 +234,10 @@ def pre_deactivate_source(args):
226234
#
227235
# Run user-provided scripts
228236
#
229-
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
230-
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
237+
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && \
238+
source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
239+
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && \
240+
source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
231241
"""
232242

233243

@@ -238,16 +248,19 @@ def post_deactivate_source(args):
238248
# Run user-provided scripts
239249
#
240250
VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV="$WORKON_HOME/%(env_name)s"
241-
[ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
242-
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
251+
[ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && \
252+
source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
253+
[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && \
254+
source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
243255
unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
244256
""" % {'env_name': args[0]}
245257

246258

247259
def get_env_details(args):
248260
log.debug('get_env_details')
249261
run_global('get_env_details', *args)
250-
script_path = get_path('$WORKON_HOME', args[0], script_folder, 'get_env_details')
262+
script_path = get_path('$WORKON_HOME', args[0],
263+
script_folder, 'get_env_details')
251264
run_script(script_path, *args)
252265
return
253266

@@ -263,7 +276,8 @@ def get_path(*args):
263276
'''
264277
path = os.path.expanduser(os.path.expandvars(os.path.join(*args)))
265278
if is_msys:
266-
# MSYS accept unix or Win32 and sometimes it drives to mixed style paths
279+
# MSYS accept unix or Win32 and sometimes
280+
# it drives to mixed style paths
267281
if re.match(r'^/[a-zA-Z](/|^)', path):
268282
# msys path could starts with '/c/'-form drive letter
269283
path = ''.join((path[1], ':', path[2:]))

0 commit comments

Comments
 (0)