Commit 1729c472 authored by André Anjos's avatar André Anjos 💬
Browse files

[multiple] Pass docformatter to clean-up blacks docstring mess

parent d5ae11d9
Pipeline #32385 passed with stage
in 5 minutes and 51 seconds
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Bootstraps a new miniconda installation and prepares it for development"""
"""Bootstraps a new miniconda installation and prepares it for development."""
_BASE_CONDARC = """\
......@@ -48,7 +48,7 @@ logger = logging.getLogger(__name__)
def set_environment(name, value, env=os.environ):
"""Function to setup the environment variable and print debug message
"""Function to setup the environment variable and print debug message.
Args:
......@@ -63,7 +63,7 @@ def set_environment(name, value, env=os.environ):
def human_time(seconds, granularity=2):
'''Returns a human readable time string like "1 day, 2 hours"'''
"""Returns a human readable time string like "1 day, 2 hours"."""
result = []
......@@ -92,17 +92,15 @@ def human_time(seconds, granularity=2):
def run_cmdline(cmd, env=None):
"""Runs a command on a environment, logs output and reports status
"""Runs a command on a environment, logs output and reports status.
Parameters:
Parameters:
cmd (list): The command to run, with parameters separated on a list
cmd (list): The command to run, with parameters separated on a list
env (dict, Optional): Environment to use for running the program on. If not
set, use :py:obj:`os.environ`.
"""
env (dict, Optional): Environment to use for running the program on. If not
set, use :py:obj:`os.environ`.
"""
if env is None:
env = os.environ
......@@ -136,21 +134,21 @@ def run_cmdline(cmd, env=None):
def touch(path):
"""Python-implementation of the "touch" command-line application"""
"""Python-implementation of the "touch" command-line application."""
with open(path, "a"):
os.utime(path, None)
def merge_conda_cache(cache, prefix, name):
"""Merges conda pkg caches and conda-bld folders
"""Merges conda pkg caches and conda-bld folders.
Args:
Args:
cache: The cached directory (from previous builds)
prefix: The current prefix (root of conda installation)
name: The name of the current package
"""
cache: The cached directory (from previous builds)
prefix: The current prefix (root of conda installation)
name: The name of the current package
"""
pkgs_dir = os.path.join(prefix, "pkgs")
pkgs_urls_txt = os.path.join(pkgs_dir, "urls.txt")
......@@ -204,7 +202,7 @@ def merge_conda_cache(cache, prefix, name):
def get_miniconda_sh():
"""Retrieves the miniconda3 installer for the current system"""
"""Retrieves the miniconda3 installer for the current system."""
import http.client
......@@ -232,14 +230,13 @@ def get_miniconda_sh():
def install_miniconda(prefix, name):
"""Creates a new miniconda installation
Args:
"""Creates a new miniconda installation.
prefix: The path leading to the (new) root of the miniconda installation
name: The name of this package
Args:
"""
prefix: The path leading to the (new) root of the miniconda installation
name: The name of this package
"""
logger.info("Installing miniconda in %s...", prefix)
......@@ -264,37 +261,36 @@ def install_miniconda(prefix, name):
def get_channels(public, stable, server, intranet, group):
"""Returns the relevant conda channels to consider if building project
The subset of channels to be returned depends on the visibility and stability
of the package being built. Here are the rules:
"""Returns the relevant conda channels to consider if building project.
* public and stable: only returns the public stable channel(s)
* public and not stable: returns both public stable and beta channels
* not public and stable: returns both public and private stable channels
* not public and not stable: returns all channels
The subset of channels to be returned depends on the visibility and stability
of the package being built. Here are the rules:
Beta channels have priority over stable channels, if returned. Private
channels have priority over public channles, if turned.
* public and stable: only returns the public stable channel(s)
* public and not stable: returns both public stable and beta channels
* not public and stable: returns both public and private stable channels
* not public and not stable: returns all channels
Beta channels have priority over stable channels, if returned. Private
channels have priority over public channles, if turned.
Args:
public: Boolean indicating if we're supposed to include only public
channels
stable: Boolean indicating if we're supposed to include only stable
channels
server: The base address of the server containing our conda channels
intranet: Boolean indicating if we should add "private"/"public" prefixes
on the conda paths
group: The group of packages (gitlab namespace) the package we're compiling
is part of. Values should match URL namespaces currently available on
our internal webserver. Currently, only "bob" or "beat" will work.
Args:
public: Boolean indicating if we're supposed to include only public
channels
stable: Boolean indicating if we're supposed to include only stable
channels
server: The base address of the server containing our conda channels
intranet: Boolean indicating if we should add "private"/"public" prefixes
on the conda paths
group: The group of packages (gitlab namespace) the package we're compiling
is part of. Values should match URL namespaces currently available on
our internal webserver. Currently, only "bob" or "beat" will work.
Returns: a list of channels that need to be considered.
"""
Returns: a list of channels that need to be considered.
"""
if (not public) and (not intranet):
raise RuntimeError(
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tools for self-building and other utilities"""
"""Tools for self-building and other utilities."""
import os
......@@ -23,21 +23,21 @@ import conda_build.api
def comment_cleanup(lines):
"""Cleans-up comments and empty lines from textual data read from files"""
"""Cleans-up comments and empty lines from textual data read from files."""
no_comments = [k.partition("#")[0].strip() for k in lines]
return [k for k in no_comments if k]
def load_order_file(path):
"""Loads an order.txt style file, removes empty lines and comments"""
"""Loads an order.txt style file, removes empty lines and comments."""
with open(path, "rt") as f:
return comment_cleanup(f.readlines())
def conda_arch():
"""Returns the current OS name and architecture as recognized by conda"""
"""Returns the current OS name and architecture as recognized by conda."""
r = "unknown"
if platform.system().lower() == "linux":
......@@ -57,32 +57,30 @@ def conda_arch():
def should_skip_build(metadata_tuples):
"""Takes the output of render_recipe as input and evaluates if this
recipe's build should be skipped.
"""
recipe's build should be skipped."""
return all(m[0].skip() for m in metadata_tuples)
def next_build_number(channel_url, basename):
"""Calculates the next build number of a package given the channel
"""Calculates the next build number of a package given the channel.
This function returns the next build number (integer) for a package given its
resulting tarball base filename (can be obtained with
:py:func:`get_output_path`).
This function returns the next build number (integer) for a package given its
resulting tarball base filename (can be obtained with
:py:func:`get_output_path`).
Args:
Args:
channel_url: The URL where to look for packages clashes (normally a beta
channel)
basename: The tarball basename to check on the channel
channel_url: The URL where to look for packages clashes (normally a beta
channel)
basename: The tarball basename to check on the channel
Returns: The next build number with the current configuration. Zero (0) is
returned if no match is found. Also returns the URLs of the packages it
finds with matches on the name, version and python-version, ordered by
(reversed) build-number.
"""
Returns: The next build number with the current configuration. Zero (0) is
returned if no match is found. Also returns the URLs of the packages it
finds with matches on the name, version and python-version, ordered by
(reversed) build-number.
"""
from conda.exports import get_index
......@@ -141,23 +139,23 @@ def next_build_number(channel_url, basename):
def make_conda_config(config, python, append_file, condarc_options):
"""Creates a conda configuration for a build merging various sources
"""Creates a conda configuration for a build merging various sources.
This function will use the conda-build API to construct a configuration by
merging different sources of information.
This function will use the conda-build API to construct a configuration by
merging different sources of information.
Args:
Args:
config: Path leading to the ``conda_build_config.yaml`` to use
python: The version of python to use for the build as ``x.y`` (e.g.
``3.6``)
append_file: Path leading to the ``recipe_append.yaml`` file to use
condarc_options: A dictionary (typically read from a condarc YAML file)
that contains build and channel options
config: Path leading to the ``conda_build_config.yaml`` to use
python: The version of python to use for the build as ``x.y`` (e.g.
``3.6``)
append_file: Path leading to the ``recipe_append.yaml`` file to use
condarc_options: A dictionary (typically read from a condarc YAML file)
that contains build and channel options
Returns: A dictionary containing the merged configuration, as produced by
conda-build API's ``get_or_merge_config()`` function.
"""
Returns: A dictionary containing the merged configuration, as produced by
conda-build API's ``get_or_merge_config()`` function.
"""
from conda_build.conda_interface import url_path
......@@ -187,39 +185,38 @@ def make_conda_config(config, python, append_file, condarc_options):
def get_output_path(metadata, config):
"""Renders the recipe and returns the name of the output file"""
"""Renders the recipe and returns the name of the output file."""
return conda_build.api.get_output_file_paths(metadata, config=config)[0]
def get_rendered_metadata(recipe_dir, config):
"""Renders the recipe and returns the interpreted YAML file"""
"""Renders the recipe and returns the interpreted YAML file."""
return conda_build.api.render(recipe_dir, config=config)
def get_parsed_recipe(metadata):
"""Renders the recipe and returns the interpreted YAML file"""
"""Renders the recipe and returns the interpreted YAML file."""
output = conda_build.api.output_yaml(metadata[0][0])
return yaml.load(output, Loader=yaml.FullLoader)
def exists_on_channel(channel_url, basename):
"""Checks on the given channel if a package with the specs exist
This procedure always ignores the package hash code, if one is set
"""Checks on the given channel if a package with the specs exist.
Args:
This procedure always ignores the package hash code, if one is set
channel_url: The URL where to look for packages clashes (normally a beta
channel)
basename: The basename of the tarball to search for
Args:
Returns: A complete package url, if the package already exists in the channel
or ``None`` otherwise.
channel_url: The URL where to look for packages clashes (normally a beta
channel)
basename: The basename of the tarball to search for
"""
Returns: A complete package url, if the package already exists in the channel
or ``None`` otherwise.
"""
build_number, urls = next_build_number(channel_url, basename)
......@@ -266,7 +263,7 @@ def parse_dependencies(recipe_dir, config):
def get_env_directory(conda, name):
"""Get the directory of a particular conda environment or fail silently"""
"""Get the directory of a particular conda environment or fail silently."""
cmd = [conda, "env", "list", "--json"]
output = subprocess.check_output(cmd)
......@@ -291,23 +288,23 @@ def get_env_directory(conda, name):
def conda_create(conda, name, overwrite, condarc, packages, dry_run, use_local):
"""Creates a new conda environment following package specifications
This command can create a new conda environment following the list of input
packages. It will overwrite an existing environment if indicated.
Args:
conda: path to the main conda executable of the installation
name: the name of the environment to create or overwrite
overwrite: if set to ```True``, overwrite potentially existing environments
with the same name
condarc: a dictionary of options for conda, including channel urls
packages: the package list specification
dry_run: if set, then don't execute anything, just print stuff
use_local: include the local conda-bld directory as a possible installation
channel (useful for testing multiple interdependent recipes that are
built locally)
"""
"""Creates a new conda environment following package specifications.
This command can create a new conda environment following the list of input
packages. It will overwrite an existing environment if indicated.
Args:
conda: path to the main conda executable of the installation
name: the name of the environment to create or overwrite
overwrite: if set to ```True``, overwrite potentially existing environments
with the same name
condarc: a dictionary of options for conda, including channel urls
packages: the package list specification
dry_run: if set, then don't execute anything, just print stuff
use_local: include the local conda-bld directory as a possible installation
channel (useful for testing multiple interdependent recipes that are
built locally)
"""
from .bootstrap import run_cmdline
......@@ -360,38 +357,37 @@ def conda_create(conda, name, overwrite, condarc, packages, dry_run, use_local):
def get_docserver_setup(public, stable, server, intranet, group):
"""Returns a setup for BOB_DOCUMENTATION_SERVER
"""Returns a setup for BOB_DOCUMENTATION_SERVER.
What is available to build the documentation depends on the setup of
``public`` and ``stable``:
What is available to build the documentation depends on the setup of
``public`` and ``stable``:
* public and stable: only returns the public stable channel(s)
* public and not stable: returns both public stable and beta channels
* not public and stable: returns both public and private stable channels
* not public and not stable: returns all channels
* public and stable: only returns the public stable channel(s)
* public and not stable: returns both public stable and beta channels
* not public and stable: returns both public and private stable channels
* not public and not stable: returns all channels
Beta channels have priority over stable channels, if returned. Private
channels have priority over public channles, if turned.
Beta channels have priority over stable channels, if returned. Private
channels have priority over public channles, if turned.
Args:
Args:
public: Boolean indicating if we're supposed to include only public
channels
stable: Boolean indicating if we're supposed to include only stable
channels
server: The base address of the server containing our conda channels
intranet: Boolean indicating if we should add "private"/"public" prefixes
on the returned paths
group: The group of packages (gitlab namespace) the package we're compiling
is part of. Values should match URL namespaces currently available on
our internal webserver. Currently, only "bob" or "beat" will work.
public: Boolean indicating if we're supposed to include only public
channels
stable: Boolean indicating if we're supposed to include only stable
channels
server: The base address of the server containing our conda channels
intranet: Boolean indicating if we should add "private"/"public" prefixes
on the returned paths
group: The group of packages (gitlab namespace) the package we're compiling
is part of. Values should match URL namespaces currently available on
our internal webserver. Currently, only "bob" or "beat" will work.
Returns: a string to be used by bob.extension to find dependent
documentation projects.
"""
Returns: a string to be used by bob.extension to find dependent
documentation projects.
"""
if (not public) and (not intranet):
raise RuntimeError(
......@@ -429,25 +425,25 @@ def get_docserver_setup(public, stable, server, intranet, group):
def check_version(workdir, envtag):
"""Checks if the version being built and the value reported match
"""Checks if the version being built and the value reported match.
This method will read the contents of the file ``version.txt`` and compare it
to the potentially set ``envtag`` (may be ``None``). If the value of
``envtag`` is different than ``None``, ensure it matches the value in
``version.txt`` or raises an exception.
This method will read the contents of the file ``version.txt`` and compare it
to the potentially set ``envtag`` (may be ``None``). If the value of
``envtag`` is different than ``None``, ensure it matches the value in
``version.txt`` or raises an exception.
Args:
Args:
workdir: The work directory where the repo of the package being built was
checked-out
envtag: (optional) tag provided by the environment
workdir: The work directory where the repo of the package being built was
checked-out
envtag: (optional) tag provided by the environment
Returns: A tuple with the version of the package that we're currently
building and a boolean flag indicating if the version number represents a
pre-release or a stable release.
"""
Returns: A tuple with the version of the package that we're currently
building and a boolean flag indicating if the version number represents a
pre-release or a stable release.
"""
version = open(os.path.join(workdir, "version.txt"), "rt").read().rstrip()
......@@ -483,15 +479,14 @@ def check_version(workdir, envtag):
def git_clean_build(runner, verbose):
"""Runs git-clean to clean-up build products
Args:
"""Runs git-clean to clean-up build products.
runner: A pointer to the ``run_cmdline()`` function
verbose: A boolean flag indicating if the git command should report erased
files or not
Args:
"""
runner: A pointer to the ``run_cmdline()`` function
verbose: A boolean flag indicating if the git command should report erased
files or not
"""
# glob wild card entries we'd like to keep
exclude_from_cleanup = [
......@@ -533,42 +528,42 @@ def base_build(
python_version,
condarc_options,
):
"""Builds a non-beat/non-bob software dependence that doesn't exist on defaults
This function will build a software dependence that is required for our
software stack, but does not (yet) exist on the defaults channels. It first
check if the build should run for the current architecture, checks if the
package is not already built on our public channel and, if that is true, then
proceeds with the build of the dependence.
Args:
bootstrap: Module that should be pre-loaded so this function can be used
in a pre-bdt build
server: The base address of the server containing our conda channels
intranet: Boolean indicating if we should add "private"/"public" prefixes
on the returned paths
group: The group of packages (gitlab namespace) the package we're compiling
is part of. Values should match URL namespaces currently available on
our internal webserver. Currently, only "bob" or "beat" will work.
recipe_dir: The directory containing the recipe's ``meta.yaml`` file
conda_build_config: Path to the ``conda_build_config.yaml`` file to use
python_version: String with the python version to build for, in the format
``x.y`` (should be passed even if not building a python package). It
can also be set to ``noarch``, or ``None``. If set to ``None``, then we
don't assume there is a python-specific version being built. If set to
``noarch``, then it is a python package without a specific build.
condarc_options: Pre-parsed condarc options loaded from the respective YAML
file
Returns:
list: The list of built packages, as returned by
``conda_build.api.build()``
"""
"""Builds a non-beat/non-bob software dependence that doesn't exist on
defaults.
This function will build a software dependence that is required for our
software stack, but does not (yet) exist on the defaults channels. It first
check if the build should run for the current architecture, checks if the
package is not already built on our public channel and, if that is true, then
proceeds with the build of the dependence.
Args:
bootstrap: Module that should be pre-loaded so this function can be used
in a pre-bdt build
server: The base address of the server containing our conda channels
intranet: Boolean indicating if we should add "private"/"public" prefixes
on the returned paths
group: The group of packages (gitlab namespace) the package we're compiling
is part of. Values should match URL namespaces currently available on
our internal webserver. Currently, only "bob" or "beat" will work.
recipe_dir: The directory containing the recipe's ``meta.yaml`` file
conda_build_config: Path to the ``conda_build_config.yaml`` file to use
python_version: String with the python version to build for, in the format
``x.y`` (should be passed even if not building a python package). It
can also be set to ``noarch``, or ``None``. If set to ``None``, then we
don't assume there is a python-specific version being built. If set to
``noarch``, then it is a python package without a specific build.
condarc_options: Pre-parsed condarc options loaded from the respective YAML
file
Returns:
list: The list of built packages, as returned by
``conda_build.api.build()``
"""
# if you get to this point, tries to build the package
public_channels = bootstrap.get_channels(
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Utilities for retrieving, parsing and auto-generating changelogs"""
"""Utilities for retrieving, parsing and auto-generating changelogs."""
import io
import datetime
......@@ -23,7 +23,7 @@ def parse_date(d):
def _sort_commits(commits, reverse):
"""Sorts gitlab commit objects using their ``committed_date`` attribute"""
"""Sorts gitlab commit objects using their ``committed_date`` attribute."""
return sorted(
commits, key=lambda x: parse_date(x.committed_date), reverse=reverse
......@@ -31,7 +31,7 @@ def _sort_commits(commits, reverse):
def _sort_tags(tags, reverse):
"""Sorts gitlab tag objects using their ``committed_date`` attribute"""
"""Sorts gitlab tag objects using their ``committed_date`` attribute."""
return sorted(
tags,
......@@ -41,13 +41,13 @@ def _sort_tags(tags, reverse):
def get_file_from_gitlab(gitpkg, path, ref="master"):
"""Retrieves a file from a Gitlab repository, returns a (StringIO) file"""
"""Retrieves a file from a Gitlab repository, returns a (StringIO) file."""
return io.StringIO(gitpkg.files.get(file_path=path, ref=branch).decode())
def get_last_tag(package):
"""Returns the last (gitlab object) tag for the given package
"""Returns the last (gitlab object) tag for the given package.
Args:
......@@ -68,7 +68,7 @@ def get_last_tag(package):
def get_last_tag_date(package):
"""Returns the last release date for the given package
"""Returns the last release date for the given package.
Falls back to the first commit date if the package has not yet been tagged
......@@ -135,14 +135,13 @@ def _get_tag_changelog(tag):
def _write_one_tag(f, pkg_name, tag):
"""Prints commit information for a single tag of a given package
"""Prints commit information for a single tag of a given package.
Args: