Repository: engnadeau/pybotics

Issue:
Implicit `GitPython` dependency
## Expected Behavior
<!--
Please explain what was expected from the code (e.g., result, speed).
-->
- Package only depends on `requirements.txt`

## Actual Behavior
<!--
Please explain what actually occured in contrast to expectations.
 
Tracebacks (formatted in code blocks) are appreciated.
-->
- `setup.py` imports `GitPython`

## Steps to Reproduce the Problem
<!--
Please explain how to reproduce the problem.
-->
- On a fresh `python:3` docker image:
```
# pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (36.6.0)
wheel (0.30.0)
```

```
# pip install pybotics
Collecting pybotics
  Using cached pybotics-0.4.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-o6nzl32t/pybotics/setup.py", line 3, in <module>
        import git
    ModuleNotFoundError: No module named 'git'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-o6nzl32t/pybotics/
```

## Specifications
<!--
Please run `utilities/print_system_specs.py` and paste the output in the code block below.
-->
```

```



Discussion:

Resolving patch:
diff --git a/pybotics/__init__.py b/pybotics/__init__.py
--- a/pybotics/__init__.py
+++ b/pybotics/__init__.py
@@ -1,5 +1,4 @@
 """Pybotics modules."""
-from .version import VERSION
 from . import calibration
 from . import constants
 from . import errors
@@ -36,4 +35,5 @@
     'validation',
 ]
 
-__version__ = VERSION
+with open('VERSION') as f:
+    __version__ = f.read()
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,132 +1,50 @@
 """Setup module."""
 from setuptools import setup, find_packages
-import git
 import os
 import logging
 
-REPO_ROOT_PATH = os.path.dirname(__file__)
-VERSION = 'dev'
-GIT_SHA = ''
-GIT_SHA_SHORT = ''
-IS_RELEASE = False
-TAG = ''
-LAST_TAG = '0.0.0'
-
-
-def write_version_py():
-    """
-    Write version info to version.py.
-
-    :return:
-    """
-    content = """
-# THIS FILE IS GENERATED FROM SETUP.PY
-VERSION = '{version}'
-GIT_SHA = '{git_sha}'
-GIT_SHA_SHORT = '{git_sha_short}'
-IS_RELEASE = {is_release}
-"""
-    filename = os.path.join(REPO_ROOT_PATH, 'pybotics', 'version.py')
-    with open(filename, 'w') as file:
-        file.write(content.format(version=VERSION,
-                                  git_sha=GIT_SHA,
-                                  git_sha_short=GIT_SHA_SHORT,
-                                  is_release=IS_RELEASE))
-
-
-def update_git_info():
-    """
-    Get the current git info.
-
-    :return:
-    """
-    repo = git.Repo(REPO_ROOT_PATH)
-    logging.info('Repo:\t{}'.format(repo))
-
-    global GIT_SHA
-    GIT_SHA = repo.head.object.hexsha
-    logging.info('Git sha:\t{}'.format(GIT_SHA))
-
-    global GIT_SHA_SHORT
-    GIT_SHA_SHORT = repo.git.rev_parse(GIT_SHA, short=4)
-    logging.info('Git short sha:\t{}'.format(GIT_SHA_SHORT))
-
-    if len(repo.tags) > 0:
-        global LAST_TAG
-        LAST_TAG = repo.tags[-1]
-        logging.info('Last tag:\t{}'.format(LAST_TAG))
-    else:
-        logging.warning('No tags found:\t{}'.format(LAST_TAG))
-
-
-def check_travis_ci():
-    """
-    Investigate if the current environment is Travis CI.
-
-    :return:
-    """
-    travis_commit = os.environ.get('TRAVIS_COMMIT')
-    logging.info('Travis commit:\t{}'.format(travis_commit))
-
-    travis_branch = os.environ.get('TRAVIS_BRANCH')
-    logging.info('Travis branch:\t{}'.format(travis_branch))
-
-    travis_pr_branch = os.environ.get('TRAVIS_PULL_REQUEST_BRANCH')
-    logging.info('Travis PR branch:\t{}'.format(travis_pr_branch))
-
-    travis_tag = os.environ.get('TRAVIS_TAG')
-    travis_tag = travis_tag if travis_tag is not None else ''
-    logging.info('Travis tag:\t{}'.format(travis_tag))
-
-    if len(travis_tag) > 0:
-        global IS_RELEASE
-        IS_RELEASE = True
-
-        global TAG
-        TAG = '{}'.format(travis_tag)
-
-
-def update_version():
-    """
-    Update the version info.
-
-    :return:
-    """
-    global VERSION
-    if IS_RELEASE:
-        VERSION = '{}'.format(TAG)
-    else:
-        VERSION = '{}.dev{}'.format(LAST_TAG, int(GIT_SHA_SHORT, 16))
-
-    logging.info('Package version:\t{}'.format(VERSION))
-
-
 if __name__ == '__main__':
     logging.basicConfig(level=logging.INFO)
 
-    try:
-        # pypi package should already have version.py
-        from pybotics import version
-    except ImportError:
-        # in CI and on dev, we don't have version.py yet
-        update_git_info()
-        check_travis_ci()
-        update_version()
-        write_version_py()
-    else:
-        VERSION = version.VERSION
-
-    with open(os.path.join(os.path.dirname(__file__),
-                           'requirements', 'requirements.txt')) as f:
+    # version
+    path = os.path.join(
+        os.path.dirname(__file__),
+        'VERSION'
+    )
+    logging.info('Version path: {}'.format(path))
+    with open(path) as f:
+        version = f.read()
+    logging.info('Version: {}'.format(version))
+
+    # requirements
+    path = os.path.join(
+        os.path.dirname(__file__),
+        'requirements',
+        'requirements.txt'
+    )
+    logging.info('Requirements path: {}'.format(path))
+    with open(path) as f:
         requirements = f.read().splitlines()
+    logging.info('Requirements: {}'.format(requirements))
 
-    with open('README.md', encoding='utf-8') as f:
+    # description
+    path = os.path.join(
+        os.path.dirname(__file__),
+        'README.md'
+    )
+    logging.info('Requirements path: {}'.format(path))
+    with open(path, encoding='utf-8') as f:
         description = f.read()
 
     setup(
         name='pybotics',
-        version=VERSION,
-        packages=find_packages(exclude=['*tests*', 'utilities', 'examples']),
+        version=version,
+        packages=find_packages(
+            exclude=[
+                '*tests*',
+                'utilities',
+                'examples'
+            ]),
         url='https://github.com/nnadeau/pybotics',
         license='MIT',
         author='Nicholas Nadeau',
diff --git a/utilities/write_travis_package_info.py b/utilities/write_travis_package_info.py
new file mode 100644
--- /dev/null
+++ b/utilities/write_travis_package_info.py
@@ -0,0 +1,36 @@
+import os
+import logging
+
+if __name__ == '__main__':
+    logging.basicConfig(level=logging.INFO)
+
+    # fetch travis variables
+    travis_commit = os.environ.get('TRAVIS_COMMIT')
+    travis_branch = os.environ.get('TRAVIS_BRANCH')
+    travis_pr_branch = os.environ.get('TRAVIS_PULL_REQUEST_BRANCH')
+    travis_tag = os.environ.get('TRAVIS_TAG')
+
+    # log variables
+    logging.info('Travis commit: {}'.format(travis_commit))
+    logging.info('Travis branch: {}'.format(travis_branch))
+    logging.info('Travis PR branch: {}'.format(travis_pr_branch))
+    logging.info('Travis tag: {}'.format(travis_tag))
+
+    # generate version
+    if travis_tag:
+        version = travis_tag
+    else:
+        if travis_commit:
+            version = '{}'.format(int(travis_commit, 16))
+        else:
+            version = '0.0.0.dev0'
+    logging.info('Version: {}'.format(version))
+
+    version_path = os.path.join(
+        os.path.dirname(os.path.dirname(__file__)),
+        'VERSION'
+    )
+    logging.info('Version path: {}'.format(version_path))
+
+    with open(version_path, 'w') as f:
+        f.write(version)


Test patch: