def test_empty_git_cpp(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ // --------------------------------------------------- // This file is autogenerated by git-version. // DO NOT MODIFY! // --------------------------------------------------- #pragma once #ifndef MESSMER_GITVERSION_VERSION_H #define MESSMER_GITVERSION_VERSION_H namespace version { constexpr const char *VERSION_STRING = "dev1+rev%s"; constexpr const char *GIT_TAG_NAME = "master"; constexpr const unsigned int GIT_COMMITS_SINCE_TAG = 1; constexpr const char *GIT_COMMIT_ID = "%s"; constexpr bool MODIFIED_SINCE_COMMIT = false; constexpr bool IS_DEV_VERSION = true; constexpr bool IS_STABLE_VERSION = false; } #endif """ % (commit_id[0:7], commit_id[0:7]) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="cpp") self.assertCodeEqual(expected, self.read_file(out_file))
def test_tagged_git_with_commits_after_tag(self): with GitDir() as git, TempFile() as out_file: git.create_git_commit() git.create_git_tag("1.0.1") commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "1.0.1.dev1+rev%s" GIT_TAG_NAME = "1.0.1" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False VERSION_COMPONENTS = ["1", "0", "1"] VERSION_TAG = "" """ % (commit_id[0:7], commit_id[0:7]) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_tagged_git_with_commits_after_tag(self): with GitDir() as git, TempFile() as out_file: git.create_git_commit() git.create_git_tag("1.0.1") commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "1.0.1.dev1+rev%s" GIT_TAG_NAME = "1.0.1" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False VERSION_COMPONENTS = ["1", "0", "1"] VERSION_TAG = "" """ % ( commit_id[0:7], commit_id[0:7], ) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_empty_git_cpp(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ // --------------------------------------------------- // This file is autogenerated by git-version. // DO NOT MODIFY! // --------------------------------------------------- #pragma once #ifndef MESSMER_GITVERSION_VERSION_H #define MESSMER_GITVERSION_VERSION_H namespace version { constexpr const char *VERSION_STRING = "dev1+rev%s"; constexpr const char *GIT_TAG_NAME = "master"; constexpr const unsigned int GIT_COMMITS_SINCE_TAG = 1; constexpr const char *GIT_COMMIT_ID = "%s"; constexpr bool MODIFIED_SINCE_COMMIT = false; constexpr bool IS_DEV_VERSION = true; constexpr bool IS_STABLE_VERSION = false; } #endif """ % ( commit_id[0:7], commit_id[0:7], ) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="cpp") self.assertCodeEqual(expected, self.read_file(out_file))
def run_main(): parser = argparse.ArgumentParser(description="Create a source file containing git version information.") parser.add_argument('--version', action='version', version=Version.VERSION_STRING) parser.add_argument('--lang', choices=['cpp', 'python'], required=True) parser.add_argument('--dir', default='.') parser.add_argument('file') args = parser.parse_args() print("Creating git version information from %s" % args.dir) main.create_version_file(git_directory=args.dir, output_file=args.file, lang=args.lang)
def run_main(): parser = argparse.ArgumentParser( description="Create a source file containing git version information.") parser.add_argument('--version', action='version', version=Version.VERSION_STRING) parser.add_argument('--lang', choices=['cpp', 'python'], required=True) parser.add_argument('--dir', default='.') parser.add_argument('file') args = parser.parse_args() print("Creating git version information from %s" % args.dir) main.create_version_file(git_directory=args.dir, output_file=args.file, lang=args.lang)
def test_tagged_git_with_different_tagname_scheme(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() git.create_git_tag("versionone") expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "versionone" GIT_TAG_NAME = "versionone" GIT_COMMITS_SINCE_TAG = 0 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = False """ % commit_id[0:7] main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_empty_git_python(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "dev1+rev%s" GIT_TAG_NAME = "master" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False """ % (commit_id[0:7], commit_id[0:7]) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_tagged_git_with_different_tagname_scheme(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() git.create_git_tag("versionone") expected = ( """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "versionone" GIT_TAG_NAME = "versionone" GIT_COMMITS_SINCE_TAG = 0 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = False """ % commit_id[0:7] ) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
def test_empty_git_python(self): with GitDir() as git, TempFile() as out_file: commit_id = git.create_git_commit() expected = """ # --------------------------------------------------- # This file is autogenerated by git-version. # DO NOT MODIFY! # --------------------------------------------------- VERSION_STRING = "dev1+rev%s" GIT_TAG_NAME = "master" GIT_COMMITS_SINCE_TAG = 1 GIT_COMMIT_ID = "%s" MODIFIED_SINCE_COMMIT = False IS_DEV_VERSION = True IS_STABLE_VERSION = False """ % ( commit_id[0:7], commit_id[0:7], ) main.create_version_file(git_directory=git.dir, output_file=out_file, lang="python") self.assertCodeEqual(expected, self.read_file(out_file))
#!/usr/bin/env python from setuptools import setup from gitversionbuilder import main main.create_version_file(git_directory=".", output_file="gitversionbuilder/Version.py", lang="python") version = main.get_version(git_directory=".") setup( name='git-version', version=version.version_string, description= 'Make git version information (e.g. git tag name, git commit id, ...) available to your C++ or python source files. A simple use case scenario is to output this version information when the application is called with "--version".', author='Sebastian Messmer', author_email='*****@*****.**', license='GPLv3', url='https://github.com/smessmer/gitversion', packages=['gitversionbuilder'], tests_require=['tempdir'], test_suite='test', entry_points={ 'console_scripts': ["git-version = gitversionbuilder.__main__:run_main"] }, classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python", "Programming Language :: C++",
#!/usr/bin/env python from setuptools import setup from gitversionbuilder import main main.create_version_file(git_directory=".", output_file="gitversionbuilder/Version.py", lang="python") version = main.get_version(git_directory=".") setup(name='git-version', version=version.version_string, description='Make git version information (e.g. git tag name, git commit id, ...) available to your C++ or python source files. A simple use case scenario is to output this version information when the application is called with "--version".', author='Sebastian Messmer', author_email='*****@*****.**', license='GPLv3', url='https://github.com/smessmer/gitversion', packages=['gitversionbuilder'], tests_require=['tempdir'], test_suite='test', entry_points = { 'console_scripts': [ "git-version = gitversionbuilder.__main__:run_main" ] }, classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python", "Programming Language :: C++", "Topic :: Software Development :: Build Tools",