test.py 5.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

import yaml
import click
import pkg_resources
import conda_build.api

from . import bdt
André Anjos's avatar
André Anjos committed
13
14
15
16
17
from ..build import (
    conda_arch,
    make_conda_config,
    get_docserver_setup,
    get_env_directory,
18
    remove_conda_loggers,
André Anjos's avatar
André Anjos committed
19
)
20
21
remove_conda_loggers()

André Anjos's avatar
André Anjos committed
22
23
24
25
26
27
28
from ..constants import (
    CONDA_BUILD_CONFIG,
    CONDA_RECIPE_APPEND,
    SERVER,
    MATPLOTLIB_RCDIR,
    BASE_CONDARC,
)
29
30
31
from ..bootstrap import set_environment, get_channels

from ..log import verbosity_option, get_logger
André Anjos's avatar
André Anjos committed
32

33
34
35
logger = get_logger(__name__)


André Anjos's avatar
André Anjos committed
36
37
@click.command(
    epilog="""
38
39
Examples:

40
  1. Tests conda package:
41
42

\b
43
     $ bdt test -vv /path/to/conda-package-v1.0.0.conda
44
45


46
  2. Tests multiple conda packages, one after the other:
47

48
\b
49
     $ bdt test -vv /path/to/conda-package-v1.0.0.conda /path/to/other-conda-package-v2.0.0.conda
50

André Anjos's avatar
André Anjos committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""
)
@click.argument(
    "package",
    required=True,
    type=click.Path(file_okay=True, dir_okay=False, exists=True),
    nargs=-1,
)
@click.option(
    "-r",
    "--condarc",
    help="Use custom conda configuration file instead of our own",
)
@click.option(
    "-m",
    "--config",
    "--variant-config-files",
    show_default=True,
    default=CONDA_BUILD_CONFIG,
    help="overwrites the path leading to " "variant configuration file to use",
)
@click.option(
    "-a",
    "--append-file",
    show_default=True,
    default=CONDA_RECIPE_APPEND,
    help="overwrites the path leading to " "appended configuration file to use",
)
@click.option(
    "-S",
    "--server",
    show_default=True,
    default=SERVER,
    help="Server used for downloading conda packages and documentation "
    "indexes of required packages",
)
@click.option(
    "-g",
    "--group",
    show_default=True,
    default="bob",
    help="Group of packages (gitlab namespace) this package belongs to",
)
@click.option(
    "-P",
    "--private/--no-private",
    default=False,
    help="Set this to **include** private channels on your build - "
    "you **must** be at Idiap to execute this build in this case - "
    "you **must** also use the correct server name through --server - "
    "notice this option has no effect to conda if you also pass --condarc",
)
@click.option(
    "-X",
    "--stable/--no-stable",
    default=False,
    help="Set this to **exclude** beta channels from your build - "
    "notice this option has no effect if you also pass --condarc",
)
@click.option(
    "-d",
    "--dry-run/--no-dry-run",
    default=False,
    help="Only goes through the actions, but does not execute them "
    "(combine with the verbosity flags - e.g. ``-vvv``) to enable "
    "printing to help you understand what will be done",
)
@click.option(
    "-C",
    "--ci/--no-ci",
    default=False,
    hidden=True,
    help="Use this flag to indicate the build will be running on the CI",
)
125
126
@verbosity_option()
@bdt.raise_on_error
André Anjos's avatar
André Anjos committed
127
128
129
130
131
132
133
134
135
136
137
138
def test(
    package,
    condarc,
    config,
    append_file,
    server,
    group,
    private,
    stable,
    dry_run,
    ci,
):
139
    """Tests (pre-built) package through conda-build with stock configuration.
140

141
142
143
144
    This command wraps the execution of conda-build so that you use the
    same conda configuration we use for our CI.  It always set ``--no-
    anaconda-upload``.
    """
145

André Anjos's avatar
André Anjos committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
    # if we are in a dry-run mode, let's let it be known
    if dry_run:
        logger.warn("!!!! DRY RUN MODE !!!!")
        logger.warn("Nothing will be really built")

    logger.debug(
        'This package is considered part of group "%s" - tunning '
        "conda package and documentation URLs for this...",
        group,
    )

    # get potential channel upload and other auxiliary channels
    channels = get_channels(
        public=(not private),
        stable=stable,
        server=server,
        intranet=ci,
        group=group,
    )

    if condarc is not None:
        logger.info("Loading CONDARC file from %s...", condarc)
        with open(condarc, "rb") as f:
            condarc_options = yaml.load(f, Loader=yaml.FullLoader)
    else:
        # use default and add channels
        all_channels = []
        all_channels += channels + ["defaults"]
        condarc_options = yaml.load(BASE_CONDARC, Loader=yaml.FullLoader)
        logger.info(
            "Using the following channels during build:\n  - %s",
            "\n  - ".join(all_channels),
        )
        condarc_options["channels"] = all_channels

    conda_config = make_conda_config(config, None, append_file, condarc_options)

    set_environment("MATPLOTLIBRC", MATPLOTLIB_RCDIR)

    # setup BOB_DOCUMENTATION_SERVER environment variable (used for bob.extension
    # and derived documentation building via Sphinx)
    set_environment("DOCSERVER", server)
    doc_urls = get_docserver_setup(
        public=(not private),
        stable=stable,
        server=server,
        intranet=ci,
        group=group,
    )
    set_environment("BOB_DOCUMENTATION_SERVER", doc_urls)

    arch = conda_arch()
    for p in package:
        logger.info("Testing %s at %s", p, arch)
        if not dry_run:
            conda_build.api.test(p, config=conda_config)