Beispiel #1
0
def rename_hook(config, fro, to):
    # could match on dotted_name< 'hook' '.' 'subscribe' '.' '{name}' >
    # but the replacement gets more complicated...
    selector = "'{name}'".format(name=fro)
    q = bowler.Query(config).select_pattern(selector)
    q.current.kwargs["name"] = fro
    return q.rename(to)
Beispiel #2
0
def do_migrate(args):
    if "bowler" not in sys.modules:
        print("bowler can't be found, not migrating config file")
        print("install it and try again")
        sys.exit(1)

    config_dir = os.path.dirname(args.config)
    for py, backup in file_and_backup(config_dir):
        shutil.copyfile(py, backup)

    for m in MIGRATIONS:
        q = bowler.Query(config_dir)
        m(q).execute(interactive=args.interactive, write=True)

    changed = False
    for py, backup in file_and_backup(config_dir):
        backup = py + BACKUP_SUFFIX
        if not filecmp.cmp(py, backup, shallow=False):
            changed = True
            break

    if not changed:
        print("Config unchanged.")
        for _, backup in file_and_backup(config_dir):
            os.remove(backup)
Beispiel #3
0
    def _patch_imports(self, resolver, output_path: Path) -> int:
        # select modules to patch imports
        query = bowler.Query()
        query.paths = []
        for package in resolver.graph.metainfo.package.packages:
            for module_path in package:
                query.paths.append(str(module_path))

        # patch vendors if it's outside of main package
        package_path = resolver.graph.metainfo.package.packages[0].path
        if package_path.resolve() not in output_path.resolve().parents:
            query.paths.append(str(output_path))

        # set renamings
        root = Path(self.config['project'])
        for library in output_path.iterdir():
            if library.name in self.config['vendor']['exclude']:
                continue
            library_module = '.'.join(library.resolve().relative_to(
                str(root)).parts)
            self.logger.debug('patch imports',
                              extra=dict(
                                  old_name=library.name,
                                  new_name=library_module,
                              ))
            query = transform_imports(
                query=query,
                old_name=library.name,
                new_name=library_module,
            )

        # execute renaming
        query.execute(interactive=False, write=True, silent=True)
        return len(query.paths)
Beispiel #4
0
 def f(config, fro=fro, to=to):
     return (bowler.Query(config).select_module(fro).rename(to))
Beispiel #5
0
def pacman_to_checkupdates(config):
    return (bowler.Query(config).select_class("Pacman").rename("CheckUpdates"))
Beispiel #6
0
def threaded_poll_text_rename(config):
    return (bowler.Query(config).select_class("ThreadedPollText").rename(
        "ThreadPoolText"))
Beispiel #7
0
def tile_master_windows_rename(config):
    return (bowler.Query(config).select_function("Tile").modify_argument(
        "masterWindows", "master_length"))