Mercurial > p > roundup > code
comparison setup.py @ 7932:55229bfcdd8a
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
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 05 May 2024 18:19:04 -0400 |
| parents | bc45c3df770a |
| children | 8bf56686f763 |
comparison
equal
deleted
inserted
replaced
| 7931:bc45c3df770a | 7932:55229bfcdd8a |
|---|---|
| 38 | 38 |
| 39 'd' -- A directory | 39 'd' -- A directory |
| 40 | 40 |
| 41 'e' -- A glob pattern""" | 41 'e' -- A glob pattern""" |
| 42 | 42 |
| 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)]) |
| 44 | 44 |
| 45 | 45 |
| 46 def mapscript(path): | 46 def mapscript(path): |
| 47 """ Helper for building a list of script names from a list of | 47 """ Helper for building a list of script names from a list of |
| 48 module files. | 48 module files. |
| 49 """ | 49 """ |
| 50 module = os.path.splitext(os.path.basename(path))[0] | 50 module = os.path.splitext(os.path.basename(path))[0] |
| 51 script = module.replace('_', '-') | 51 script = module.replace('_', '-') |
| 52 return '%s = roundup.scripts.%s:run' % (script, module) | 52 return '%s = roundup.scripts.%s:run' % (script, module) |
| 53 | |
| 53 | 54 |
| 54 def make_data_files_absolute(data_files, prefix): | 55 def make_data_files_absolute(data_files, prefix): |
| 55 """Using setuptools data files are put under the egg install directory | 56 """Using setuptools data files are put under the egg install directory |
| 56 if the datafiles are relative paths. We don't want this. Data files | 57 if the datafiles are relative paths. We don't want this. Data files |
| 57 like man pages, documentation, templates etc. should be installed | 58 like man pages, documentation, templates etc. should be installed |
| 63 new_data_files = [ (os.path.join(prefix,df[0]),df[1]) | 64 new_data_files = [ (os.path.join(prefix,df[0]),df[1]) |
| 64 for df in data_files ] | 65 for df in data_files ] |
| 65 | 66 |
| 66 return new_data_files | 67 return new_data_files |
| 67 | 68 |
| 69 | |
| 68 def get_prefix(): | 70 def get_prefix(): |
| 69 """Get site specific prefix using --prefix, platform lib or | 71 """Get site specific prefix using --prefix, platform lib or |
| 70 sys.prefix. | 72 sys.prefix. |
| 71 """ | 73 """ |
| 72 prefix_arg=False | 74 prefix_arg = False |
| 73 prefix="" | 75 prefix = "" |
| 74 for a in sys.argv: | 76 for a in sys.argv: |
| 75 if prefix_arg: | 77 if prefix_arg: |
| 76 prefix=a | 78 prefix = a |
| 77 break | 79 break |
| 78 # is there a short form -p or something for this?? | 80 # is there a short form -p or something for this?? |
| 79 if a.startswith('--prefix'): | 81 if a.startswith('--prefix'): |
| 80 if a == '--prefix': | 82 if a == '--prefix': |
| 81 # next argument is prefix | 83 # next argument is prefix |
| 82 prefix_arg=True | 84 prefix_arg = True |
| 83 continue | 85 continue |
| 84 else: | 86 # strip '--prefix=' |
| 85 # strip '--prefix=' | 87 prefix = a[9:] |
| 86 prefix=a[9:] | |
| 87 if prefix: | 88 if prefix: |
| 88 return prefix | 89 return prefix |
| 89 else: | 90 |
| 90 if sys.platform.startswith('win'): | 91 if sys.platform.startswith('win'): |
| 91 # on windows, using pip to install and | 92 # on windows, using pip to install and |
| 92 # prefixing data file paths with c:\path\a\b\... | 93 # prefixing data file paths with c:\path\a\b\... |
| 93 # results in treatment as a relative path. | 94 # results in treatment as a relative path. |
| 94 # The result is files are buried under: | 95 # The result is files are buried under: |
| 95 # platlib\path\a\b\...\share\ and not findable by | 96 # platlib\path\a\b\...\share\ and not findable by |
| 96 # Roundup. So return no prefix which places the files at | 97 # Roundup. So return no prefix which places the files at |
| 97 # platlib\share\{doc,locale,roundup} where roundup can | 98 # platlib\share\{doc,locale,roundup} where roundup can |
| 98 # find templates/translations etc. | 99 # find templates/translations etc. |
| 99 # sigh.... | 100 # sigh.... |
| 100 return "" | 101 return "" |
| 101 | 102 |
| 102 # start with the platform library | 103 # start with the platform library |
| 103 plp = get_path('platlib') | 104 plp = get_path('platlib') |
| 104 # nuke suffix that matches lib/* and return prefix | 105 # nuke suffix that matches lib/* and return prefix |
| 105 head, tail = os.path.split(plp) | 106 head, tail = os.path.split(plp) |
| 106 old_head = None | 107 old_head = None |
| 107 while tail.lower() not in ['lib', 'lib64' ] and head != old_head: | 108 while tail.lower() not in ['lib', 'lib64'] and head != old_head: |
| 108 old_head = head | 109 old_head = head |
| 109 head, tail = os.path.split(head) | 110 head, tail = os.path.split(head) |
| 110 if head == old_head: | 111 if head == old_head: |
| 111 head = sys.prefix | 112 head = sys.prefix |
| 112 return head | 113 return head |
| 113 | 114 |
| 114 | 115 |
| 115 def main(): | 116 def main(): |
| 116 # template munching | 117 # template munching |
| 117 packages = [ | 118 packages = [ |
| 130 # build list of scripts from their implementation modules | 131 # build list of scripts from their implementation modules |
| 131 scripts = [mapscript(f) for f in glob('roundup/scripts/[!_]*.py')] | 132 scripts = [mapscript(f) for f in glob('roundup/scripts/[!_]*.py')] |
| 132 | 133 |
| 133 # build list of zope files/directories | 134 # build list of zope files/directories |
| 134 Zope = {} | 135 Zope = {} |
| 135 Zope['module'] = [f for f in glob('frontends/ZRoundup/*.py')] | 136 Zope['module'] = list(glob('frontends/ZRoundup/*.py')) |
| 136 Zope['module'].append('frontends/ZRoundup/refresh.txt'); | 137 Zope['module'].append('frontends/ZRoundup/refresh.txt') |
| 137 Zope['icons'] = [f for f in glob('frontends/ZRoundupscripts/*.gif')] | 138 Zope['icons'] = list(glob('frontends/ZRoundupscripts/*.gif')) |
| 138 Zope['dtml'] = [f for f in glob('frontends/ZRoundupscripts/*.dtml')] | 139 Zope['dtml'] = list(glob('frontends/ZRoundupscripts/*.dtml')) |
| 139 | 140 |
| 140 data_files = [ | 141 data_files = [ |
| 141 ('share/roundup/cgi-bin', ['frontends/roundup.cgi']), | 142 ('share/roundup/cgi-bin', ['frontends/roundup.cgi']), |
| 142 ('share/roundup/frontends', ['frontends/wsgi.py']), | 143 ('share/roundup/frontends', ['frontends/wsgi.py']), |
| 143 ('share/roundup/frontends/ZRoundup', Zope['module']), | 144 ('share/roundup/frontends/ZRoundup', Zope['module']), |
| 144 ('share/roundup/frontends/ZRoundup/icons', Zope['icons']), | 145 ('share/roundup/frontends/ZRoundup/icons', Zope['icons']), |
| 145 ('share/roundup/frontends/ZRoundup/dtml', Zope['dtml']) | 146 ('share/roundup/frontends/ZRoundup/dtml', Zope['dtml']), |
| 146 ] | 147 ] |
| 147 # install man pages on POSIX platforms | 148 # install man pages on POSIX platforms |
| 148 if os.name == 'posix': | 149 if os.name == 'posix': |
| 149 data_files.append(include('share/man/man1', '*')) | 150 data_files.append(include('share/man/man1', '*')) |
| 150 | 151 |
| 189 # will produce an non-installable installer on linux *and* we can't | 190 # will produce an non-installable installer on linux *and* we can't |
| 190 # run the bdist_wininst on Linux if there are non-ascii characters | 191 # run the bdist_wininst on Linux if there are non-ascii characters |
| 191 # because the distutils installer will try to use the mbcs codec | 192 # because the distutils installer will try to use the mbcs codec |
| 192 # which isn't available on non-windows platforms. See also | 193 # which isn't available on non-windows platforms. See also |
| 193 # http://bugs.python.org/issue10945 | 194 # 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() | |
| 195 try: | 197 try: |
| 196 # attempt to interpret string as 'ascii' | 198 # attempt to interpret string as 'ascii' |
| 197 long_description.encode('ascii') | 199 long_description.encode('ascii') |
| 198 except UnicodeEncodeError as cause: | 200 except UnicodeEncodeError as cause: |
| 199 print("doc/announcement.txt contains non-ascii: %s" | 201 print("doc/announcement.txt contains non-ascii: %s" |
| 250 'Topic :: Internet :: WWW/HTTP :: WSGI :: Application', | 252 'Topic :: Internet :: WWW/HTTP :: WSGI :: Application', |
| 251 ], | 253 ], |
| 252 extras_require={ | 254 extras_require={ |
| 253 "charting": ['pygal'], | 255 "charting": ['pygal'], |
| 254 "jinja2": ['jinja2'], | 256 "jinja2": ['jinja2'], |
| 255 "extras": [ 'brotli', 'pytz'], | 257 "extras": ['brotli', 'pytz'], |
| 256 "test": ['pytest > 7.0.0'], | 258 "test": ['pytest > 7.0.0'], |
| 257 }, | 259 }, |
| 258 # Override certain command classes with our own ones | 260 # Override certain command classes with our own ones |
| 259 cmdclass={'build_doc': build_doc, | 261 cmdclass={'build_doc': build_doc, |
| 260 'build': build, | 262 'build': build, |
| 261 'bdist_rpm': bdist_rpm, | 263 'bdist_rpm': bdist_rpm, |
| 262 'install_lib': install_lib, | 264 'install_lib': install_lib, |
| 263 }, | 265 }, |
| 264 packages=packages, | 266 packages=packages, |
| 265 entry_points={ | 267 entry_points={ |
| 266 'console_scripts': scripts | 268 'console_scripts': scripts, |
| 267 }, | 269 }, |
| 268 data_files=data_files) | 270 data_files=data_files) |
| 271 | |
| 269 | 272 |
| 270 if __name__ == '__main__': | 273 if __name__ == '__main__': |
| 271 | 274 |
| 272 # Prevent `pip install roundup` from building bdist_wheel. | 275 # Prevent `pip install roundup` from building bdist_wheel. |
| 273 # Man pages, templates, locales installed under site-packages not | 276 # Man pages, templates, locales installed under site-packages not |
