Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
crgwbr committed Mar 23, 2016
1 parent dd518e6 commit 02dc995
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# file GENERATED by distutils, do NOT edit
LICENSE.md
README.rst
requirements.txt
setup.py
version.txt
versiontag/__init__.py
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

5 changes: 4 additions & 1 deletion tests/test_versiontag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
import tempfile
import unittest
import os
import logging

import versiontag


def silent_call(*args):
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(args)
subprocess.check_call(args, stdout=devnull, stderr=devnull)


class VersionTagTest(unittest.TestCase):
def setUp(self):
logging.disable(logging.CRITICAL)
self.repo_dir = tempfile.TemporaryDirectory()
os.chdir(self.repo_dir.name)

def tearDown(self):
self.repo_dir.cleanup()
logging.disable(logging.NOTSET)

def _set_author(self):
silent_call('git', 'config', 'user.email', '[email protected]')
Expand Down
15 changes: 12 additions & 3 deletions versiontag/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import subprocess
import re
import logging


__default_version__ = 'r0.0.0'
logger = logging.getLogger(__name__)


def __get_git_tag():
Expand All @@ -19,21 +21,25 @@ def __get_cache_file():
return os.path.join(os.getcwd(), 'version.txt')


def __open_cache_file(mode):
return open(__get_cache_file(), mode)


def cache_git_tag():
try:
version = __get_git_tag()
with __open_cache_file('w') as vf:
vf.write(version)
except:
version = __default_version__
with open(__get_cache_file(), 'w') as vf:
vf.write(version)
return version


def get_version(pypi=False):
version = __default_version__

try:
with open(__get_cache_file(), 'r') as vf:
with __open_cache_file('r') as vf:
version = vf.read().strip()
except:
pass
Expand All @@ -43,6 +49,9 @@ def get_version(pypi=False):
except:
pass

if version == __default_version__:
logger.warning("versiontag could not determine package version using cwd %s. Returning default: %s" % (os.getcwd(), __default_version__))

if pypi:
# Convert to pypi valid version:
# 1. Drop the r prefix we use on git tags: r1.0.1-12-geaea7b6 => 1.0.1-12-geaea7b6
Expand Down

0 comments on commit 02dc995

Please sign in to comment.