Skip to content

Commit

Permalink
adding site-packages override to avoid dependency breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
lockefox committed Nov 8, 2017
1 parent bb103fa commit e13c128
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
35 changes: 18 additions & 17 deletions prosper/common/prosper_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@

def get_version(
here_path,
default_version=DEFAULT_VERSION,
default_branch=DEFAULT_BRANCH
default_version=DEFAULT_VERSION
):
"""tries to resolve version number
Args:
here_path (str): path to project local dir
default_version (str, optional): what version to return if all else fails
default_branch (str, optional): production branch name
Returns:
(str): semantic_version information for library
str: semantic_version information for library
"""
if 'site-packages' in here_path:
# Running as dependency
return _version_from_file(here_path)

if os.environ.get('TRAVIS_TAG'):
#Running on Travis-CI: trumps all
if not TEST_MODE: #pragma: no cover
# Running on Travis-CI: trumps all
if not TEST_MODE: # pragma: no cover
return os.environ.get('TRAVIS_TAG').replace('v', '')
else:
warnings.warn(
Expand All @@ -43,14 +45,14 @@ def get_version(

try:
current_tag = _read_git_tags(default_version=default_version)
except Exception: #pragma: no cover
except Exception: # pragma: no cover
return _version_from_file(here_path)

#TODO: if #steps from tag root, increment minor
#TODO: check if off main branch and add name to prerelease
# TODO: if #steps from tag root, increment minor
# TODO: check if off main branch and add name to prerelease

with open(os.path.join(here_path, 'version.txt'), 'w') as v_fh:
#save version info somewhere static
# save version info somewhere static
v_fh.write(current_tag)

return current_tag
Expand All @@ -69,13 +71,13 @@ def _read_git_tags(
git_command (:obj:`list`, optional): subprocess command
Retruns:
(str): latest version found, or default
str: latest version found, or default
Raises:
(:obj:`exceptions.ProsperDefaultVersionWarning`): git version not found
exceptions.ProsperDefaultVersionWarning: git version not found
"""
try: #pragma: no cover
try: # pragma: no cover
current_tags = check_output(git_command).splitlines()
except Exception:
raise
Expand All @@ -91,8 +93,8 @@ def _read_git_tags(
tag_str = decode(tag, 'utf-8').replace('v', '')
try:
tag_ver = semantic_version.Version(tag_str)
except Exception: #pragma: no cover
continue #invalid tags ok, but no release
except Exception: # pragma: no cover
continue # invalid tags ok, but no release

if tag_ver > latest_version:
latest_version = tag_ver
Expand All @@ -110,7 +112,7 @@ def _version_from_file(
default_version (str, optional): fallback version in case of error
Returns:
(str): current working version
str: current working version
"""
version_filepath = os.path.join(path_to_version, 'version.txt')
Expand All @@ -124,4 +126,3 @@ def _version_from_file(
data = v_fh.read()

return data

19 changes: 19 additions & 0 deletions tests/test_prosper_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from codecs import decode
from os import path
import os
import shutil
from subprocess import check_output

import pytest
Expand Down Expand Up @@ -124,3 +125,21 @@ def test_travis_tag_testmode():
p_version.TEST_MODE = False
if old_environ:
os.environ['TRAVIS_TAG'] = old_environ

def test_version_installed_as_dep():
"""validate expected return when installed as dependency"""
# Prep a dummy version
virtualenv_name = 'DUMMY_VENV'
dummy_version = '9.9.9'
virtualenv_path = path.join(
HERE, virtualenv_name, 'lib/python3.6/site-packages/prosper/common')
os.makedirs(virtualenv_path, exist_ok=True)
with open(path.join(virtualenv_path, 'version.txt'), 'w') as dummy_fh:
dummy_fh.write(dummy_version)


# Test the thing
assert p_version.get_version(virtualenv_path) == dummy_version

# Clean up yer mess
shutil.rmtree(path.join(HERE, virtualenv_name))

0 comments on commit e13c128

Please sign in to comment.