# Buggy code
def __enter__(self):
    self.release_version = Release.version

    # Get the hash from the git repository if available
    self.restore_version = False
    git_master_path = ".git/refs/heads/master"
    if self.release_version.endswith(".dev"):
        p = subprocess.Popen(
            ["git", "describe", "--tags", "--dirty", "--always"], stdout=subprocess.PIPE
        )
        stdout = p.communicate()[0]
        if p.returncode != 0:
            # Git is not available, we keep the version as is
            self.restore_version = False
            self.version = self.release_version
        else:
            gd = stdout[1:].strip().decode()
            # Remove the tag
            gd = gd[gd.index("-") + 1 :]
            self.version = self.release_version + "+git."
            self.version += gd.replace("-", ".")
            update_version(self.version)
            self.restore_version = True
    else:
        self.version = self.release_version
    return self.version


# Traceback (FileNotFoundError)
Obtaining file:///C:/Users/macark/Documents/GitHub/hyperspy
Complete output from command python setup.py egg_info:
C:\Users\macark\Documents\GitHub\hyperspy\setup.py:180: UserWarning: WARNING: C compiler can't be found.
Only slow pure python alternative functions will be available.
To use fast implementation of some functions writen in cython/c either:
a) check that you have compiler (EXACTLY SAME as your python
distribution was compiled with) installed,
b) use binary distribution of hyperspy (i.e. wheels, egg, (only osx and win)).
Installation will continue in 5 sec...
Installation will continue in 5 sec...""")
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\macark\Documents\GitHub\hyperspy\setup.py", line 298, in <module>
with update_version_when_dev() as version:
File "C:\Users\macark\Documents\GitHub\hyperspy\setup.py", line 275, in __enter__
stdout=subprocess.PIPE)
File "c:\program files\anaconda3\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "c:\program files\anaconda3\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\macark\Documents\GitHub\hyperspy\

# Fixed code
def __enter__(self):
    self.release_version = Release.version

    # Get the hash from the git repository if available
    self.restore_version = False
    if self.release_version.endswith(".dev"):
        p = subprocess.Popen(
            ["git", "describe", "--tags", "--dirty", "--always"],
            stdout=subprocess.PIPE,
            shell=True,
        )
        stdout = p.communicate()[0]
        if p.returncode != 0:
            # Git is not available, we keep the version as is
            self.restore_version = False
            self.version = self.release_version
        else:
            gd = stdout[1:].strip().decode()
            # Remove the tag
            gd = gd[gd.index("-") + 1 :]
            self.version = self.release_version + "+git."
            self.version += gd.replace("-", ".")
            update_version(self.version)
            self.restore_version = True
    else:
        self.version = self.release_version
    return self.version