Skip to content
Snippets Groups Projects
setup.py 1.85 KiB
Newer Older
Tessaris Sergio's avatar
Tessaris Sergio committed
from setuptools import setup, find_packages
import re
import codecs
import os
import subprocess

# Hack to allow non-normalised versions
#   see <https://github.com/pypa/setuptools/issues/308>
from setuptools.extern.packaging import version
version.Version = version.LegacyVersion

_INCLUDE_GIT_REV_ = False


# see <https://stackoverflow.com/a/39671214> and 
#     <https://packaging.python.org/guides/single-sourcing-package-version>
def find_version(*pkg_path):
    pkg_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), *pkg_path)
    version_file = codecs.open(os.path.join(pkg_dir, '__init__.py'), 'r').read()
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    _git_revision_ = None
    if _INCLUDE_GIT_REV_:
        try:
            _git_revision_ = subprocess.check_output(['git', 'describe', '--always', '--dirty'], encoding='utf-8').strip()
        except subprocess.CalledProcessError:
            pass
    if version_match:
        return version_match.group(1) + ('' if _git_revision_ is None else '+' + _git_revision_)
    elif _git_revision_:
        return _git_revision_
    raise RuntimeError("Unable to find version string.")


def long_description_md(fname='README.md'):
    this_directory = os.path.abspath(os.path.dirname(__file__))
    with open(os.path.join(this_directory, fname), encoding='utf-8') as f:
        long_description = f.read()
    return long_description


setup(
    name='wumpus',
    version=find_version('wumpus'),
    description='Wumpus world simulator',
    long_description=long_description_md(),
    long_description_content_type='text/markdown',
    author='Sergio Tessaris',
    author_email='tessaris@inf.unibz.it',
    packages=find_packages(),
    include_package_data=True,
    install_requires=[
    ],
    exclude_package_data={'': ['.gitignore']},
)