changeset 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
files setup.py
diffstat 1 files changed, 42 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Sun May 05 17:20:35 2024 -0400
+++ b/setup.py	Sun May 05 18:19:04 2024 -0400
@@ -40,7 +40,7 @@
 
     'e' -- A glob pattern"""
 
-    return (d, [f for f in glob('%s/%s'%(d, e)) if os.path.isfile(f)])
+    return (d, [f for f in glob('%s/%s' % (d, e)) if os.path.isfile(f)])
 
 
 def mapscript(path):
@@ -51,6 +51,7 @@
     script = module.replace('_', '-')
     return '%s = roundup.scripts.%s:run' % (script, module)
 
+
 def make_data_files_absolute(data_files, prefix):
     """Using setuptools data files are put under the egg install directory
        if the datafiles are relative paths. We don't want this. Data files
@@ -65,51 +66,51 @@
 
     return new_data_files
 
+
 def get_prefix():
     """Get site specific prefix using --prefix, platform lib or
        sys.prefix.
     """
-    prefix_arg=False
-    prefix=""
+    prefix_arg = False
+    prefix = ""
     for a in sys.argv:
         if prefix_arg:
-            prefix=a
+            prefix = a
             break
         # is there a short form -p or something for this??
         if a.startswith('--prefix'):
             if a == '--prefix':
                 # next argument is prefix
-                prefix_arg=True
+                prefix_arg = True
                 continue
-            else:
-                # strip '--prefix='
-                prefix=a[9:]
+            # strip '--prefix='
+            prefix = a[9:]
     if prefix:
         return prefix
-    else:
-        if sys.platform.startswith('win'):
-            # on windows, using pip to install and
-            # prefixing data file paths with c:\path\a\b\...
-            # results in treatment as a relative path.
-            # The result is files are buried under:
-            # platlib\path\a\b\...\share\ and not findable by
-            # Roundup. So return no prefix which places the files at
-            # platlib\share\{doc,locale,roundup} where roundup can
-            # find templates/translations etc.
-            # sigh....
-            return ""
 
-        # start with the platform library
-        plp = get_path('platlib')
-        # nuke suffix that matches lib/* and return prefix
-        head, tail = os.path.split(plp)
-        old_head = None
-        while tail.lower() not in ['lib', 'lib64' ] and head != old_head:
-            old_head = head
-            head, tail = os.path.split(head)
-        if head == old_head:
-            head = sys.prefix
-        return head
+    if sys.platform.startswith('win'):
+        # on windows, using pip to install and
+        # prefixing data file paths with c:\path\a\b\...
+        # results in treatment as a relative path.
+        # The result is files are buried under:
+        # platlib\path\a\b\...\share\ and not findable by
+        # Roundup. So return no prefix which places the files at
+        # platlib\share\{doc,locale,roundup} where roundup can
+        # find templates/translations etc.
+        # sigh....
+        return ""
+
+    # start with the platform library
+    plp = get_path('platlib')
+    # nuke suffix that matches lib/* and return prefix
+    head, tail = os.path.split(plp)
+    old_head = None
+    while tail.lower() not in ['lib', 'lib64'] and head != old_head:
+        old_head = head
+        head, tail = os.path.split(head)
+    if head == old_head:
+        head = sys.prefix
+    return head
 
 
 def main():
@@ -132,17 +133,17 @@
 
     # build list of zope files/directories
     Zope = {}
-    Zope['module'] = [f for f in glob('frontends/ZRoundup/*.py')]
-    Zope['module'].append('frontends/ZRoundup/refresh.txt');
-    Zope['icons'] = [f for f in glob('frontends/ZRoundupscripts/*.gif')]
-    Zope['dtml'] = [f for f in glob('frontends/ZRoundupscripts/*.dtml')]
+    Zope['module'] = list(glob('frontends/ZRoundup/*.py'))
+    Zope['module'].append('frontends/ZRoundup/refresh.txt')
+    Zope['icons'] = list(glob('frontends/ZRoundupscripts/*.gif'))
+    Zope['dtml'] = list(glob('frontends/ZRoundupscripts/*.dtml'))
 
     data_files = [
         ('share/roundup/cgi-bin', ['frontends/roundup.cgi']),
         ('share/roundup/frontends', ['frontends/wsgi.py']),
         ('share/roundup/frontends/ZRoundup', Zope['module']),
         ('share/roundup/frontends/ZRoundup/icons', Zope['icons']),
-        ('share/roundup/frontends/ZRoundup/dtml', Zope['dtml'])
+        ('share/roundup/frontends/ZRoundup/dtml', Zope['dtml']),
     ]
     # install man pages on POSIX platforms
     if os.name == 'posix':
@@ -191,7 +192,8 @@
     # because the distutils installer will try to use the mbcs codec
     # which isn't available on non-windows platforms. See also
     # http://bugs.python.org/issue10945
-    long_description=open('doc/announcement.txt').read()
+    with open('doc/announcement.txt') as announcement:
+        long_description = announcement.read()
     try:
         # attempt to interpret string as 'ascii'
         long_description.encode('ascii')
@@ -252,7 +254,7 @@
           extras_require={
               "charting": ['pygal'],
               "jinja2": ['jinja2'],
-              "extras": [ 'brotli', 'pytz'],
+              "extras": ['brotli', 'pytz'],
               "test": ['pytest > 7.0.0'],
               },
           # Override certain command classes with our own ones
@@ -263,10 +265,11 @@
                      },
           packages=packages,
           entry_points={
-              'console_scripts': scripts
+              'console_scripts': scripts,
           },
           data_files=data_files)
 
+
 if __name__ == '__main__':
 
     # Prevent `pip install roundup` from building bdist_wheel.

Roundup Issue Tracker: http://roundup-tracker.org/