Exemplo n.º 1
0
def dist(opts):
    config = load_config(opts)
    reset_conda_env(opts, config)
    try:
        # Create a build environment.
        build_path = os.path.join(opts.work_path, "build")
        rimraf(build_path)
        mkdirp(build_path)
        try:
            # Copy source.
            with mark_task(opts, "Copying source"):
                shell(
                    opts,
                    "cd {root_path} && git archive HEAD --format=tar | tar -x -C {build_path}",
                    root_path=opts.root_path,
                    build_path=build_path,
                )
            # Download deps.
            download_conda_deps(opts)
            download_pip_deps(opts, config)
            # Copy libs.
            with mark_task(opts, "Copying libs"):
                shutil.copytree(
                    opts.lib_path,
                    os.path.join(
                        build_path,
                        os.path.relpath(opts.lib_path, opts.root_path)),
                )
            # Compress the build.
            dist_path = os.path.join(opts.root_path, opts.dist_dir)
            mkdirp(dist_path)
            dist_file = os.path.join(
                "{name}-{version}-{os_name}-amd64.zip".format(
                    name=config.get("name", os.path.basename(opts.root_path)),
                    version=config.get("version", "1.0.0"),
                    os_name=opts.os_name,
                ))
            with mark_task(opts, "Creating archive {}".format(dist_file)):
                dist_file_path = os.path.join(dist_path, dist_file)
                rimraf(dist_file_path)
                shell(
                    opts,
                    "cd {build_path} && zip -9 -qq -r {dist_file_path} './'",
                    build_path=build_path,
                    dist_file_path=dist_file_path,
                )
        finally:
            rimraf(build_path)
    finally:
        delete_conda_env(opts)
Exemplo n.º 2
0
def dist(opts):
    config = load_config(opts)
    reset_conda_env(opts, config)
    try:
        # Create a build environment.
        build_path = os.path.join(opts.work_path, "build")
        rimraf(build_path)
        mkdirp(build_path)
        try:
            # Copy source.
            with mark_task(opts, "Copying source"):
                shell(
                    opts,
                    "cd {root_path} && git archive HEAD --format=tar | tar -x -C {build_path}",
                    root_path=opts.root_path,
                    build_path=build_path,
                )
            # Download deps.
            download_conda_deps(opts)
            download_pip_deps(opts, config)
            # Copy libs.
            with mark_task(opts, "Copying libs"):
                shutil.copytree(
                    opts.lib_path,
                    os.path.join(build_path, os.path.relpath(opts.lib_path, opts.root_path)),
                )
            # Compress the build.
            dist_path = os.path.join(opts.root_path, opts.dist_dir)
            mkdirp(dist_path)
            dist_file = os.path.join("{name}-{version}-{os_name}-amd64.zip".format(
                name=config.get("name", os.path.basename(opts.root_path)),
                version=config.get("version", "1.0.0"),
                os_name=opts.os_name,
            ))
            with mark_task(opts, "Creating archive {}".format(dist_file)):
                dist_file_path = os.path.join(dist_path, dist_file)
                rimraf(dist_file_path)
                shell(
                    opts,
                    "cd {build_path} && zip -9 -qq -r {dist_file_path} './'",
                    build_path=build_path,
                    dist_file_path=dist_file_path,
                )
        finally:
            rimraf(build_path)
    finally:
        delete_conda_env(opts)
Exemplo n.º 3
0
Arquivo: pip.py Projeto: etianen/py.sh
def install_pip_deps(opts, config):
    deps = get_pip_deps(opts, config)
    if deps:
        with mark_task(opts, "Installing {} pip dependencies".format(opts.conda_env)):
            shell_local(
                opts,
                "pip install {args} {{deps}}".format(args=get_pip_args(opts, config)),
                deps=deps,
            )
Exemplo n.º 4
0
Arquivo: pip.py Projeto: etianen/py.sh
def install_pip_deps_offline(opts, config):
    deps = glob.glob(os.path.join(opts.pip_lib_path, "*.*"))
    if deps:
        with mark_task(opts, "Installing {} pip dependencies".format(opts.conda_env)):
            shell_local(
                opts,
                "pip install --no-index --no-deps {deps}",
                deps=deps,
            )
Exemplo n.º 5
0
def install_pip_deps_offline(opts, config):
    deps = glob.glob(os.path.join(opts.pip_lib_path, "*.*"))
    if deps:
        with mark_task(opts, "Installing {} pip dependencies".format(opts.conda_env)):
            shell_local(
                opts,
                "pip install {deps}",
                deps=deps,
            )
Exemplo n.º 6
0
def install_pip_deps(opts, config):
    deps = get_pip_deps(opts, config)
    if deps:
        with mark_task(opts, "Installing {} pip dependencies".format(opts.conda_env)):
            shell_local(
                opts,
                "pip install {args} {{deps}}".format(args=get_pip_args(opts, config)),
                deps=deps,
            )
Exemplo n.º 7
0
def reset_conda_env_offline(opts, config):
    delete_conda_env(opts)
    # Create a new env.
    with mark_task(opts, "Installing {} conda dependencies".format(opts.conda_env)):
        deps = glob.glob(os.path.join(opts.conda_lib_path, "*.tar.bz2"))
        shell(
            opts,
            "conda create --offline --yes --name {conda_env} {deps}",
            conda_env=opts.conda_env,
            deps=deps,
        )
Exemplo n.º 8
0
def activate(opts):
    config = load_config(opts)
    package_name = config.get("name", os.path.basename(opts.root_path))
    with mark_task(opts, "Activating {} environment".format(opts.conda_env)):
        shell_local_exec(
            opts,
            apply_styles(opts, """printf "{success}done!{plain}
Deactivate environment with {code}exit{plain} or {code}[Ctl+D]{plain}.
" && export PS1="(\[{code}\]{{package_name}}\[{plain}\]) \\h:\\W \\u\\$ " && bash"""),
            package_name=package_name,
        )
Exemplo n.º 9
0
def download_pip_deps(opts, config):
    rimraf(opts.pip_lib_path)
    mkdirp(opts.pip_lib_path)
    deps = get_pip_deps(opts, config)
    if deps:
        with mark_task(opts, "Downloading pip dependencies"):
            shell_local(
                opts,
                "pip download {args} --dest {{dest_path}} {{deps}}".format(args=get_pip_args(opts, config)),
                dest_path=opts.pip_lib_path,
                deps=deps,
            )
Exemplo n.º 10
0
def reset_conda_env_offline(opts, config):
    delete_conda_env(opts)
    # Create a new env.
    with mark_task(opts,
                   "Installing {} conda dependencies".format(opts.conda_env)):
        deps = glob.glob(os.path.join(opts.conda_lib_path, "*.tar.bz2"))
        shell(
            opts,
            "conda create --offline --yes --name {conda_env} {deps}",
            conda_env=opts.conda_env,
            deps=deps,
        )
Exemplo n.º 11
0
Arquivo: pip.py Projeto: etianen/py.sh
def download_pip_deps(opts, config):
    rimraf(opts.pip_lib_path)
    mkdirp(opts.pip_lib_path)
    deps = get_pip_deps(opts, config)
    if deps:
        with mark_task(opts, "Downloading pip dependencies"):
            shell_local(
                opts,
                "pip download {args} --dest {{dest_path}} {{deps}}".format(args=get_pip_args(opts, config)),
                dest_path=opts.pip_lib_path,
                deps=deps,
            )
Exemplo n.º 12
0
def activate(opts):
    config = load_config(opts)
    package_name = config.get("name", os.path.basename(opts.root_path))
    with mark_task(opts, "Activating {} environment".format(opts.conda_env)):
        shell_local_exec(
            opts,
            apply_styles(
                opts, """printf "{success}done!{plain}
Deactivate environment with {code}exit{plain} or {code}[Ctl+D]{plain}.
" && export PS1="(\[{code}\]{{package_name}}\[{plain}\]) \\h:\\W \\u\\$ " && bash"""
            ),
            package_name=package_name,
        )
Exemplo n.º 13
0
def load_config(opts):
    with mark_task(opts, "Loading config from {}".format(opts.config_file)):
        package_json_path = os.path.join(opts.root_path, opts.config_file)
        if os.path.exists(package_json_path):
            with open(package_json_path, "rb") as package_json_handle:
                try:
                    return Config(json.loads(package_json_handle.read().decode("utf-8")), [])
                except ValueError:
                    raise TaskError("Invalid {} config file.".format(opts.config_file))
        else:
            raise TaskWarning("Missing {} config file.".format(opts.config_file))
    # Provide a fallback config.
    return Config({}, [])
Exemplo n.º 14
0
def install(opts):
    config = load_config(opts)
    if opts.offline:
        reset_conda_env_offline(opts, config)
        install_pip_deps_offline(opts, config)
    else:
        reset_conda_env(opts, config)
        install_pip_deps(opts, config)
    # Run install scripts.
    install_scripts = config.get("pysh").get("install", [])
    if install_scripts:
        with mark_task(opts, "Running install scripts"):
            for install_script in install_scripts:
                shell_local(opts, install_script)
Exemplo n.º 15
0
def install(opts):
    config = load_config(opts)
    if opts.offline:
        reset_conda_env_offline(opts, config)
        install_pip_deps_offline(opts, config)
    else:
        reset_conda_env(opts, config)
        install_pip_deps(opts, config)
    # Run install scripts.
    install_scripts = config.get("pysh").get("install", [])
    if install_scripts:
        with mark_task(opts, "Running install scripts"):
            for install_script in install_scripts:
                shell_local(opts, install_script)
Exemplo n.º 16
0
def download_conda_deps(opts):
    rimraf(opts.conda_lib_path)
    mkdirp(opts.conda_lib_path)
    deps = [
        dep for dep in shell_local(
            opts, "conda list --explicit").decode().splitlines()
        if not dep.startswith("#") and not dep.startswith("@")
    ]
    if deps:
        with mark_task(opts, "Downloading conda dependencies"):
            for dep in deps:
                download(
                    dep,
                    os.path.join(opts.conda_lib_path, posixpath.basename(dep)),
                )
Exemplo n.º 17
0
def download_conda_deps(opts):
    rimraf(opts.conda_lib_path)
    mkdirp(opts.conda_lib_path)
    deps = [
        dep
        for dep
        in shell_local(opts, "conda list --explicit").decode().splitlines()
        if not dep.startswith("#") and not dep.startswith("@")
    ]
    if deps:
        with mark_task(opts, "Downloading conda dependencies"):
            for dep in deps:
                download(
                    dep,
                    os.path.join(opts.conda_lib_path, posixpath.basename(dep)),
                )
Exemplo n.º 18
0
def reset_conda_env(opts, config):
    delete_conda_env(opts)
    # Create a new env.
    with mark_task(opts,
                   "Installing {} conda dependencies".format(opts.conda_env)):
        python_version = config.get("pysh").get("python").get("version", "3")
        deps = [
            "{}={}".format(*dep) for dep in get_deps(opts, config, "conda")
        ]
        shell(
            opts,
            "conda create --yes --name {conda_env} python={python_version} {deps}",
            conda_env=opts.conda_env,
            python_version=python_version,
            deps=deps,
        )
Exemplo n.º 19
0
def reset_conda_env(opts, config):
    delete_conda_env(opts)
    # Create a new env.
    with mark_task(opts, "Installing {} conda dependencies".format(opts.conda_env)):
        python_version = config.get("pysh").get("python").get("version", "3")
        deps = [
            "{}={}".format(*dep)
            for dep
            in get_deps(opts, config, "conda")
        ]
        shell(
            opts,
            "conda create --yes --name {conda_env} python={python_version} {deps}",
            conda_env=opts.conda_env,
            python_version=python_version,
            deps=deps,
        )
Exemplo n.º 20
0
def load_config(opts):
    with mark_task(opts, "Loading config from {}".format(opts.config_file)):
        package_json_path = os.path.join(opts.root_path, opts.config_file)
        if os.path.exists(package_json_path):
            with open(package_json_path, "rb") as package_json_handle:
                try:
                    return Config(
                        json.loads(package_json_handle.read().decode("utf-8")),
                        [])
                except ValueError:
                    raise TaskError("Invalid {} config file.".format(
                        opts.config_file))
        else:
            raise TaskWarning("Missing {} config file.".format(
                opts.config_file))
    # Provide a fallback config.
    return Config({}, [])
Exemplo n.º 21
0
def delete_conda_env(opts):
    with mark_task(opts, "Cleaning {} environment".format(opts.conda_env)):
        shell(opts,
              "conda env remove --yes --name {conda_env}",
              conda_env=opts.conda_env)
Exemplo n.º 22
0
def delete_conda_env(opts):
    with mark_task(opts, "Cleaning {} environment".format(opts.conda_env)):
        shell(opts, "conda env remove --yes --name {conda_env}", conda_env=opts.conda_env)