示例#1
0
def execute(args, parser):
    files = args.package_files

    for file in files:
        if not file.endswith('.tar.bz2'):
            raise RuntimeError("%s does not appear to be a conda package" % file)

        file = abspath(expanduser(file))
        t = tarfile.open(file)
        cext = False
        if args.show_imports:
            cext = has_cext(t, show=True)

        if not args.force and (cext or has_cext(t)):
            print("WARNING: Package %s has C extensions, skipping. Use -f to "
            "force conversion." % file)
            continue

        output_dir = args.output_dir
        file_dir, fn = split(file)
        if abspath(expanduser(output_dir)) == abspath(expanduser(file_dir)):
            raise RuntimeError("Cannot use the same output directory as the input files.")

        info = json.loads(t.extractfile('info/index.json').read().decode('utf-8'))
        source_type = 'unix' if info['platform'] in {'osx', 'linux'} else 'win'

        nonpy_unix = False
        nonpy_win = False

        for platform in args.platforms:
            dest_plat, dest_arch = platform.split('-')
            dest_type = 'unix' if dest_plat in {'osx', 'linux'} else 'win'

            if source_type == 'unix' and dest_type == 'win':
                nonpy_unix = nonpy_unix or has_nonpy_entry_points(t,
                    unix_to_win=True, show=args.verbose)
            if source_type == 'win' and dest_type == 'unix':
                nonpy_win = nonpy_win or has_nonpy_entry_points(t,
                    unix_to_win=False, show=args.verbose)

            if nonpy_unix and not args.force:
                print(("WARNING: Package %s has non-Python entry points, "
                    "skipping %s to %s conversion. Use -f to force.") % (file,
                        info['platform'], platform))
                continue

            if nonpy_win and not args.force:
                print(("WARNING: Package %s has entry points, which are not "
                    "supported yet. Skipping %s to %s conversion. Use -f to force.") % (file,
                        info['platform'], platform))
                continue

            file_map = get_pure_py_file_map(t, platform)

            if args.dry_run:
                print("Would convert %s from %s to %s" % (file, info['platform'], dest_plat))
                if args.verbose:
                    pprint.pprint(file_map)
                continue
            else:
                print("Converting %s from %s to %s" % (file, info['platform'], dest_plat))

            tar_update(t, join(output_dir, fn), file_map, verbose=args.verbose)
示例#2
0
def execute(args, parser):
    files = args.package_files

    for file in files:
        # Don't use byte literals for paths in Python 2
        if not PY3:
            file = file.decode(getpreferredencoding())

        if not file.endswith('.tar.bz2'):
            raise RuntimeError("%s does not appear to be a conda package"
                               % file)

        file = abspath(expanduser(file))
        with tarfile.open(file) as t:
            if not args.force and has_cext(t, show=args.show_imports):
                print("WARNING: Package %s has C extensions, skipping. Use -f to "
                      "force conversion." % file)
                continue

            output_dir = args.output_dir
            if not PY3:
                output_dir = output_dir.decode(getpreferredencoding())
            file_dir, fn = split(file)

            info = json.loads(t.extractfile('info/index.json')
                              .read().decode('utf-8'))
            source_type = 'unix' if info['platform'] in {'osx', 'linux'} else 'win'

            nonpy_unix = False
            nonpy_win = False

            if 'all' in args.platforms:
                args.platforms = ['osx-64', 'linux-32', 'linux-64', 'win-32', 'win-64']
            for platform in args.platforms:
                if not PY3:
                    platform = platform.decode('utf-8')
                dest_plat = platform.split('-')[0]
                dest_type = 'unix' if dest_plat in {'osx', 'linux'} else 'win'


                if source_type == 'unix' and dest_type == 'win':
                    nonpy_unix = nonpy_unix or has_nonpy_entry_points(t,
                                                                      unix_to_win=True,
                                                                      show=args.verbose)
                if source_type == 'win' and dest_type == 'unix':
                    nonpy_win = nonpy_win or has_nonpy_entry_points(t,
                                                                    unix_to_win=False,
                                                                    show=args.verbose)

                if nonpy_unix and not args.force:
                    print(("WARNING: Package %s has non-Python entry points, "
                           "skipping %s to %s conversion. Use -f to force.") %
                          (file, info['platform'], platform))
                    continue

                if nonpy_win and not args.force:
                    print(("WARNING: Package %s has entry points, which are not "
                           "supported yet. Skipping %s to %s conversion. Use -f to force.") %
                          (file, info['platform'], platform))
                    continue

                file_map = get_pure_py_file_map(t, platform)

                if args.dry_run:
                    print("Would convert %s from %s to %s" %
                          (file, info['platform'], dest_plat))
                    if args.verbose:
                        pprint.pprint(file_map)
                    continue
                else:
                    print("Converting %s from %s to %s" %

                          (file, info['platform'], platform))

                if not exists(join(output_dir, platform)):
                    makedirs(join(output_dir, platform))
                tar_update(t, join(output_dir, platform, fn), file_map, verbose=args.verbose)
示例#3
0
def conda_convert(file, args):
    if not args.show_imports and args.platforms is None:
        sys.exit(
            'Error: --platform option required for conda package conversion')

    with tarfile.open(file) as t:
        if args.show_imports:
            has_cext(t, show=True)
            return

        if not args.force and has_cext(t, show=args.show_imports):
            print("WARNING: Package %s has C extensions, skipping. Use -f to "
                  "force conversion." % file,
                  file=sys.stderr)
            return

        file_dir, fn = split(file)

        info = json.loads(
            t.extractfile('info/index.json').read().decode('utf-8'))
        source_type = 'unix' if info['platform'] in {'osx', 'linux'} else 'win'

        nonpy_unix = False
        nonpy_win = False

        if 'all' in args.platforms:
            args.platforms = [
                'osx-64', 'linux-32', 'linux-64', 'win-32', 'win-64'
            ]
        for platform in args.platforms:
            output_dir = join(args.output_dir, platform)
            if abspath(expanduser(join(output_dir, fn))) == file:
                if not args.quiet:
                    print("Skipping %s/%s. Same as input file" %
                          (platform, fn))
                continue
            if not PY3:
                platform = platform.decode('utf-8')
            dest_plat = platform.split('-')[0]
            dest_type = 'unix' if dest_plat in {'osx', 'linux'} else 'win'

            if source_type == 'unix' and dest_type == 'win':
                nonpy_unix = nonpy_unix or has_nonpy_entry_points(
                    t, unix_to_win=True, show=args.verbose, quiet=args.quiet)
            if source_type == 'win' and dest_type == 'unix':
                nonpy_win = nonpy_win or has_nonpy_entry_points(
                    t, unix_to_win=False, show=args.verbose, quiet=args.quiet)

            if nonpy_unix and not args.force:
                print(("WARNING: Package %s has non-Python entry points, "
                       "skipping %s to %s conversion. Use -f to force.") %
                      (file, info['platform'], platform),
                      file=sys.stderr)
                continue

            if nonpy_win and not args.force:
                print((
                    "WARNING: Package %s has entry points, which are not "
                    "supported yet. Skipping %s to %s conversion. Use -f to force."
                ) % (file, info['platform'], platform),
                      file=sys.stderr)
                continue

            file_map = get_pure_py_file_map(t, platform)

            if args.dry_run:
                if not args.quiet:
                    print("Would convert %s from %s to %s" %
                          (file, info['platform'], dest_plat))
                if args.verbose:
                    pprint.pprint(file_map)
                continue
            else:
                if not args.quiet:
                    print("Converting %s from %s to %s" %
                          (file, info['platform'], platform))

            if not isdir(output_dir):
                os.makedirs(output_dir)
            tar_update(t,
                       join(output_dir, fn),
                       file_map,
                       verbose=args.verbose,
                       quiet=args.quiet)
示例#4
0
def execute(args, parser):
    files = args.package_files

    for file in files:
        # Don't use byte literals for paths in Python 2
        if not PY3:
            file = file.decode(getpreferredencoding())

        if not file.endswith('.tar.bz2'):
            raise RuntimeError("%s does not appear to be a conda package" %
                               file)

        file = abspath(expanduser(file))
        with tarfile.open(file) as t:
            if not args.force and has_cext(t, show=args.show_imports):
                print(
                    "WARNING: Package %s has C extensions, skipping. Use -f to "
                    "force conversion." % file)
                continue

            output_dir = args.output_dir
            if not PY3:
                output_dir = output_dir.decode(getpreferredencoding())
            file_dir, fn = split(file)

            info = json.loads(
                t.extractfile('info/index.json').read().decode('utf-8'))
            source_type = 'unix' if info['platform'] in {'osx', 'linux'
                                                         } else 'win'

            nonpy_unix = False
            nonpy_win = False

            if 'all' in args.platforms:
                args.platforms = [
                    'osx-64', 'linux-32', 'linux-64', 'win-32', 'win-64'
                ]
            for platform in args.platforms:
                if not PY3:
                    platform = platform.decode('utf-8')
                dest_plat = platform.split('-')[0]
                dest_type = 'unix' if dest_plat in {'osx', 'linux'} else 'win'

                if source_type == 'unix' and dest_type == 'win':
                    nonpy_unix = nonpy_unix or has_nonpy_entry_points(
                        t, unix_to_win=True, show=args.verbose)
                if source_type == 'win' and dest_type == 'unix':
                    nonpy_win = nonpy_win or has_nonpy_entry_points(
                        t, unix_to_win=False, show=args.verbose)

                if nonpy_unix and not args.force:
                    print(("WARNING: Package %s has non-Python entry points, "
                           "skipping %s to %s conversion. Use -f to force.") %
                          (file, info['platform'], platform))
                    continue

                if nonpy_win and not args.force:
                    print((
                        "WARNING: Package %s has entry points, which are not "
                        "supported yet. Skipping %s to %s conversion. Use -f to force."
                    ) % (file, info['platform'], platform))
                    continue

                file_map = get_pure_py_file_map(t, platform)

                if args.dry_run:
                    print("Would convert %s from %s to %s" %
                          (file, info['platform'], dest_plat))
                    if args.verbose:
                        pprint.pprint(file_map)
                    continue
                else:
                    print("Converting %s from %s to %s" %
                          (file, info['platform'], platform))

                if not exists(join(output_dir, platform)):
                    makedirs(join(output_dir, platform))
                tar_update(t,
                           join(output_dir, platform, fn),
                           file_map,
                           verbose=args.verbose)
示例#5
0
def conda_convert(file, args):
    if not args.show_imports and args.platforms is None:
        sys.exit('Error: --platform option required for conda package conversion')

    with tarfile.open(file) as t:
        if args.show_imports:
            has_cext(t, show=True)
            return

        if not args.force and has_cext(t, show=args.show_imports):
            print("WARNING: Package %s has C extensions, skipping. Use -f to "
                  "force conversion." % file, file=sys.stderr)
            return

        file_dir, fn = split(file)

        info = json.loads(t.extractfile('info/index.json')
                          .read().decode('utf-8'))
        source_type = 'unix' if info['platform'] in {'osx', 'linux'} else 'win'

        nonpy_unix = False
        nonpy_win = False

        if 'all' in args.platforms:
            args.platforms = ['osx-64', 'linux-32', 'linux-64', 'win-32', 'win-64']
        for platform in args.platforms:
            output_dir = join(args.output_dir, platform)
            if abspath(expanduser(join(output_dir, fn))) == file:
                if not args.quiet:
                    print("Skipping %s/%s. Same as input file" % (platform, fn))
                continue
            if not PY3:
                platform = platform.decode('utf-8')
            dest_plat = platform.split('-')[0]
            dest_type = 'unix' if dest_plat in {'osx', 'linux'} else 'win'

            if source_type == 'unix' and dest_type == 'win':
                nonpy_unix = nonpy_unix or has_nonpy_entry_points(t,
                    unix_to_win=True,
                    show=args.verbose,
                    quiet=args.quiet)
            if source_type == 'win' and dest_type == 'unix':
                nonpy_win = nonpy_win or has_nonpy_entry_points(t,
                    unix_to_win=False,
                    show=args.verbose,
                    quiet=args.quiet)

            if nonpy_unix and not args.force:
                print(("WARNING: Package %s has non-Python entry points, "
                       "skipping %s to %s conversion. Use -f to force.") %
                      (file, info['platform'], platform), file=sys.stderr)
                continue

            if nonpy_win and not args.force:
                print(("WARNING: Package %s has entry points, which are not "
                       "supported yet. Skipping %s to %s conversion. Use -f to force.") %
                      (file, info['platform'], platform), file=sys.stderr)
                continue

            file_map = get_pure_py_file_map(t, platform)

            if args.dry_run:
                if not args.quiet:
                    print("Would convert %s from %s to %s" %
                        (file, info['platform'], dest_plat))
                if args.verbose:
                    pprint.pprint(file_map)
                continue
            else:
                if not args.quiet:
                    print("Converting %s from %s to %s" %
                        (file, info['platform'], platform))

            if not isdir(output_dir):
                os.makedirs(output_dir)
            tar_update(t, join(output_dir, fn), file_map,
                verbose=args.verbose, quiet=args.quiet)