Skip to content

Commit

Permalink
Merge pull request #53 from r9y9/version
Browse files Browse the repository at this point in the history
setuppy: Include git commit hash to __version__
  • Loading branch information
r9y9 committed Dec 22, 2017
2 parents 74bc912 + 6b0404e commit 87da379
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pysptk/_sptk.c
pysptk/version.py
docs/generated

# Created by https://www.gitignore.io
Expand Down
4 changes: 1 addition & 3 deletions pysptk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@

from __future__ import division, print_function, absolute_import

import pkg_resources

__version__ = pkg_resources.get_distribution('pysptk').version
from .version import __version__

from .sptk import * # pylint: disable=wildcard-import

Expand Down
48 changes: 44 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,54 @@
from __future__ import with_statement, print_function, absolute_import

from setuptools import setup, find_packages, Extension
import setuptools.command.develop
import setuptools.command.build_py
from distutils.version import LooseVersion

import numpy as np
import os
from glob import glob
from os.path import join
import subprocess

version = '0.1.8'

# Adapted from https://github.com/pytorch/pytorch
cwd = os.path.dirname(os.path.abspath(__file__))
if os.getenv('PYSPTK_BUILD_VERSION'):
version = os.getenv('PYSPTK_BUILD_VERSION')
else:
try:
sha = subprocess.check_output(
['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip()
version += '+' + sha[:7]
except subprocess.CalledProcessError:
pass


class build_py(setuptools.command.build_py.build_py):

def run(self):
self.create_version_file()
setuptools.command.build_py.build_py.run(self)

@staticmethod
def create_version_file():
global version, cwd
print('-- Building version ' + version)
version_path = os.path.join(cwd, 'pysptk', 'version.py')
with open(version_path, 'w') as f:
f.write("__version__ = '{}'\n".format(version))


class develop(setuptools.command.develop.develop):

def run(self):
build_py.create_version_file()
setuptools.command.develop.develop.run(self)


cmdclass = {"build_py": build_py, "develop": develop}

min_cython_ver = '0.21.0'
try:
Expand All @@ -29,12 +70,11 @@

if cython:
ext = '.pyx'
cmdclass = {'build_ext': build_ext}
cmdclass['build_ext'] = build_ext
else:
ext = '.c'
cmdclass = {}
if not os.path.exists(join("pysptk", "_sptk" + ext)):
raise RuntimeError("Cython is required to generate C codes.")
raise RuntimeError("Cython is required to generate C code.")

# SPTK sources
src_top = join("lib", "SPTK")
Expand Down Expand Up @@ -73,7 +113,7 @@

setup(
name='pysptk',
version='0.1.8-dev',
version=version,
description='A python wrapper for Speech Signal Processing Toolkit (SPTK)',
author='Ryuichi Yamamoto',
author_email='zryuichi@gmail.com',
Expand Down

0 comments on commit 87da379

Please sign in to comment.