Commits

yedpodtrzitko committed cf4813a

some more fixes for setuptools

Comments (0)

Files changed (11)

tart/tart_conf.py

+import re
+
+from os.path import abspath, dirname, join
+
+
+ROOT_DIR = abspath(dirname(__file__))
+TART_INI = 'tart.ini'       # found in current or ancestor folder
+STATE_DIR = '.tart-state'   # in TART_INI's folder
+CLEANPAT = '[{}]+'.format(re.escape(r'/\\.:@'))
+
+# define here just in case we find a reason to change it, so we don't have
+# to do a messy global replace
+NAME = 'tart'
+
+ININAME = 'tart-project.ini'       # found in current or ancestor folder
+DEFSECTION = 'project'
+
+BUILD_ID = False
+
+DEPLOY_DEFAULT_TIMEOUT = 1.0
+DEPLOY_MIN_LATENCY = 0.25
+DEPLOY_DEBUG = True

tart/tart_runner.py

 
 from os.path import exists, join
 
-from .tartutil.tart_conf import NAME
+from tart.tart_conf import NAME
 
 
 def help():
         help()
     else:
         try:
-            import_name = (__package__, 'commands', args.cmd)
+            import_name = ('tart', 'tartutil', 'commands', args.cmd)
             mod = importlib.import_module(".".join(import_name))
         except ImportError:
             if exists(join(*import_name) + ".py"):

tart/tartutil/__main__.py

-#!/usr/bin/env python
-
-import argparse
-import importlib
-
-from os.path import exists, join
-from .tart_conf import NAME
-
-
-def help():
-    parser.print_help()
-
-
-def main():
-    global parser
-    parser = argparse.ArgumentParser(prog=NAME)
-    parser.add_argument('-q', '--quiet', action='store_true',
-        help='silence all non-critical output')
-    parser.add_argument('cmd', nargs='?',
-        help='subcommand')
-    parser.add_argument('rest', nargs=argparse.REMAINDER, metavar='...',
-        help='rest of arguments')
-
-    global args
-    args = parser.parse_args()
-
-    if not args.cmd:
-        help()
-    else:
-        try:
-            import_name = (__package__, 'commands', args.cmd)
-            mod = importlib.import_module(".".join(import_name))
-        except ImportError:
-            if exists(join(*import_name) + ".py"):
-                raise
-            print('{}: unknown command "{}"'.format(NAME, args.cmd))
-        else:
-            cmd = mod.Command(args)
-            cmd._run()
-
-
-if __name__ == '__main__':
-    main()

tart/tartutil/command.py

 
 import argparse
 
-from .tart_conf import NAME
+from tart.tart_conf import NAME
 
 
 class Command:

tart/tartutil/commands/__init__.py

-from ..tart_conf import DEPLOY_DEBUG
 from time import time
 
+from tart.tart_conf import DEPLOY_DEBUG
+
 
 def get_time(basetime=time()):
     '''Return seconds since the app started. This is used for timestamps

tart/tartutil/commands/package.py

 
 from .. import command, project
 from ..core import tart
-from ..tart_conf import BUILD_ID
-from . import log
+
+from tart.tart_conf import BUILD_ID, ROOT_DIR
+
 
 BAR_TEMPLATE = join(dirname(__file__), 'bar-descriptor-template.xml')
 
             device = 'Device' if args.arch == 'arm' else 'Simulator'
             config.configuration = '{}-Debug'.format(device)
 
-        tartdistro = tart.relpath('tart')
-
         config.desc = self.project.config('description', 'The {} app'.format(appname))
         config.theme = self.project.config('theme', 'dark')
 
                         relpath_ = relpath(path, self.project.root)
                         include.add((self.project.root, relpath_))
 
-            include.update(self.find_modules(tartdistro))
+            include.update(self.find_modules())
 
         with tempfile.TemporaryDirectory(prefix='tart-', dir='.') as tdir:
             os.chdir(tdir)
                 else:
                     entry = 'TartStart-x86'
 
-                addlink(join(tartdistro, 'entry'), entry)
+                addlink(join(ROOT_DIR, 'entry'), entry)
 
                 # this is full of ugliness... we'll have to clean up
                 # the path stuff since the @optionfile approach has
 
                 # TODO: remove this very special handling for assets/tart.js
                 if args.mode != 'quick':
-                    addlink(join(tartdistro), 'assets/tart.js')
+                    addlink(join(ROOT_DIR), 'assets/tart.js')
 
                 with open('build.info', 'w') as fbuild:
                     print(dt.datetime.now(), file=fbuild)
         with open(path + 'c', 'wb') as pyc:
             pyc.write(bytecode)
 
-    def find_modules(self, tartdir):
-        tartpydir = join(tartdir, 'python')
+    def find_modules(self):
+        tartpydir = join(ROOT_DIR, 'python')
         searchpath = [tartpydir, self.project.root]
         for path in sys.path:
             if 'site-packages' in path:
                 searchpath.append(path)
 
         finder = modulefinder.ModuleFinder(path=searchpath)
-        finder.run_script(join(tartpydir, 'blackberry_tart.py'))
+        print(join(ROOT_DIR, 'python', 'blackberry_tart.py'))
+        finder.run_script(join(ROOT_DIR, 'python', 'blackberry_tart.py'))
 
         modules = set()
         for name, mod in finder.modules.items():

tart/tartutil/commands/quickdeploy.py

 from .. import command
 from ..core import tart
 from ..project import Project
-from ..tart_conf import DEPLOY_DEFAULT_TIMEOUT, DEPLOY_DEBUG, DEPLOY_MIN_LATENCY
+
+from tart.tart_conf import DEPLOY_DEFAULT_TIMEOUT, DEPLOY_DEBUG, DEPLOY_MIN_LATENCY
 
 
 # our section name in config files (appears in square brackets)

tart/tartutil/commands/template.py

 
 from .. import command
 
-from ..tart_conf import ININAME
+from tart.tart_conf import ININAME
 
 from ..core import tart
 

tart/tartutil/core.py

 '''Tart core stuff.'''
+from genericpath import isfile
 
 import os
 import configparser
 import re
 
-from os.path import join, dirname, normpath, isfile, exists
-from .decorators import cached_property
-from .tart_conf import STATE_DIR, TART_INI, CLEANPAT
+from os.path import join, normpath, exists, expanduser
 
+from tart.tart_conf import STATE_DIR, TART_INI, CLEANPAT, ROOT_DIR
+from tart.tartutil.decorators import cached_property
 
-#------------------------------------------------
-#
+
 class Tart:
-    def __init__(self):
-        self.root = self.get_tart_root()
 
     @cached_property
     def statedir(self):
         '''Retrieve Tart state folder, creating if it doesn't exist.'''
-        statedir = join(self.root, STATE_DIR)
+        statedir = join(ROOT_DIR, STATE_DIR)
         if not exists(statedir):
             os.makedirs(statedir, exist_ok=True)
         return statedir
         return self.get_tart_ini()
 
     @staticmethod
-    def get_tart_root():
-        '''Search for a Tart configuration (ini) file.'''
-        folder = normpath(os.getcwd())
-        while folder != dirname(folder):
-            if isfile(join(folder, TART_INI)):
-                return folder
-
-            folder = dirname(folder)
-
-        raise ValueError('file not found: {}'.format(TART_INI))
-
-    @staticmethod
     def get_tart_ini():
         '''Read Tart configuration (ini) file.'''
-        root = Tart.get_tart_root()
         ini = configparser.ConfigParser()
-        ini.read(join(root, TART_INI))
+        ini_paths = (
+            join(expanduser('~'), '.tart', TART_INI),
+            join(ROOT_DIR, TART_INI),
+        )
+
+        for try_ini in ini_paths:
+            if isfile(try_ini):
+                ini.read(try_ini)
+
         return ini
 
     def get_cache_path(self, name, folder=''):

tart/tartutil/project.py

 
 from os.path import join, basename, normpath, dirname, abspath, isfile
 
-from .tart_conf import ININAME, DEFSECTION
+from tart.tart_conf import ININAME, DEFSECTION
+from tart.tartutil.decorators import cached_property
 
-from .decorators import cached_property
 
-
-#------------------------------------------------
-#
 class Project:
     def __init__(self, path):
         self.root = self.get_root(path)

tart/tartutil/tart_conf.py

-import re
-
-TART_INI = 'tart.ini'       # found in current or ancestor folder
-STATE_DIR = '.tart-state'   # in TART_INI's folder
-CLEANPAT = '[{}]+'.format(re.escape(r'/\\.:@'))
-
-# define here just in case we find a reason to change it, so we don't have
-# to do a messy global replace
-NAME = 'tart'
-
-ININAME = 'tart-project.ini'       # found in current or ancestor folder
-DEFSECTION = 'project'
-
-BUILD_ID = False
-
-DEPLOY_DEFAULT_TIMEOUT = 1.0
-DEPLOY_MIN_LATENCY = 0.25
-DEPLOY_DEBUG = True