Skip to content

Commit 5e3c619

Browse files
committed
chore(ruff): cleanup setup.py whitespace, comprehensions etc.
Fixes: replace [f for f in ...] with list(...) replace else block after return in if true case use with open() when reading announcement.txt add trailing , in lists. whitespace normalizing
1 parent 4650469 commit 5e3c619

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

setup.py

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def include(d, e):
4040
4141
'e' -- A glob pattern"""
4242

43-
return (d, [f for f in glob('%s/%s'%(d, e)) if os.path.isfile(f)])
43+
return (d, [f for f in glob('%s/%s' % (d, e)) if os.path.isfile(f)])
4444

4545

4646
def mapscript(path):
@@ -51,6 +51,7 @@ def mapscript(path):
5151
script = module.replace('_', '-')
5252
return '%s = roundup.scripts.%s:run' % (script, module)
5353

54+
5455
def make_data_files_absolute(data_files, prefix):
5556
"""Using setuptools data files are put under the egg install directory
5657
if the datafiles are relative paths. We don't want this. Data files
@@ -65,51 +66,51 @@ def make_data_files_absolute(data_files, prefix):
6566

6667
return new_data_files
6768

69+
6870
def get_prefix():
6971
"""Get site specific prefix using --prefix, platform lib or
7072
sys.prefix.
7173
"""
72-
prefix_arg=False
73-
prefix=""
74+
prefix_arg = False
75+
prefix = ""
7476
for a in sys.argv:
7577
if prefix_arg:
76-
prefix=a
78+
prefix = a
7779
break
7880
# is there a short form -p or something for this??
7981
if a.startswith('--prefix'):
8082
if a == '--prefix':
8183
# next argument is prefix
82-
prefix_arg=True
84+
prefix_arg = True
8385
continue
84-
else:
85-
# strip '--prefix='
86-
prefix=a[9:]
86+
# strip '--prefix='
87+
prefix = a[9:]
8788
if prefix:
8889
return prefix
89-
else:
90-
if sys.platform.startswith('win'):
91-
# on windows, using pip to install and
92-
# prefixing data file paths with c:\path\a\b\...
93-
# results in treatment as a relative path.
94-
# The result is files are buried under:
95-
# platlib\path\a\b\...\share\ and not findable by
96-
# Roundup. So return no prefix which places the files at
97-
# platlib\share\{doc,locale,roundup} where roundup can
98-
# find templates/translations etc.
99-
# sigh....
100-
return ""
101-
102-
# start with the platform library
103-
plp = get_path('platlib')
104-
# nuke suffix that matches lib/* and return prefix
105-
head, tail = os.path.split(plp)
106-
old_head = None
107-
while tail.lower() not in ['lib', 'lib64' ] and head != old_head:
108-
old_head = head
109-
head, tail = os.path.split(head)
110-
if head == old_head:
111-
head = sys.prefix
112-
return head
90+
91+
if sys.platform.startswith('win'):
92+
# on windows, using pip to install and
93+
# prefixing data file paths with c:\path\a\b\...
94+
# results in treatment as a relative path.
95+
# The result is files are buried under:
96+
# platlib\path\a\b\...\share\ and not findable by
97+
# Roundup. So return no prefix which places the files at
98+
# platlib\share\{doc,locale,roundup} where roundup can
99+
# find templates/translations etc.
100+
# sigh....
101+
return ""
102+
103+
# start with the platform library
104+
plp = get_path('platlib')
105+
# nuke suffix that matches lib/* and return prefix
106+
head, tail = os.path.split(plp)
107+
old_head = None
108+
while tail.lower() not in ['lib', 'lib64'] and head != old_head:
109+
old_head = head
110+
head, tail = os.path.split(head)
111+
if head == old_head:
112+
head = sys.prefix
113+
return head
113114

114115

115116
def main():
@@ -132,17 +133,17 @@ def main():
132133

133134
# build list of zope files/directories
134135
Zope = {}
135-
Zope['module'] = [f for f in glob('frontends/ZRoundup/*.py')]
136-
Zope['module'].append('frontends/ZRoundup/refresh.txt');
137-
Zope['icons'] = [f for f in glob('frontends/ZRoundupscripts/*.gif')]
138-
Zope['dtml'] = [f for f in glob('frontends/ZRoundupscripts/*.dtml')]
136+
Zope['module'] = list(glob('frontends/ZRoundup/*.py'))
137+
Zope['module'].append('frontends/ZRoundup/refresh.txt')
138+
Zope['icons'] = list(glob('frontends/ZRoundupscripts/*.gif'))
139+
Zope['dtml'] = list(glob('frontends/ZRoundupscripts/*.dtml'))
139140

140141
data_files = [
141142
('share/roundup/cgi-bin', ['frontends/roundup.cgi']),
142143
('share/roundup/frontends', ['frontends/wsgi.py']),
143144
('share/roundup/frontends/ZRoundup', Zope['module']),
144145
('share/roundup/frontends/ZRoundup/icons', Zope['icons']),
145-
('share/roundup/frontends/ZRoundup/dtml', Zope['dtml'])
146+
('share/roundup/frontends/ZRoundup/dtml', Zope['dtml']),
146147
]
147148
# install man pages on POSIX platforms
148149
if os.name == 'posix':
@@ -191,7 +192,8 @@ def main():
191192
# because the distutils installer will try to use the mbcs codec
192193
# which isn't available on non-windows platforms. See also
193194
# http://bugs.python.org/issue10945
194-
long_description=open('doc/announcement.txt').read()
195+
with open('doc/announcement.txt') as announcement:
196+
long_description = announcement.read()
195197
try:
196198
# attempt to interpret string as 'ascii'
197199
long_description.encode('ascii')
@@ -252,7 +254,7 @@ def main():
252254
extras_require={
253255
"charting": ['pygal'],
254256
"jinja2": ['jinja2'],
255-
"extras": [ 'brotli', 'pytz'],
257+
"extras": ['brotli', 'pytz'],
256258
"test": ['pytest > 7.0.0'],
257259
},
258260
# Override certain command classes with our own ones
@@ -263,10 +265,11 @@ def main():
263265
},
264266
packages=packages,
265267
entry_points={
266-
'console_scripts': scripts
268+
'console_scripts': scripts,
267269
},
268270
data_files=data_files)
269271

272+
270273
if __name__ == '__main__':
271274

272275
# Prevent `pip install roundup` from building bdist_wheel.

0 commit comments

Comments
 (0)