Diff of /pyke/knowledge_engine.py [2aac52] .. [2922d1]  Maximize  Restore

  Switch to unified view

a/pyke/knowledge_engine.py b/pyke/knowledge_engine.py
...
...
425
        self.get_rb(rb_name).trace(rule_name)
425
        self.get_rb(rb_name).trace(rule_name)
426
426
427
    def untrace(self, rb_name, rule_name):
427
    def untrace(self, rb_name, rule_name):
428
        self.get_rb(rb_name).untrace(rule_name)
428
        self.get_rb(rb_name).untrace(rule_name)
429
429
430
Compiled_suffix = None
431
430
def _get_target_pkg(target_name):
432
def _get_target_pkg(target_name):
433
    global Compiled_suffix
431
    if debug: print >> sys.stderr, "_get_target_pkg", target_name
434
    if debug: print >> sys.stderr, "_get_target_pkg", target_name
432
    module = target_pkg.import_(target_name)
435
    module = target_pkg.import_(target_name)
433
    path = module.__file__
436
    path = module.__file__
434
    if debug: print >> sys.stderr, "_get_target_pkg __file__ is", path
437
    if debug: print >> sys.stderr, "_get_target_pkg __file__ is", path
435
    if path.endswith(('.pyc', '.pyo')): path = path[:-1]
438
    do_reload = False
436
    compiled_path = path + ('o' if sys.flags.optimize else 'c')
439
    if path.endswith('.py'):
437
    if debug:
440
        if Compiled_suffix is None:
438
        print >> sys.stderr, "source path is", path
441
            # We don't know whether this compiles to .pyc or .pyo yet, so do a
439
        if os.path.exists(path):
442
            # reload just to be sure...
440
            print >> sys.stderr, "source path exists"
443
            do_reload = True
441
            print >> sys.stderr, "source path mtime", os.path.getmtime(path)
442
        else:
444
        else:
445
            source_path = path
446
            path = path[:-3] + Compiled_suffix
447
    else:
448
        assert path.endswith(('.pyc', '.pyo')), \
449
               'unknown file extension: %r' % (path,)
450
        Compiled_suffix = path[-4:]
451
        source_path = path[:-1]
452
    if not do_reload:
453
        if debug:
454
            print >> sys.stderr, "source path is", source_path
455
            if os.path.exists(source_path):
456
                print >> sys.stderr, "source path exists"
457
                print >> sys.stderr, "source path mtime", \
458
                                     os.path.getmtime(source_path)
459
            else:
443
            print >> sys.stderr, "source path does not exist"
460
                print >> sys.stderr, "source path does not exist"
444
        print >> sys.stderr, "compiled path is", compiled_path
461
            print >> sys.stderr, "compiled path is", path
445
        if os.path.exists(compiled_path):
462
            if os.path.exists(path):
446
            print >> sys.stderr, "compiled path exists"
463
                print >> sys.stderr, "compiled path exists"
447
            print >> sys.stderr, "compiled path mtime", \
464
                print >> sys.stderr, "compiled path mtime", \
448
                                 os.path.getmtime(compiled_path)
465
                                     os.path.getmtime(path)
449
        else:
466
            else:
450
            print >> sys.stderr, "compiled path does not exist"
467
                print >> sys.stderr, "compiled path does not exist"
451
    if not os.path.exists(compiled_path) or \
468
        if not os.path.exists(path) or \
452
          os.path.exists(path) and \
469
              os.path.exists(source_path) and \
453
          os.path.getmtime(path) > os.path.getmtime(compiled_path):
470
              os.path.getmtime(source_path) > os.path.getmtime(path):
471
            do_reload = True
472
    if do_reload:
454
        if debug:
473
        if debug:
455
            print >> sys.stderr, "_get_target_pkg doing reload for", target_name
474
            print >> sys.stderr, "_get_target_pkg doing reload for", target_name
456
        module = imp.reload(module)
475
        module = imp.reload(module)
476
        suffix = module.__file__[-4:]
477
        if suffix in ('.pyc', '.pyo'):
478
            Compiled_suffix = suffix
457
    if getattr(module, 'target_pkg_version', None) != pyke.target_pkg_version:
479
    if getattr(module, 'target_pkg_version', None) != pyke.target_pkg_version:
458
        if debug:
480
        if debug:
459
            print >> sys.stderr, "_get_target_pkg doing invalid version for", \
481
            print >> sys.stderr, "_get_target_pkg doing invalid version for", \
460
                                 target_name
482
                                 target_name
461
        return None
483
        return None
...
...
465
    r'''Returns path_to_package, package_name, remainder_path, zip_file_flag.
487
    r'''Returns path_to_package, package_name, remainder_path, zip_file_flag.
466
488
467
    If zip_file_flag is set, remainder_path is ''.
489
    If zip_file_flag is set, remainder_path is ''.
468
    '''
490
    '''
469
    path = os.path.normpath(os.path.abspath(path))
491
    path = os.path.normpath(os.path.abspath(path))
470
    if path.endswith(('.py', '.pyc', '.pyo')):
492
    if path.endswith(('.py', '.pyw', '.pyc', '.pyo')):
471
        path = os.path.dirname(path)
493
        path = os.path.dirname(path)
472
    package_name = ''
494
    package_name = ''
473
    remainder_path = ''
495
    remainder_path = ''
474
    remainder_package_name = ''
496
    remainder_package_name = ''
475
    ans = '', '', path, False
497
    ans = '', '', path, False
...
...
481
                if os.path.isdir(path):
503
                if os.path.isdir(path):
482
                    ans = path, package_name, remainder_path, False
504
                    ans = path, package_name, remainder_path, False
483
                else:
505
                else:
484
                    ans = path, remainder_package_name, '', True
506
                    ans = path, remainder_package_name, '', True
485
        parent_path, dir = os.path.split(path)
507
        parent_path, dir = os.path.split(path)
486
        if parent_path == '' or parent_path == '/' and dir == '':
508
        if parent_path == '' or parent_path == path:
487
            break
509
            break
488
        if _is_package_dir(path):
510
        if _is_package_dir(path):
489
            if package_name:
511
            if package_name:
490
                package_name = dir + '.' + package_name
512
                package_name = dir + '.' + package_name
491
            else:
513
            else:
...
...
505
    return ans
527
    return ans
506
528
507
def _is_package_dir(path):
529
def _is_package_dir(path):
508
    if not os.path.isdir(path): return False
530
    if not os.path.isdir(path): return False
509
    return os.path.exists(os.path.join(path, '__init__.py')) or \
531
    return os.path.exists(os.path.join(path, '__init__.py')) or \
532
           os.path.exists(os.path.join(path, '__init__.pyw')) or \
510
           os.path.exists(os.path.join(path, '__init__.pyc')) or \
533
           os.path.exists(os.path.join(path, '__init__.pyc')) or \
511
           os.path.exists(os.path.join(path, '__init__.pyo'))
534
           os.path.exists(os.path.join(path, '__init__.pyo'))
512
535
513
def in_sys_path(path):
536
def in_sys_path(path):
514
    r'''Assumes path is a normalized abspath.
537
    r'''Assumes path is a normalized abspath.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks