From 50cf420238dff5c8d3ea7b9a084d4bb656e0382b Mon Sep 17 00:00:00 2001
From: Zohreh MOSTAANI <zohreh.mostaani@idiap.ch>
Date: Wed, 5 Jun 2019 16:41:21 +0200
Subject: [PATCH] added command to generate documentations locally

---
 bob/devtools/scripts/local.py | 83 +++++++++++++++++++++++++++++++++++
 setup.py                      |  5 +++
 2 files changed, 88 insertions(+)
 create mode 100644 bob/devtools/scripts/local.py

diff --git a/bob/devtools/scripts/local.py b/bob/devtools/scripts/local.py
new file mode 100644
index 00000000..e5b89277
--- /dev/null
+++ b/bob/devtools/scripts/local.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import re
+import glob
+import shutil
+
+import gitlab
+
+import yaml
+import click
+import pkg_resources
+from click_plugins import with_plugins
+
+from . import bdt
+from . import ci
+from ..constants import SERVER, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \
+    WEBDAV_PATHS, BASE_CONDARC
+from ..deploy import deploy_conda_package, deploy_documentation
+from ..ci import read_packages, comment_cleanup, uniq
+
+from ..log import verbosity_option, get_logger, echo_normal
+logger = get_logger(__name__)
+
+
+def set_up_environment_variables(python, name_space, project_dir='.', project_visibility='public'):
+  """
+  This function sets up the proper environment variables when user wants to run the commands usually run on ci
+  locally
+  """
+  os.environ['CI_JOB_TOKEN'] = gitlab.Gitlab.from_config('idiap').private_token
+  os.environ['CI_PROJECT_DIR'] = project_dir
+  os.environ['CI_PROJECT_NAMESPACE'] = name_space
+  os.environ['CI_PROJECT_VISIBILITY'] = project_visibility
+  os.environ['PYTHON_VERSION']= python
+
+
+
+@with_plugins(pkg_resources.iter_entry_points('bdt.local.cli'))
+@click.group(cls=bdt.AliasedGroup)
+def local():
+  """Commands for building packages and handling certain activities locally
+  it requires a proper set up for ~/.python-gitlab.cfg
+
+  Commands defined here can be run in your own installation.
+  """
+  pass
+
+
+@local.command(epilog='''
+Examples:
+
+  1. Prepares the docs locally:
+
+     $ bdt local docs -vv requirements.txt
+
+''')
+@click.argument('requirement', required=True, type=click.Path(file_okay=True,
+  dir_okay=False, exists=True), nargs=1)
+@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('-p', '--python', default=('%d.%d' % sys.version_info[:2]),
+    show_default=True, help='Version of python to build the environment for')
+@click.option('-g', '--group', show_default=True, default='bob',
+    help='Group of packages (gitlab namespace) this package belongs to')
+@verbosity_option()
+@bdt.raise_on_error
+@click.pass_context
+def docs(ctx, requirement, dry_run, python, group):
+  """Prepares documentation build
+
+  This command:
+    1. Clones all the necessary packages necessary to build the bob/beat
+       documentation
+    2. Generates the `extra-intersphinx.txt` and `nitpick-exceptions.txt` file
+
+  """
+  set_up_environment_variables(python=python, name_space=group)  
+
+  ctx.invoke(ci.docs, requirement=requirement, dry_run=dry_run)
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 03be32f0..dc8c28f9 100644
--- a/setup.py
+++ b/setup.py
@@ -55,6 +55,7 @@ setup(
           'test = bob.devtools.scripts.test:test',
           'caupdate = bob.devtools.scripts.caupdate:caupdate',
           'ci = bob.devtools.scripts.ci:ci',
+          'local = bob.devtools.scripts.local:local',
           'gitlab = bob.devtools.scripts.gitlab:gitlab',
           ],
 
@@ -82,6 +83,10 @@ setup(
           'docs = bob.devtools.scripts.ci:docs',        
           ],
 
+        'bdt.local.cli': [
+          'docs = bob.devtools.scripts.local:docs',        
+          ],
+
     },
     classifiers=[
         'Framework :: Bob',
-- 
GitLab