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

Commit

Permalink
Merge pull request #215 from nnadeau/version-fix
Browse files Browse the repository at this point in the history
Version fix
  • Loading branch information
nnadeau authored Nov 19, 2017
2 parents 4f78e66 + c53b551 commit bc5af98
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 124 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,5 @@ ENV/

.idea
*.rej
VERSION
.mypy_cache/
README.rst
pybotics/version.py
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@ addons:
- python-wheel-common
- python3-wheel

before_install:
- python utilities/write_travis_package_info.py

install:
- pip install -r requirements/coverage.txt
- pip install -r requirements/examples.txt
- pip install -r requirements/packaging.txt
- pip install -r requirements/requirements.txt
- pip install -r requirements/static-testing.txt
- pip install -v .
- chmod +x ci/log-system-info.sh
- chmod +x ci/run-static-tests.sh
- chmod +x utilities/log-system-info.sh
- chmod +x utilities/run-static-tests.sh

script:
# log info
- ./ci/log-system-info.sh
- ./utilities/log-system-info.sh
# static testing
- ./ci/run-static-tests.sh
- ./utilities/run-static-tests.sh
# unit testing
- python setup.py test
# dist testing
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.5.0] - 2017-11-18
### Fixed
- [Implicit `GitPython` dependency](https://github.com/nnadeau/pybotics/issues/214)

## [0.4.1] - 2017-11-10
### Fixed
- Error in `setup.py` when installing released package from PyPI
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include LICENSE
include README.md
include VERSION
include requirements/requirements.txt
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0.dev0
4 changes: 2 additions & 2 deletions pybotics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Pybotics modules."""
from .version import VERSION
from . import calibration
from . import constants
from . import errors
Expand Down Expand Up @@ -36,4 +35,5 @@
'validation',
]

__version__ = VERSION
with open('VERSION') as f:
__version__ = f.read()
1 change: 0 additions & 1 deletion requirements/packaging.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
GitPython==2.1.7
pytest==3.2.5
pytest-runner==3.0
setuptools==36.7.2
148 changes: 33 additions & 115 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,132 +1,50 @@
"""Setup module."""
from setuptools import setup, find_packages
import git
import os
import logging

REPO_ROOT_PATH = os.path.dirname(__file__)
VERSION = 'dev'
GIT_SHA = ''
GIT_SHA_SHORT = ''
IS_RELEASE = False
TAG = ''
LAST_TAG = '0.0.0'


def write_version_py():
"""
Write version info to version.py.
:return:
"""
content = """
# THIS FILE IS GENERATED FROM SETUP.PY
VERSION = '{version}'
GIT_SHA = '{git_sha}'
GIT_SHA_SHORT = '{git_sha_short}'
IS_RELEASE = {is_release}
"""
filename = os.path.join(REPO_ROOT_PATH, 'pybotics', 'version.py')
with open(filename, 'w') as file:
file.write(content.format(version=VERSION,
git_sha=GIT_SHA,
git_sha_short=GIT_SHA_SHORT,
is_release=IS_RELEASE))


def update_git_info():
"""
Get the current git info.
:return:
"""
repo = git.Repo(REPO_ROOT_PATH)
logging.info('Repo:\t{}'.format(repo))

global GIT_SHA
GIT_SHA = repo.head.object.hexsha
logging.info('Git sha:\t{}'.format(GIT_SHA))

global GIT_SHA_SHORT
GIT_SHA_SHORT = repo.git.rev_parse(GIT_SHA, short=4)
logging.info('Git short sha:\t{}'.format(GIT_SHA_SHORT))

if len(repo.tags) > 0:
global LAST_TAG
LAST_TAG = repo.tags[-1]
logging.info('Last tag:\t{}'.format(LAST_TAG))
else:
logging.warning('No tags found:\t{}'.format(LAST_TAG))


def check_travis_ci():
"""
Investigate if the current environment is Travis CI.
:return:
"""
travis_commit = os.environ.get('TRAVIS_COMMIT')
logging.info('Travis commit:\t{}'.format(travis_commit))

travis_branch = os.environ.get('TRAVIS_BRANCH')
logging.info('Travis branch:\t{}'.format(travis_branch))

travis_pr_branch = os.environ.get('TRAVIS_PULL_REQUEST_BRANCH')
logging.info('Travis PR branch:\t{}'.format(travis_pr_branch))

travis_tag = os.environ.get('TRAVIS_TAG')
travis_tag = travis_tag if travis_tag is not None else ''
logging.info('Travis tag:\t{}'.format(travis_tag))

if len(travis_tag) > 0:
global IS_RELEASE
IS_RELEASE = True

global TAG
TAG = '{}'.format(travis_tag)


def update_version():
"""
Update the version info.
:return:
"""
global VERSION
if IS_RELEASE:
VERSION = '{}'.format(TAG)
else:
VERSION = '{}.dev{}'.format(LAST_TAG, int(GIT_SHA_SHORT, 16))

logging.info('Package version:\t{}'.format(VERSION))


if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)

try:
# pypi package should already have version.py
from pybotics import version
except ImportError:
# in CI and on dev, we don't have version.py yet
update_git_info()
check_travis_ci()
update_version()
write_version_py()
else:
VERSION = version.VERSION

with open(os.path.join(os.path.dirname(__file__),
'requirements', 'requirements.txt')) as f:
# version
path = os.path.join(
os.path.dirname(__file__),
'VERSION'
)
logging.info('Version path: {}'.format(path))
with open(path) as f:
version = f.read()
logging.info('Version: {}'.format(version))

# requirements
path = os.path.join(
os.path.dirname(__file__),
'requirements',
'requirements.txt'
)
logging.info('Requirements path: {}'.format(path))
with open(path) as f:
requirements = f.read().splitlines()
logging.info('Requirements: {}'.format(requirements))

with open('README.md', encoding='utf-8') as f:
# description
path = os.path.join(
os.path.dirname(__file__),
'README.md'
)
logging.info('Requirements path: {}'.format(path))
with open(path, encoding='utf-8') as f:
description = f.read()

setup(
name='pybotics',
version=VERSION,
packages=find_packages(exclude=['*tests*', 'utilities', 'examples']),
version=version,
packages=find_packages(
exclude=[
'*tests*',
'utilities',
'examples'
]),
url='https://github.com/nnadeau/pybotics',
license='MIT',
author='Nicholas Nadeau',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions utilities/write_travis_package_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import logging

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)

# fetch travis variables
travis_commit = os.environ.get('TRAVIS_COMMIT')
travis_branch = os.environ.get('TRAVIS_BRANCH')
travis_pr_branch = os.environ.get('TRAVIS_PULL_REQUEST_BRANCH')
travis_tag = os.environ.get('TRAVIS_TAG')

# log variables
logging.info('Travis commit: {}'.format(travis_commit))
logging.info('Travis branch: {}'.format(travis_branch))
logging.info('Travis PR branch: {}'.format(travis_pr_branch))
logging.info('Travis tag: {}'.format(travis_tag))

# generate version
if travis_tag:
version = travis_tag
else:
if travis_commit:
version = '{}'.format(int(travis_commit, 16))
else:
version = '0.0.0.dev0'
logging.info('Version: {}'.format(version))

version_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'VERSION'
)
logging.info('Version path: {}'.format(version_path))

with open(version_path, 'w') as f:
f.write(version)

0 comments on commit bc5af98

Please sign in to comment.