Skip to content

Commit

Permalink
Merge pull request #4 from /issues/3
Browse files Browse the repository at this point in the history
Issues/3 - fix exception when git binary not present
  • Loading branch information
jantman authored Jun 16, 2017
2 parents 050027e + 5f2499d commit 3a6e3ad
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ matrix:
env: TOXENV=py34-acceptance PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "3.5"
env: TOXENV=py35-acceptance PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "3.6"
env: TOXENV=py36-acceptance PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "2.7"
env: TOXENV=py27-unit PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "3.3"
Expand All @@ -23,6 +25,8 @@ matrix:
env: TOXENV=py34-unit PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "3.5"
env: TOXENV=py35-unit PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "3.6"
env: TOXENV=py36-unit PIP_DOWNLOAD_CACHE=$HOME/.pip-cache
- python: "2.7"
env: TOXENV=docs PIP_DOWNLOAD_CACHE=$HOME/.pip-cache

Expand Down
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

0.1.1 (2017-06-16)
------------------

* Prevent dieing with an exception if ``git`` is not installed on the system.
* Add hack to ``docs/source/conf.py`` as workaround for https://github.com/sphinx-doc/sphinx/issues/3860
* Add TravisCI testing for py36

0.1.0 (2016-12-04)
------------------

Expand Down
28 changes: 25 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import sys
import os
import re
import logging
import types
# to let sphinx find the actual source...
sys.path.insert(0, os.path.abspath("../.."))
from versionfinder.version import VERSION
Expand Down Expand Up @@ -291,7 +293,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'https://docs.python.org/2/': None,
'https://docs.python.org/3/': None,
}

autoclass_content = 'class'
Expand All @@ -307,17 +309,37 @@
r'https?://testpypi\.python\.org/pypi/versionfinder'
]


# exclude module docstrings - see http://stackoverflow.com/a/18031024/211734
def remove_module_docstring(app, what, name, obj, options, lines):
if what == "module":
del lines[:]


# ignore non-local image warnings
def _warn_node(self, msg, node, **kwargs):
if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '%s:%s' % get_source_line(node))
if msg.startswith('nonlocal image URI found:'):
return
self._warnfunc(msg, '%s:%s' % get_source_line(node))

sphinx.environment.BuildEnvironment.warn_node = _warn_node


# BEGIN workaround for https://github.com/sphinx-doc/sphinx/issues/3860
def _images_log_warning(self, msg, *args, **kwargs):
if msg.startswith(
'Could not fetch remote image: '
'https://readthedocs.org/projects/versionfinder/badge/?'
):
print('Suppressing RTD badge remote image warning: %s' % msg)
return
self._orig_warning(msg, *args, **kwargs)

img_log = logging.getLogger('sphinx.transforms.post_transforms.images')
img_log._orig_warning = img_log.warning
img_log.warning = types.MethodType(_images_log_warning, img_log)
# END workaround for https://github.com/sphinx-doc/sphinx/issues/3860


def setup(app):
app.connect("autodoc-process-docstring", remove_module_docstring)
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ envlist = {py27,py33,py34,py35,py36}-{unit,acceptance},docs
[testenv]
deps =
cov-core
coverage==3.7.1
execnet
pep8
py
Expand All @@ -19,6 +18,8 @@ deps =
requests
virtualenv
backoff
py36: coverage
{py27,py33,py34,py35}-{unit,acceptance}: coverage==3.7.1

passenv=TRAVIS*
setenv =
Expand Down
53 changes: 40 additions & 13 deletions versionfinder/tests/test_acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import subprocess
import json
import inspect
import locale
import backoff
import requests
import logging
Expand Down Expand Up @@ -120,7 +119,7 @@ def _get_git_commit():
return commit


def _check_output(args, stderr=None):
def _check_output(args, stderr=None, env=None):
"""
Python version compatibility wrapper for subprocess.check_output
Expand All @@ -130,15 +129,13 @@ def _check_output(args, stderr=None):
:returns: command output
:rtype: string
"""
if sys.version_info < (2, 7):
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr)
(res, err) = p.communicate()
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, args)
else:
res = subprocess.check_output(args, stderr=stderr) # pragma: no cover
if sys.version_info >= (3, 0):
res = res.decode(locale.getdefaultlocale()[1])
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr, env=env)
(res, err) = p.communicate()
if p.returncode != 0:
print("Command %s OUT/ERR:\n%s", args, res)
raise subprocess.CalledProcessError(p.returncode, args)
if not isinstance(res, type("")):
res = res.decode('utf-8')
return res


Expand Down Expand Up @@ -396,7 +393,7 @@ def _make_git_repo(self, path):
print_header("git repository in %s commit: %s" % (path, commit))
return commit

def _get_version(self, path):
def _get_version(self, path, env=None):
"""
In the virtualenv at ``path``, run ``versionfinder-test`` and
return the JSON-decoded output dict.
Expand All @@ -408,7 +405,7 @@ def _get_version(self, path):
"""
args = [os.path.join(path, 'bin', 'versionfinder-test')]
print_header("_get_version() running: " + ' '.join(args))
res = _check_output(args, stderr=subprocess.STDOUT)
res = _check_output(args, stderr=subprocess.STDOUT, env=env)
print(res)
print('DONE')
j = json.loads(res.strip().split("\n")[-1])
Expand Down Expand Up @@ -714,6 +711,10 @@ def test_install_sdist(self, capsys, tmpdir):
}
assert actual == expected

@pytest.mark.skipif(
sys.version_info[0:2] >= (3, 6),
reason='pip 1.5.4 does not work on py >= 3.6'
)
def test_install_sdist_pip154(self, capsys, tmpdir):
"""regression test for issue #55"""
path = str(tmpdir)
Expand Down Expand Up @@ -764,6 +765,32 @@ def test_install_bdist_wheel(self, capsys, tmpdir):
}
assert actual == expected

def test_install_bdist_wheel_no_git_binary(self, capsys, tmpdir):
e = {x: os.environ[x] for x in os.environ}
e['GIT_PYTHON_GIT_EXECUTABLE'] = '/tmp/NoSuchFile'
path = str(tmpdir)
self._make_venv(path)
with capsys_disabled(capsys):
print("\n%s() venv=%s src=%s" % (
inspect.stack()[0][0].f_code.co_name, path, TEST_WHEEL_PATH))
self._pip_install(path, [TEST_WHEEL_PATH])
actual = self._get_result(self._get_version(path, env=e))
expected = {
'failed': False,
'result': {
'git_commit': None,
'git_tag': None,
'git_remotes': None,
'git_is_dirty': None,
'pip_version': TEST_VERSION,
'pip_url': TEST_PROJECT_URL,
'pip_requirement': 'versionfinder-test-pkg==%s' % TEST_VERSION,
'pkg_resources_version': TEST_VERSION,
'pkg_resources_url': TEST_PROJECT_URL,
}
}
assert actual == expected

def test_install_git(self, capsys, tmpdir):
path = str(tmpdir)
self._make_venv(path)
Expand Down
2 changes: 1 addition & 1 deletion versionfinder/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
##################################################################################
"""

VERSION = '0.1.0'
VERSION = '0.1.1'
PROJECT_URL = 'https://github.com/jantman/versionfinder'
2 changes: 1 addition & 1 deletion versionfinder/versionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

try:
from git import Repo
except ImportError:
except Exception:
# this is used within try blocks; NBD if they fail
pass

Expand Down

0 comments on commit 3a6e3ad

Please sign in to comment.