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 include LICENSE README.rst buildout.cfg version.txt
recursive-include doc conf.py *.rst 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 @@ ...@@ -4,6 +4,7 @@
"""Main entry point for bdt """Main entry point for bdt
""" """
import os
import pkg_resources import pkg_resources
import click import click
...@@ -52,3 +53,8 @@ def raise_on_error(view_func): ...@@ -52,3 +53,8 @@ def raise_on_error(view_func):
context_settings=dict(help_option_names=['-?', '-h', '--help'])) context_settings=dict(help_option_names=['-?', '-h', '--help']))
def main(): def main():
"""Bob Development Tools - see available commands below""" """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 ...@@ -13,15 +13,8 @@ import yaml
from . import bdt from . import bdt
from ..log import verbosity_option from ..log import verbosity_option
from ..bootstrap import parse_dependencies, conda_create, make_conda_config from ..bootstrap import parse_dependencies, conda_create, make_conda_config
from ..constants import CONDARC, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \
SERVER
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'
@click.command(epilog=''' @click.command(epilog='''
...@@ -68,16 +61,16 @@ Examples: ...@@ -68,16 +61,16 @@ Examples:
help='If set and an environment with the same name exists, ' \ help='If set and an environment with the same name exists, ' \
'deletes it first before creating the new environment', 'deletes it first before creating the new environment',
show_default=True) 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',) help='overwrites the path leading to the condarc file to use',)
@click.option('-m', '--config', '--variant-config-files', show_default=True, @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') 'variant configuration file to use')
@click.option('-a', '--append-file', show_default=True, @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') 'appended configuration file to use')
@click.option('-D', '--docserver', show_default=True, @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') 'and other goodies')
@click.option('-d', '--dry-run/--no-dry-run', default=False, @click.option('-d', '--dry-run/--no-dry-run', default=False,
help='Only goes through the actions, but does not execute them ' \ help='Only goes through the actions, but does not execute them ' \
...@@ -116,12 +109,11 @@ def bootstrap(name, recipe_dir, python, overwrite, condarc, config, ...@@ -116,12 +109,11 @@ def bootstrap(name, recipe_dir, python, overwrite, condarc, config,
"have you activated the build environment containing bob.devtools " \ "have you activated the build environment containing bob.devtools " \
"properly?") "properly?")
# set condarc before continuing # set some environment variables before continuing
logger.debug("[var] CONDARC=%s", condarc) set_environment('CONDARC', condarc, os.environ)
os.environ['CONDARC'] = condarc set_environment('SERVER', docserver, os.environ)
set_environment('LANG', 'en_US.UTF-8', os.environ)
logger.debug("[var] DOCSERVER=%s", docserver) set_environment('LC_ALL', os.environ['LANG'], os.environ)
os.environ['DOCSERVER'] = docserver
conda_config = make_conda_config(config, python, append_file, condarc) conda_config = make_conda_config(config, python, append_file, condarc)
deps = parse_dependencies(recipe_dir, conda_config) deps = parse_dependencies(recipe_dir, conda_config)
......
...@@ -13,10 +13,8 @@ from . import bdt ...@@ -13,10 +13,8 @@ from . import bdt
from ..log import verbosity_option from ..log import verbosity_option
from ..conda import next_build_number, osname from ..conda import next_build_number, osname
from ..bootstrap import get_rendered_metadata, get_parsed_recipe from ..bootstrap import get_rendered_metadata, get_parsed_recipe
from ..constants import CONDARC, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \
SERVER, MATPLOTLIB_RCDIR, set_environment
from .bootstrap import DEFAULT_CONDARC, DEFAULT_VARIANT, DEFAULT_APPEND, \
DEFAULT_DOCSERVER
@click.command(epilog=''' @click.command(epilog='''
...@@ -43,10 +41,10 @@ Examples: ...@@ -43,10 +41,10 @@ Examples:
@click.option('-p', '--python', default=('%d.%d' % sys.version_info[:2]), @click.option('-p', '--python', default=('%d.%d' % sys.version_info[:2]),
show_default=True, help='Version of python to build the ' \ show_default=True, help='Version of python to build the ' \
'environment for [default: %(default)s]') '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',) help='overwrites the path leading to the condarc file to use',)
@click.option('-m', '--config', '--variant-config-files', show_default=True, @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') 'variant configuration file to use')
@click.option('-c', '--channel', show_default=True, @click.option('-c', '--channel', show_default=True,
default='https://www.idiap.ch/software/bob/conda/label/beta', default='https://www.idiap.ch/software/bob/conda/label/beta',
...@@ -55,10 +53,10 @@ Examples: ...@@ -55,10 +53,10 @@ Examples:
@click.option('-n', '--no-test', is_flag=True, @click.option('-n', '--no-test', is_flag=True,
help='Do not test the package, only builds it') help='Do not test the package, only builds it')
@click.option('-a', '--append-file', show_default=True, @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') 'appended configuration file to use')
@click.option('-D', '--docserver', show_default=True, @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') 'and other goodies')
@click.option('-d', '--dry-run/--no-dry-run', default=False, @click.option('-d', '--dry-run/--no-dry-run', default=False,
help='Only goes through the actions, but does not execute them ' \ 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, ...@@ -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')] 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 from ..bootstrap import make_conda_config
conda_config = make_conda_config(config, python, append_file, condarc) conda_config = make_conda_config(config, python, append_file, condarc)
logger.debug("[var] DOCSERVER=%s", docserver) set_environment('LANG', 'en_US.UTF-8', os.environ)
os.environ['DOCSERVER'] = docserver 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: for d in recipe_dir:
...@@ -101,8 +101,7 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file, ...@@ -101,8 +101,7 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file,
version_candidate = os.path.join(d, '..', 'version.txt') version_candidate = os.path.join(d, '..', 'version.txt')
if os.path.exists(version_candidate): if os.path.exists(version_candidate):
version = open(version_candidate).read().rstrip() version = open(version_candidate).read().rstrip()
logger.debug("[var] BOB_PACKAGE_VERSION=%s", version) set_environment('BOB_PACKAGE_VERSION', version, os.environ)
os.environ['BOB_PACKAGE_VERSION'] = version
# pre-renders the recipe - figures out package name and version # pre-renders the recipe - figures out package name and version
metadata = get_rendered_metadata(d, conda_config) metadata = get_rendered_metadata(d, conda_config)
...@@ -125,8 +124,7 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file, ...@@ -125,8 +124,7 @@ def build(recipe_dir, python, condarc, config, channel, no_test, append_file,
else: else:
build_number = 0 build_number = 0
logger.debug("[var] BOB_BUILD_NUMBER=%s", build_number) set_environment('BOB_BUILD_NUMBER', build_number, os.environ)
os.environ['BOB_BUILD_NUMBER'] = str(build_number)
# we don't execute the following command, it is just here for logging # we don't execute the following command, it is just here for logging
# purposes. we directly use the conda_build API. # 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