Skip to content

Commit 4dc2561

Browse files
committed
config.py: pep257, pep 8
1 parent aa2d2cc commit 4dc2561

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

tmuxp/config.py

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def validate_schema(sconf):
4040

4141
if not 'panes' in window:
4242
raise exc.ConfigError(
43-
'config window %s requires list of panes' % window['window_name'])
43+
'config window %s requires list of panes' %
44+
window['window_name']
45+
)
4446

4547
return True
4648

@@ -61,7 +63,10 @@ def is_config_file(filename, extensions=['.yml', '.yaml', '.json']):
6163
return any(filename.endswith(e) for e in extensions)
6264

6365

64-
def in_dir(config_dir=os.path.expanduser('~/.tmuxp'), extensions=['.yml', '.yaml', '.json']):
66+
def in_dir(
67+
config_dir=os.path.expanduser('~/.tmuxp'),
68+
extensions=['.yml', '.yaml', '.json']
69+
):
6570
"""Return a list of configs in ``config_dir``.
6671
6772
:param config_dir: directory to search
@@ -74,7 +79,8 @@ def in_dir(config_dir=os.path.expanduser('~/.tmuxp'), extensions=['.yml', '.yaml
7479
configs = []
7580

7681
for filename in os.listdir(config_dir):
77-
if is_config_file(filename, extensions) and not filename.startswith('.'):
82+
if is_config_file(filename, extensions) and \
83+
not filename.startswith('.'):
7884
configs.append(filename)
7985

8086
return configs
@@ -106,12 +112,20 @@ def inline(sconf):
106112
107113
"""
108114

109-
if ('shell_command' in sconf and isinstance(sconf['shell_command'], list) and len(sconf['shell_command']) == 1):
115+
if (
116+
'shell_command' in sconf and
117+
isinstance(sconf['shell_command'], list) and
118+
len(sconf['shell_command']) == 1
119+
):
110120
sconf['shell_command'] = sconf['shell_command'][0]
111121

112122
if len(sconf.keys()) == int(1):
113123
sconf = sconf['shell_command']
114-
if ('shell_command_before' in sconf and isinstance(sconf['shell_command_before'], list) and len(sconf['shell_command_before']) == 1):
124+
if (
125+
'shell_command_before' in sconf and
126+
isinstance(sconf['shell_command_before'], list) and
127+
len(sconf['shell_command_before']) == 1
128+
):
115129
sconf['shell_command_before'] = sconf['shell_command_before'][0]
116130

117131
# recurse into window and pane config items
@@ -153,22 +167,28 @@ def expand(sconf, cwd=None):
153167
if not cwd:
154168
cwd = os.getcwd()
155169

156-
157170
# Any config section, session, window, pane that can contain the
158171
# 'shell_command' value
159172
if 'start_directory' in sconf:
160-
if any(sconf['start_directory'].startswith(a) for a in ['.', './']):
161-
sconf['start_directory'] = os.path.normpath(os.path.join(cwd, sconf['start_directory']))
162-
elif any(sconf['start_directory'] == a for a in ['.', './']):
163-
sconf['start_directory'] = os.path.normpath(os.path.join(cwd, sconf['start_directory']))
164-
165-
if ('shell_command' in sconf and isinstance(sconf['shell_command'], basestring)):
173+
if (
174+
any(sconf['start_directory'].startswith(a) for a in ['.', './']) or
175+
any(sconf['start_directory'] == a for a in ['.', './'])
176+
):
177+
start_path = os.path.normpath(
178+
os.path.join(cwd, sconf['start_directory'])
179+
)
180+
sconf['start_directory'] = start_path
181+
182+
if (
183+
'shell_command' in sconf and
184+
isinstance(sconf['shell_command'], basestring)
185+
):
166186
sconf['shell_command'] = [sconf['shell_command']]
167-
# elif not 'windows' in sconf and not 'panes' in sconf and isinstance(sconf, basestring): # probable pane
168-
# logger.error(sconf)
169-
# sconf = {'shell_command': [sconf]}
170187

171-
if ('shell_command_before' in sconf and isinstance(sconf['shell_command_before'], basestring)):
188+
if (
189+
'shell_command_before' in sconf and
190+
isinstance(sconf['shell_command_before'], basestring)
191+
):
172192
sconf['shell_command_before'] = [sconf['shell_command_before']]
173193

174194
# recurse into window and pane config items
@@ -181,12 +201,12 @@ def expand(sconf, cwd=None):
181201
for p in sconf['panes']:
182202
p_index = sconf['panes'].index(p)
183203

184-
if not isinstance(p, dict) and not isinstance(p, list): # probable pane
204+
if not isinstance(p, dict) and not isinstance(p, list):
185205
p = sconf['panes'][p_index] = {
186206
'shell_command': [p]
187207
}
188208

189-
if isinstance (p, dict) and not len(p):
209+
if isinstance(p, dict) and not len(p):
190210
p = sconf['panes'][p_index] = {
191211
'shell_command': []
192212
}
@@ -208,11 +228,16 @@ def expand(sconf, cwd=None):
208228
p = sconf['panes'][p_index] = {
209229
'shell_command': []
210230
}
211-
elif isinstance(p['shell_command'], list) and \
212-
len(p['shell_command']) == int(1) and (
213-
any(a in p['shell_command'] for a in [None, 'blank', 'pane']) or \
214-
p['shell_command'][0] is None
215-
):
231+
elif (
232+
isinstance(p['shell_command'], list) and (
233+
len(p['shell_command']) == int(1) and (
234+
any(
235+
a in p['shell_command']
236+
for a in [None, 'blank', 'pane']
237+
) or p['shell_command'][0] is None
238+
)
239+
)
240+
):
216241
p = sconf['panes'][p_index] = {
217242
'shell_command': []
218243
}
@@ -253,9 +278,14 @@ def trickle(sconf):
253278
if not 'start_directory' in windowconfig:
254279
windowconfig['start_directory'] = session_start_directory
255280
else:
256-
if not any(windowconfig['start_directory'].startswith(a) for a in ['~', '/']):
257-
windowconfig['start_directory'] = os.path.join(
258-
session_start_directory, windowconfig['start_directory'])
281+
if not any(
282+
windowconfig['start_directory'].startswith(a)
283+
for a in ['~', '/']
284+
):
285+
window_start_path = os.path.join(
286+
session_start_directory, windowconfig['start_directory']
287+
)
288+
windowconfig['start_directory'] = window_start_path
259289

260290
for paneconfig in windowconfig['panes']:
261291
commands_before = []

0 commit comments

Comments
 (0)