Skip to content

Commit

Permalink
Add custom platform option to conda vendor. Black some files, add tes…
Browse files Browse the repository at this point in the history
…ts. (#20)

* Add custom platform option to conda vendor. Black some files, add tests.

* Streamline CLI, make platform a single choice instead of name and bits
  • Loading branch information
tylerpotts committed Sep 22, 2021
1 parent 1a73df6 commit aafe65f
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 83 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -23,7 +23,7 @@ The intermediate meta-manifest is generated to allow for the creation of custom

Conda-vendor solves an environment with conda from an `environment.yaml` and determines all the packages that are required. The metadata for these required packages is stored in a file called `meta_manifest.yaml`. To create this file, run:

conda vendor create-meta-manifes
conda vendor meta-manifest
t --environment-yaml environment.yaml
The above command will output a `meta_manifest.yaml` file in the current directory.
Expand All @@ -32,9 +32,9 @@ The above command will output a `meta_manifest.yaml` file in the current directo

With a meta-manifest file created, conda-vendor can then create local channels.

conda vendor create-channels --meta-manifest-path ./meta_manifest.yaml
conda vendor channels --meta-manifest-path ./meta_manifest.yaml

This will create a directory called `local_channel` that will contain the same number of channels as were listed in the original `environment.yaml` file. These local channels will only contain the packages that are needed to satisfy the solved environment from the `create-meta-manifest` step.
This will create a directory called `local_channel` that will contain the same number of channels as were listed in the original `environment.yaml` file. These local channels will only contain the packages that are needed to satisfy the solved environment from the `meta-manifest` step.

### Using the Local channel

Expand All @@ -53,7 +53,7 @@ This should show a list of all the packages in the environment the local paths t

To generate a conda environment yaml that contains all the packages from the input `environment.yaml`, run the following:

conda vendor create-local-yaml --meta-manifest-path ./meta_manifest.yaml --channel-root <absolute_path_to_local_channel_dir>
conda vendor local-yaml --meta-manifest-path ./meta_manifest.yaml --channel-root <absolute_path_to_local_channel_dir>

This will create a environment file inside the `local_channel` directory called `local_conda-vendor-env.yaml`. An environment can then be created with:

Expand All @@ -67,6 +67,6 @@ The following functionality is only applicable if there is an organization that

To generate an iron bank manifest from the meta-manifest, run:

conda vendor create-custom-manifest --meta-manifest-path ./meta-manifest.yaml --output-manifest-path ./custom_manifest.yaml
conda vendor custom-manifest --meta-manifest-path ./meta-manifest.yaml --output-manifest-path ./custom_manifest.yaml

This will output a manifest file in the Iron Bank format.
52 changes: 31 additions & 21 deletions conda_vendor/__main__.py
Expand Up @@ -2,10 +2,10 @@

import click
from conda_vendor.cli import (
create_ironbank_from_meta_manifest,
create_local_channels_from_meta_manifest,
create_meta_manifest_from_env_yml,
create_yaml_from_manifest,
ironbank_from_meta_manifest,
local_channels_from_meta_manifest,
meta_manifest_from_env_yml,
yaml_from_manifest,
)
from conda_vendor.version import __version__

Expand Down Expand Up @@ -47,15 +47,24 @@ def cli():
default="meta_manifest.yaml",
help="filename of output manifest",
)
def create_meta_manifest(verbose, environment_yaml, manifest_root, manifest_filename):
@click.option(
"--custom-platform",
"-c",
default=None,
type=click.Choice(["linux-64", "linux-32", "windows-64", "windows-32", "osx-64"]),
help="Specify an alternate platform to use for the conda solve.",
)
def meta_manifest(
verbose, environment_yaml, manifest_root, manifest_filename, custom_platform,
):
set_logging_verbosity(verbose)
click.echo(manifest_root)
click.echo(manifest_filename)
environment_yaml = Path(environment_yaml)
manifest_root = Path(manifest_root)

create_meta_manifest_from_env_yml(
environment_yaml, manifest_root, manifest_filename
meta_manifest_from_env_yml(
environment_yaml, manifest_root, manifest_filename, custom_platform,
)


Expand All @@ -73,11 +82,11 @@ def create_meta_manifest(verbose, environment_yaml, manifest_root, manifest_file
default="./meta_manifest.yaml",
help="path to meta manifest file",
)
def create_channels(verbose, channel_root, meta_manifest_path):
def channels(verbose, channel_root, meta_manifest_path):
set_logging_verbosity(verbose)
channel_root = Path(channel_root)
meta_manifest_path = Path(meta_manifest_path)
create_local_channels_from_meta_manifest(channel_root, meta_manifest_path)
local_channels_from_meta_manifest(channel_root, meta_manifest_path)


@click.command(help="custom manifest from meta-manifest file")
Expand All @@ -87,21 +96,20 @@ def create_channels(verbose, channel_root, meta_manifest_path):
)
@click.option(
"--meta-manifest-path",
"-m",
default="./meta_manifest.yaml",
help="path to meta manifest file",
)
@click.option(
"--output-manifest-path", default="./", help="output manifest path",
"--output-manifest-path", "-o", default="./", help="output manifest path",
)
def create_custom_manifest(
verbose, manifest_type, meta_manifest_path, output_manifest_path
):
def custom_manifest(verbose, manifest_type, meta_manifest_path, output_manifest_path):
set_logging_verbosity(verbose)
meta_manifest_path = Path(meta_manifest_path)
output_manifest_path = Path(output_manifest_path)

if manifest_type == "iron-bank":
create_ironbank_from_meta_manifest(
ironbank_from_meta_manifest(
meta_manifest_path=meta_manifest_path,
output_manifest_dir=output_manifest_path,
)
Expand All @@ -122,25 +130,27 @@ def create_custom_manifest(
)
@click.option(
"--meta-manifest-path",
"-m",
default="./meta_manifest.yaml",
help="path to meta manifest file",
)
@click.option(
"--env-name",
"-n",
default="conda-vendor-env",
help="name of conda environment defined in yaml",
help="name of conda environment to be defined in yaml",
)
def create_local_yaml(verbose, channel_root, meta_manifest_path, env_name):
def local_yaml(verbose, channel_root, meta_manifest_path, env_name):
set_logging_verbosity(verbose)
channel_root = Path(channel_root)
meta_manifest_path = Path(meta_manifest_path)
create_yaml_from_manifest(channel_root, meta_manifest_path, env_name)
yaml_from_manifest(channel_root, meta_manifest_path, env_name)


cli.add_command(create_meta_manifest)
cli.add_command(create_channels)
cli.add_command(create_custom_manifest)
cli.add_command(create_local_yaml)
cli.add_command(meta_manifest)
cli.add_command(channels)
cli.add_command(custom_manifest)
cli.add_command(local_yaml)


if __name__ == "__main__":
Expand Down
14 changes: 8 additions & 6 deletions conda_vendor/cli.py
Expand Up @@ -6,26 +6,28 @@
from conda_vendor.manifest import MetaManifest


def create_meta_manifest_from_env_yml(
environment_yaml, manifest_root, manifest_filename
def meta_manifest_from_env_yml(
environment_yaml, manifest_root, manifest_filename, custom_platform=None,
):
conda_channel = MetaManifest(environment_yaml, manifest_root=manifest_root)
conda_channel = MetaManifest(
environment_yaml, manifest_root=manifest_root, custom_platform=custom_platform,
)
conda_channel.create_manifest(manifest_filename=manifest_filename)


def create_local_channels_from_meta_manifest(channel_root, meta_manifest_path):
def local_channels_from_meta_manifest(channel_root, meta_manifest_path):
conda_channel = CondaChannel(
channel_root=channel_root, meta_manifest_path=meta_manifest_path
)
conda_channel.write_repo_data()
conda_channel.download_binaries()


def create_ironbank_from_meta_manifest(meta_manifest_path, output_manifest_dir):
def ironbank_from_meta_manifest(meta_manifest_path, output_manifest_dir):
custom_manifest = IBManifest(meta_manifest_path)
custom_manifest.write_custom_manifest(output_manifest_dir)


def create_yaml_from_manifest(channel_root, meta_manifest_path, env_name):
def yaml_from_manifest(channel_root, meta_manifest_path, env_name):
george_forge = YamlFromManifest(channel_root, meta_manifest_path=meta_manifest_path)
george_forge.create_yaml(channel_root, env_name)
14 changes: 11 additions & 3 deletions conda_vendor/manifest.py
Expand Up @@ -28,7 +28,13 @@ def solve(*args, **kwargs):


# see https://github.com/conda/conda/blob/248741a843e8ce9283fa94e6e4ec9c2fafeb76fd/conda/base/context.py#L51
def get_conda_platform(platform=sys.platform):
def get_conda_platform(
platform=sys.platform, custom_platform=None,
):

if custom_platform is not None:
return custom_platform

_platform_map = {
"linux2": "linux",
"linux": "linux",
Expand All @@ -42,10 +48,12 @@ def get_conda_platform(platform=sys.platform):


class MetaManifest:
def __init__(self, environment_yml, *, manifest_root=Path()):
def __init__(
self, environment_yml, *, manifest_root=Path(), custom_platform=None,
):
self.manifest_root = Path(manifest_root)
logger.info(f"manifest_root : {self.manifest_root.absolute()}")
self.platform = get_conda_platform()
self.platform = get_conda_platform(custom_platform=custom_platform)

self.valid_platforms = [self.platform, "noarch"]

Expand Down
2 changes: 1 addition & 1 deletion conda_vendor/version.py
@@ -1,4 +1,4 @@
__version__ = "0.1.8"
__version__ = "0.1.9"

if __name__ == "__main__":
print(__version__, end="")
10 changes: 5 additions & 5 deletions docs/source/user_guide.md
Expand Up @@ -17,17 +17,17 @@ The intermediate meta-manifest is generated to allow for the creation of custom

Conda-vendor solves an environment with conda from an `environment.yaml` and determines all the packages that are required. The metadata for these required packages is stored in a file called `meta_manifest.yaml`. To create this file, run:

conda vendor create-meta-manifest --environment-yaml environment.yaml
conda vendor meta-manifest --environment-yaml environment.yaml
The above command will output a `meta_manifest.yaml` file in the current directory.

### Creating a Local Channel

With a meta-manifest file created, conda-vendor can then create local channels.

conda vendor create-channels --meta-manifest-path ./meta_manifest.yaml
conda vendor channels --meta-manifest-path ./meta_manifest.yaml

This will create a directory called `local_channel` that will contain the same number of channels as were listed in the original `environment.yaml` file. These local channels will only contain the packages that are needed to satisfy the solved environment from the `create-meta-manifest` step.
This will create a directory called `local_channel` that will contain the same number of channels as were listed in the original `environment.yaml` file. These local channels will only contain the packages that are needed to satisfy the solved environment from the `meta-manifest` step.

### Using the Local channel

Expand All @@ -46,7 +46,7 @@ This should show a list of all the packages in the environment the local paths t

To generate a conda environment yaml that contains all the packages from the input `environment.yaml`, run the following:

conda vendor create-local-yaml --meta-manifest-path ./meta_manifest.yaml --channel-root <absolute_path_to_local_channel_dir>
conda vendor local-yaml --meta-manifest-path ./meta_manifest.yaml --channel-root <absolute_path_to_local_channel_dir>

This will create a environment file inside the `local_channel` directory called `local_conda-vendor-env.yaml`. An environment can then be created with:

Expand All @@ -60,6 +60,6 @@ The following functionality is only applicable if there is an organization that

To generate an iron bank manifest from the meta-manifest, run:

conda vendor create-custom-manifest --meta-manifest-path ./meta-manifest.yaml --output-manifest-path ./custom_manifest.yaml
conda vendor custom-manifest --meta-manifest-path ./meta-manifest.yaml --output-manifest-path ./custom_manifest.yaml

This will output a manifest file in the Iron Bank format.
11 changes: 2 additions & 9 deletions tests/test_conda_channel.py
Expand Up @@ -70,11 +70,7 @@ def test_CondaChannel_fetch_and_filter_repodata(mock_download, conda_channel_fix

fake_manifest_subset_metadata = {
"repodata_url": "https://url1",
"entries": [
{"fn": "file1"},
{"fn": "file2"},
{"fn": "file3"},
],
"entries": [{"fn": "file1"}, {"fn": "file2"}, {"fn": "file3"},],
}
fake_live_repo_data_json = {
"info": {"subdir": "fake_subdir"},
Expand All @@ -97,10 +93,7 @@ def test_CondaChannel_fetch_and_filter_repodata(mock_download, conda_channel_fix

expected = {
"info": {"subdir": "fake_subdir"},
"packages": {
"file1": {"id": 1},
"file2": {"id": 3},
},
"packages": {"file1": {"id": 1}, "file2": {"id": 3},},
"packages.conda": {"file3": {"id": 5}},
}
expected_mock_call = call("https://url1")
Expand Down

0 comments on commit aafe65f

Please sign in to comment.