Skip to content

Commit

Permalink
feat: check for Git in relevant commands and put this requirement in …
Browse files Browse the repository at this point in the history
…the docs

* docs: add git requirement to memote isntall instruction

* feat: check for the presence of git in all relevant CLI commands

* chore: update changelog

* chore: implement suggestions from code review
  • Loading branch information
ChristianLieven committed Apr 12, 2019
1 parent 3e69578 commit ee0e729
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ History

Next Release
------------
* Include memote's requirement for git on installation instructions.
* Check for the presence of `git` in CLI commands that require it.
* Replace vega with taucharts in all reports.
* Fix plots to be large enough.
* Fix responsive behaviour.
Expand Down
14 changes: 9 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ at via GitHub pages for your repository.
Installation
============

We highly recommend creating a Python virtualenv for your model testing purposes.
Before installing `memote`, make sure that you have correctly installed the
latest version of `git <https://git-scm.com/>`_.

To install memote, run this command in your terminal:
Moreover, we highly recommend creating a Python virtualenv for your model
testing purposes.

To install `memote`, run this command in your terminal:

.. code-block:: console
$ pip install memote
This is the preferred method to install memote, as it will always install the
This is the preferred method to install `memote`, as it will always install the
most recent stable release.

.. who-start
Expand Down Expand Up @@ -99,7 +103,7 @@ Credits
This package was created with Cookiecutter_ and the
`audreyr/cookiecutter-pypackage`_ project template.

Memote relies on click_ for the command line interface, pytest_ for unit
`Memote` relies on click_ for the command line interface, pytest_ for unit
and model tests, gitpython_ for interacting with git repositories,
pandas_ for tabular datastructures and data input, jinja2_ for interacting
with HTML templates, cobrapy_ for analysing genome-scale metabolic
Expand All @@ -116,7 +120,7 @@ The Memote Report App user interface is built with `Angular 5`_,
`Angular Flex-Layout`_, and `Angular Material`_. We rely on Vega_ for plotting
results.

The initial development of memote has received funding from:
The initial development of `memote` has received funding from:

.. image:: https://upload.wikimedia.org/wikipedia/commons/d/d5/Novo_nordisk_foundation_Logo.png
:target: http://novonordiskfonden.dk/en
Expand Down
4 changes: 4 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
Installation
============

Before installing memote, make sure that you have correctly installed the
latest version of `git`_.

We highly recommend creating a Python `virtualenv`_ for your model testing
purposes.

.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/
.. _git: https://git-scm.com/

Stable release
--------------
Expand Down
16 changes: 16 additions & 0 deletions memote/suite/cli/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import shlex
import sys
import logging
from subprocess import check_output, CalledProcessError

import click
import git
Expand Down Expand Up @@ -97,3 +98,18 @@ def abort_if_false(ctx, param, value):
"""Require confirmation."""
if not value:
ctx.abort()


def git_installed():
"""Interrupt execution of memote if `git` has not been installed."""
LOGGER.info("Checking `git` installation.")
try:
check_output(['git', '--version'])
except CalledProcessError as e:
LOGGER.critical(
"The execution of memote was interrupted since no installation of "
"`git` could be detected. Please install git to use "
"this functionality: "
"https://git-scm.com/book/en/v2/Getting-Started-Installing-Git")
LOGGER.debug("Underlying error:", exc_info=e)
sys.exit(1)
1 change: 1 addition & 0 deletions memote/suite/cli/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def snapshot(model, filename, pytest_args, exclusive, skip, solver,
"option can be specified multiple times.")
def history(location, model, filename, deployment, custom_config):
"""Generate a report over a model's git commit history."""
callbacks.git_installed()
LOGGER.info("Initialising history report generation.")
if location is None:
raise click.BadParameter("No 'location' given or configured.")
Expand Down
4 changes: 4 additions & 0 deletions memote/suite/cli/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def is_verbose(arg):
if ignore_git:
repo = None
else:
callbacks.git_installed()
repo = callbacks.probe_git()
if collect:
if repo is not None:
Expand Down Expand Up @@ -239,6 +240,7 @@ def new(directory, replay):
--directory option.
"""
callbacks.git_installed()
if directory is None:
directory = os.getcwd()
cookiecutter("gh:opencobra/cookiecutter-memote", output_dir=directory,
Expand Down Expand Up @@ -324,6 +326,7 @@ def history(model, message, rewrite, solver, location, pytest_args, deployment,
"""
# callbacks.validate_path(model)
callbacks.git_installed()
if location is None:
raise click.BadParameter("No 'location' given or configured.")
if "--tb" not in pytest_args:
Expand Down Expand Up @@ -730,6 +733,7 @@ def _setup_travis_ci(gh_repo_name, auth_token, repo_access_token):
help="The GitHub username. Usually this is configured for you.")
def online(note, github_repository, github_username):
"""Upload the repository to GitHub and enable testing on Travis CI."""
callbacks.git_installed()
try:
repo = git.Repo()
except git.InvalidGitRepositoryError:
Expand Down

0 comments on commit ee0e729

Please sign in to comment.