<commit_before>#!/usr/bin/env python

__all__ = ("get_version")

from subprocess import check_output
from os import path, name
current_directory = path.dirname(path.abspath(__file__))
version_file = path.join(current_directory, "VERSION")

git_command = "git"
if name == "nt":
    def find_git_on_windows():
        from subprocess import CalledProcessError
        # first see if git is in the path
        try:
            check_output(["where", "/Q", "git"])
            # if this command succeeded, git is in the path
            return "git"
        # catch the exception thrown if git was not found
        except CalledProcessError:
            None
        # There are several locations git.exe may be hiding
        possible_locations = []
        from os import environ, listdir
        # look in program files for msysgit
        if "PROGRAMFILES(X86)" in environ:
            possible_locations.append("%s/Git/cmd/git.exe" % \
                environ["PROGRAMFILES(X86)"])
        if "PROGRAMFILES" in environ:
            possible_locations.append("%s/Git/cmd/git.exe" % \
                environ["PROGRAMFILES"])
        # look for the github version of git
        if "LOCALAPPDATA" in environ:
            github_dir = "%s/GitHub" % environ["LOCALAPPDATA"]
            if path.isdir(github_dir):
                for subdir in listdir(github_dir):
                    if not subdir.startswith("PortableGit"):
                        continue
                    possible_locations.append("%s/%s/bin/git.exe" % \
                        (github_dir, subdir))
        for possible_location in possible_locations:
            if path.isfile(possible_location):
                return possible_location
        # git was not found
        return "git"

    git_command = find_git_on_windows()


def call_git_describe(abbrev=4):
    try:
        return check_output([git_command, "describe",  "--tags",
            "--abbrev=%d" % abbrev], cwd=current_directory).strip()
    except:
        return None


def read_release_version():
    try:
        with open(version_file, "r") as infile:
            version = infile.read().strip()
        if len(version) == 0:
            version = None
        return version
    except:
        return None

<commit_msg>fixes issue #22 (7 char git hash in version)<commit_after>#!/usr/bin/env python

__all__ = ("get_version")

from subprocess import check_output
from os import path, name
current_directory = path.dirname(path.abspath(__file__))
version_file = path.join(current_directory, "VERSION")

git_command = "git"
if name == "nt":
    def find_git_on_windows():
        from subprocess import CalledProcessError
        # first see if git is in the path
        try:
            check_output(["where", "/Q", "git"])
            # if this command succeeded, git is in the path
            return "git"
        # catch the exception thrown if git was not found
        except CalledProcessError:
            None
        # There are several locations git.exe may be hiding
        possible_locations = []
        from os import environ, listdir
        # look in program files for msysgit
        if "PROGRAMFILES(X86)" in environ:
            possible_locations.append("%s/Git/cmd/git.exe" % \
                environ["PROGRAMFILES(X86)"])
        if "PROGRAMFILES" in environ:
            possible_locations.append("%s/Git/cmd/git.exe" % \
                environ["PROGRAMFILES"])
        # look for the github version of git
        if "LOCALAPPDATA" in environ:
            github_dir = "%s/GitHub" % environ["LOCALAPPDATA"]
            if path.isdir(github_dir):
                for subdir in listdir(github_dir):
                    if not subdir.startswith("PortableGit"):
                        continue
                    possible_locations.append("%s/%s/bin/git.exe" % \
                        (github_dir, subdir))
        for possible_location in possible_locations:
            if path.isfile(possible_location):
                return possible_location
        # git was not found
        return "git"

    git_command = find_git_on_windows()


def call_git_describe(abbrev=7):
    try:
        return check_output([git_command, "describe",  "--tags",
            "--abbrev=%d" % abbrev], cwd=current_directory).strip()
    except:
        return None


def read_release_version():
    try:
        with open(version_file, "r") as infile:
            version = infile.read().strip()
        if len(version) == 0:
            version = None
        return version
    except:
        return None


{'fraction_non_alphanumeric': 0.09608229371853798, 'fraction_numerical': 0.003282994090610637, 'mean_word_length': 2.060951105157401, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2921199', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1252, 'n_words': 352}