Skip to content
Snippets Groups Projects
Commit 5729e750 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[constants] Formalize and add support for centralized constants used for various operations

parent e3e7ac3d
No related branches found
No related tags found
No related merge requests found
include LICENSE README.rst buildout.cfg version.txt
recursive-include doc conf.py *.rst
recursive-include bob/devtools/data *.md *.yaml build-condarc
recursive-include bob/devtools/data *.md *.yaml *condarc *.pem matplotlibrc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Constants used for building and more'''
import os
import pkg_resources
import logging
logger = logging.getLogger(__name__)
CONDARC = pkg_resources.resource_filename(__name__,
os.path.join('data', 'build-condarc'))
'''The .condarc to use for building and creating new environments'''
CONDA_BUILD_CONFIG = pkg_resources.resource_filename(__name__,
os.path.join('data', 'conda_build_config.yaml'))
'''Configuration variants we like building'''
CONDA_RECIPE_APPEND = pkg_resources.resource_filename(__name__,
os.path.join('data', 'recipe_append.yaml'))
'''Extra information to be appended to every recipe upon building'''
SERVER = 'http://www.idiap.ch'
'''This is the default server use use to store data and build artifacts'''
CACERT = pkg_resources.resource_filename(__name__,
os.path.join('data', 'cacert.pem'))
'''We keep a copy of the CA certificates we trust here
To update this file use: ``curl --remote-name --time-cond cacert.pem https://curl.haxx.se/ca/cacert.pem``
More information here: https://curl.haxx.se/docs/caextract.html
'''
MATPLOTLIB_RCDIR = pkg_resources.resource_filename(__name__, 'data')
'''Base directory where the file matplotlibrc lives
It is required for certain builds that use matplotlib functionality.
'''
def set_environment(name, value, env=os.environ):
'''Function to setup the environment variable and print debug message
Args:
name: The name of the environment variable to set
value: The value to set the environment variable to
env: Optional environment (dictionary) where to set the variable at
'''
if name in env:
logger.warn('Overriding existing environment variable ${%s} (was: "%s")',
name, env[name])
env[name] = value
logger.debug('$ export %s="%s"', name, value)
Source diff could not be displayed: it is too large. Options to address this: view the blob.
backend : agg
......@@ -4,6 +4,7 @@
"""Main entry point for bdt
"""
import os
import pkg_resources
import click
......@@ -52,3 +53,8 @@ def raise_on_error(view_func):
context_settings=dict(help_option_names=['-?', '-h', '--help']))
def main():
"""Bob Development Tools - see available commands below"""
#sets up basic environment variables required everywhere
from ..constants import CACERT, set_environment
set_environment('SSL_CERT_FILE', CACERT, os.environ)
......@@ -13,15 +13,8 @@ import yaml
from . import bdt
from ..log import verbosity_option
from ..bootstrap import parse_dependencies, conda_create, make_conda_config
DEFAULT_CONDARC = pkg_resources.resource_filename(__name__,
os.path.join('..', 'data', 'build-condarc'))
DEFAULT_VARIANT = pkg_resources.resource_filename(__name__,
os.path.join('..', 'data', 'conda_build_config.yaml'))
DEFAULT_APPEND = pkg_resources.resource_filename(__name__,
os.path.join('..', 'data', 'recipe_append.yaml'))
DEFAULT_DOCSERVER = 'http://www.idiap.ch'
from ..constants import CONDARC, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \
SERVER
@click.command(epilog='''
......@@ -68,16 +61,16 @@ Examples:
help='If set and an environment with the same name exists, ' \
'deletes it first before creating the new environment',
show_default=True)
@click.option('-r', '--condarc', default=DEFAULT_CONDARC, show_default=True,
@click.option('-r', '--condarc', default=CONDARC, show_default=True,
help='overwrites the path leading to the condarc file to use',)
@click.option('-m', '--config', '--variant-config-files', show_default=True,
default=DEFAULT_VARIANT, help='overwrites the path leading to ' \
default=CONDA_BUILD_CONFIG, help='overwrites the path leading to ' \
'variant configuration file to use')
@click.option('-a', '--append-file', show_default=True,
default=DEFAULT_APPEND, help='overwrites the path leading to ' \
default=CONDA_RECIPE_APPEND, help='overwrites the path leading to ' \
'appended configuration file to use')
@click.option('-D', '--docserver', show_default=True,
default=DEFAULT_DOCSERVER, help='Server used for uploading artifacts ' \
default=SERVER, help='Server used for uploading artifacts ' \
'and other goodies')
@click.option('-d', '--dry-run/--no-dry-run', default=False,
help='Only goes through the actions, but does not execute them ' \
......@@ -116,12 +109,11 @@ def bootstrap(name, recipe_dir, python, overwrite, condarc, config,
"have you activated the build environment containing bob.devtools " \
"properly?")
# set condarc before continuing
logger.debug("[var] CONDARC=%s", condarc)
os.environ['CONDARC'] = condarc
logger.debug("[var] DOCSERVER=%s", docserver)
os.environ['DOCSERVER'] = docserver
# set some environment variables before continuing
set_environment('CONDARC', condarc, os.environ)
set_environment('SERVER', docserver, os.environ)
set_environment('LANG', 'en_US.UTF-8', os.environ)
set_environment('LC_ALL', os.environ['LANG'], os.environ)
conda_config = make_conda_config(config, python, append_file, condarc)
deps = parse_dependencies(recipe_dir, conda_config)
......
......@@ -13,10 +13,8 @@ from . import bdt
from ..log import verbosity_option
from ..conda import next_build_number, osname
from ..bootstrap import get_rendered_metadata, get_parsed_recipe
from .bootstrap import DEFAULT_CONDARC, DEFAULT_VARIANT, DEFAULT_APPEND, \
DEFAULT_DOCSERVER
from ..constants import CONDARC, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \
SERVER, MATPLOTLIB_RCDIR, set_environment
@click.command(epilog='''
......@@ -43,10 +41,10 @@ Examples:
@click.option('-p', '--python', default=('%d.%d' % sys.version_info[:2]),
show_default=True, help='Version of python to build the ' \
'environment for [default: %(default)s]')
@click.option('-r', '--condarc', default=DEFAULT_CONDARC, show_default=True,
@click.option('-r', '--condarc', default=CONDARC, show_default=True,
help='overwrites the path leading to the condarc file to use',)
@click.option('-m', '--config', '--variant-config-files', show_default=True,
default=DEFAULT_VARIANT, help='overwrites the path leading to ' \
default=CONDA_BUILD_CONFIG, help='overwrites the path leading to ' \
'variant configuration file to use')
@click.option('-c', '--channel', show_default=True,
default='https://www.idiap.ch/software/bob/conda/label/beta',
......@@ -55,10 +53,10 @@ Examples:
@click.option('-n', '--no-test', is_flag=True,
help='Do not test the package, only builds it')
@click.option('-a', '--append-file', show_default=True,
default=DEFAULT_APPEND, help='overwrites the path leading to ' \
default=CONDA_RECIPE_APPEND, help='overwrites the path leading to ' \
'appended configuration file to use')
@click.option('-D', '--docserver', show_default=True,
default=DEFAULT_DOCSERVER, help='Server used for uploading artifacts ' \
default=SERVER, help='Server used for uploading artifacts ' \
'and other goodies')
@click.option('-d', '--dry-run/--no-dry-run', default=False,
help='Only goes through the actions, but does not execute them ' \
......@@ -85,13 +83,15 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file,
recipe_dir = recipe_dir or [os.path.join(os.path.realpath('.'), 'conda')]
logger.debug("[var] CONDARC=%s", condarc)
logger.debug("CONDARC=%s", condarc)
from ..bootstrap import make_conda_config
conda_config = make_conda_config(config, python, append_file, condarc)
logger.debug("[var] DOCSERVER=%s", docserver)
os.environ['DOCSERVER'] = docserver
set_environment('LANG', 'en_US.UTF-8', os.environ)
set_environment('LC_ALL', os.environ['LANG'], os.environ)
set_environment('DOCSERVER', docserver, os.environ)
set_environment('MATPLOTLIBRC', MATPLOTLIB_RCDIR, os.environ)
for d in recipe_dir:
......@@ -101,8 +101,7 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file,
version_candidate = os.path.join(d, '..', 'version.txt')
if os.path.exists(version_candidate):
version = open(version_candidate).read().rstrip()
logger.debug("[var] BOB_PACKAGE_VERSION=%s", version)
os.environ['BOB_PACKAGE_VERSION'] = version
set_environment('BOB_PACKAGE_VERSION', version, os.environ)
# pre-renders the recipe - figures out package name and version
metadata = get_rendered_metadata(d, conda_config)
......@@ -125,8 +124,7 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file,
else:
build_number = 0
logger.debug("[var] BOB_BUILD_NUMBER=%s", build_number)
os.environ['BOB_BUILD_NUMBER'] = str(build_number)
set_environment('BOB_BUILD_NUMBER', build_number, os.environ)
# we don't execute the following command, it is just here for logging
# purposes. we directly use the conda_build API.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment