Rewrite setup.py; seems to help with py2app

Sun, 05 Dec 2021 13:34:02 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 05 Dec 2021 13:34:02 +0200
changeset 135
45c1a38f8709
parent 134
a7aa8ca7b3d0
child 136
c40f341a99e0
child 137
41eca7c39c39
child 138
26080284df3c

Rewrite setup.py; seems to help with py2app

borgend/__main__.py file | annotate | diff | comparison | revisions
setup.py file | annotate | diff | comparison | revisions
--- a/borgend/__main__.py	Sun Dec 05 13:09:12 2021 +0200
+++ b/borgend/__main__.py	Sun Dec 05 13:34:02 2021 +0200
@@ -44,86 +44,86 @@
     action='store_true',
     help='Set logging level to debug')
 
-args=parser.parse_args()
-
-#
-# Done parsing args, import our own modules, and launch everything
-#
+def main():
+    args=parser.parse_args()
 
-import borgend.config as config
-import borgend.dreamtime as dreamtime
-import borgend.loggers as loggers
-from borgend.scheduler import Scheduler
-from borgend.repository import Repository
-from borgend.backup import Backup
+    # Done parsing args, import our own modules, and launch everything
+    import borgend.config as config
+    import borgend.dreamtime as dreamtime
+    import borgend.loggers as loggers
+    from borgend.scheduler import Scheduler
+    from borgend.repository import Repository
+    from borgend.backup import Backup
 
-logger=loggers.mainlogger
+    logger=loggers.mainlogger
 
-if args.debug:
-    logger.setLevel(logging.DEBUG)
+    if args.debug:
+        logger.setLevel(logging.DEBUG)
+
+    tray = None
+    repos=[]
+    backups=[]
 
-tray = None
-repos=[]
-backups=[]
+    try:
+        dreamtime.start_monitoring()
 
-try:
-    dreamtime.start_monitoring()
+        scheduler = Scheduler()
+        scheduler.start()
 
-    scheduler = Scheduler()
-    scheduler.start()
-
-    repoconfigs=config.settings['repositories']
+        repoconfigs=config.settings['repositories']
 
-    logger.info('Initialising repositories')
-    for i in range(len(repoconfigs)):
-        r=Repository(i, repoconfigs[i])
-        repos.append(r)
+        logger.info('Initialising repositories')
+        for i in range(len(repoconfigs)):
+            r=Repository(i, repoconfigs[i])
+            repos.append(r)
 
-    backupconfigs=config.settings['backups']
+        backupconfigs=config.settings['backups']
 
-    logger.info('Initialising backups')
-    for i in range(len(backupconfigs)):
-        b=Backup(i, backupconfigs[i], scheduler)
-        backups.append(b)
+        logger.info('Initialising backups')
+        for i in range(len(backupconfigs)):
+            b=Backup(i, backupconfigs[i], scheduler)
+            backups.append(b)
 
-    if args.notray or platform.system()!='Darwin':
-        # Wait for scheduler to finish
-        run=scheduler.join
-    else:
-        # This is needed for Ctrl+C to work.
-        # TODO: proper exit handler, which seems to require
-        # ditching/forking/extending rumps to extend the NSApp class
-        from PyObjCTools.AppHelper import installMachInterrupt
-        installMachInterrupt()
-        # Start UI, and let it handle exit control
-        from borgend.ui import BorgendTray
-        tray=BorgendTray(backups);
-        run=tray.run
+        if args.notray or platform.system()!='Darwin':
+            # Wait for scheduler to finish
+            run=scheduler.join
+        else:
+            # This is needed for Ctrl+C to work.
+            # TODO: proper exit handler, which seems to require
+            # ditching/forking/extending rumps to extend the NSApp class
+            from PyObjCTools.AppHelper import installMachInterrupt
+            installMachInterrupt()
+            # Start UI, and let it handle exit control
+            from borgend.ui import BorgendTray
+            tray=BorgendTray(backups);
+            run=tray.run
 
-    for r in repos:
-        r.start()
+        for r in repos:
+            r.start()
 
-    for b in backups:
-        b.start()
+        for b in backups:
+            b.start()
+
+        run()
 
-    run()
+    except Exception as err:
+        # TODO: Should write errors here to stderr;
+        # perhaps add an extra stderr logger for error level messages
+        logger.exception("Exception fell through: exiting")
 
-except Exception as err:
-    # TODO: Should write errors here to stderr;
-    # perhaps add an extra stderr logger for error level messages
-    logger.exception("Exception fell through: exiting")
+    finally:
+        logger.debug("Exiting")
 
-finally:
-    logger.debug("Exiting")
+        for b in backups:
+            b.terminate()
 
-    for b in backups:
-        b.terminate()
-
-    for r in repos:
-        r.terminate()
+        for r in repos:
+            r.terminate()
 
-    if tray:
-        tray.quit()
-    else:
-        logging.shutdown()
+        if tray:
+            tray.quit()
+        else:
+            logging.shutdown()
 
+if __name__ == "__main__":
+    sys.exit(main())
--- a/setup.py	Sun Dec 05 13:09:12 2021 +0200
+++ b/setup.py	Sun Dec 05 13:34:02 2021 +0200
@@ -1,20 +1,32 @@
-from setuptools import setup
-
-APP = ['borgend.py']
-DATA_FILES = []
-OPTIONS = {
-    'argv_emulation': False,
-    'plist': {
-        'LSUIElement': True,
-    },
-    'packages': ['rumps', 'keyring', 'yaml'],
-    'includes': ['xdg'],
-    'excludes': ['wx', 'PyQt5', 'matplotlib', 'numpy', 'scipy'],
-}
+from setuptools import setup, find_packages
 
 setup(
-    app=APP,
-    data_files=DATA_FILES,
-    options={'py2app': OPTIONS},
+    name = 'borgend',
+    version = '0.1.0',
+    author = 'Tuomo Valkonen',
+    author_email = 'tuomov@iki.fi',
+    url = 'https://tuomov.iki.fi/software/borgend/',
+    packages = ['borgend'],
+    data_files=[],
+    entry_points= {
+        "console_scripts": ["borgend = borgend.__main__:main"]
+    },
+    #setup_requires=['py2app'],
+    install_requires=[
+        "rumps",
+        "keyring",
+        "PyYAML",
+        "xdg;platform_system!='darwin'",
+    ],
+    app=['borgend/__main__.py'],
     setup_requires=['py2app'],
+    options={
+        'py2app': {
+            'argv_emulation': False,
+            'plist': {
+                'LSUIElement': True,
+            },
+            'excludes': ['wx', 'matplotlib', 'numpy', 'scipy', 'sip'],
+        }
+    }
 )

mercurial