You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2018/08/09 14:12:28 UTC

[arrow] branch master updated: ARROW-3012: [Python] Fix setuptools_scm usage

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 18edb97  ARROW-3012: [Python] Fix setuptools_scm usage
18edb97 is described below

commit 18edb97d5d801e584c8a930666c355c991aca1c4
Author: Antoine Pitrou <an...@python.org>
AuthorDate: Thu Aug 9 10:12:15 2018 -0400

    ARROW-3012: [Python] Fix setuptools_scm usage
    
    We were using a deprecated / unofficial API together with hand-written version parsing.
    We can just pass a custom git tag regex instead.
    
    Also, harden the fallback in setup.py when we're not in a git clone (typically when running `pip install`, as pip always copies the project directory before acting on it).
    Include a clear error message when not able to infer the Arrow version, to let people
    know how to workaround the issue.
    
    pip-installing source distributions should now work fine (and get the right version
    number).
    
    Author: Antoine Pitrou <an...@python.org>
    
    Closes #2413 from pitrou/ARROW-3012-fix-setuptools-scm-usage and squashes the following commits:
    
    5369d640 <Antoine Pitrou> Re-add a parse function to avoid non-C++ tags
    2a93f9cc <Antoine Pitrou> ARROW-3012:  Fix setuptools_scm usage
---
 python/MANIFEST.in         |  1 +
 python/pyarrow/__init__.py | 33 ++++++++-----------
 python/setup.py            | 79 ++++++++++++++++++++++++++++++----------------
 3 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/python/MANIFEST.in b/python/MANIFEST.in
index c6c9cd4..1ae612f 100644
--- a/python/MANIFEST.in
+++ b/python/MANIFEST.in
@@ -11,3 +11,4 @@ global-exclude *~
 global-exclude \#*
 global-exclude .git*
 global-exclude .DS_Store
+prune .asv
diff --git a/python/pyarrow/__init__.py b/python/pyarrow/__init__.py
index f4137d9..44edda4 100644
--- a/python/pyarrow/__init__.py
+++ b/python/pyarrow/__init__.py
@@ -24,32 +24,27 @@ from pkg_resources import get_distribution, DistributionNotFound
 try:
     __version__ = get_distribution(__name__).version
 except DistributionNotFound:
-   # package is not installed
+    # Package is not installed, parse git tag at runtime
     try:
-        # This code is duplicated from setup.py to avoid a dependency on each
-        # other.
-        def parse_version(root):
-            from setuptools_scm import version_from_scm
-            import setuptools_scm.git
-            describe = (setuptools_scm.git.DEFAULT_DESCRIBE +
-                        " --match 'apache-arrow-[0-9]*'")
-            # Strip catchall from the commandline
-            describe = describe.replace("--match *.*", "")
-            version = setuptools_scm.git.parse(root, describe)
-            if not version:
-                return version_from_scm(root)
-            else:
-                return version
-
         import setuptools_scm
-        __version__ = setuptools_scm.get_version('../', parse=parse_version)
-    except (ImportError, LookupError):
+        # Code duplicated from setup.py to avoid a dependency on each other
+        def parse_git(root, **kwargs):
+            """
+            Parse function for setuptools_scm that ignores tags for non-C++
+            subprojects, e.g. apache-arrow-js-XXX tags.
+            """
+            from setuptools_scm.git import parse
+            kwargs['describe_command'] = \
+                "git describe --dirty --tags --long --match 'apache-arrow-[0-9].*'"
+            return parse(root, **kwargs)
+        __version__ = setuptools_scm.get_version('../',
+                                                 parse=parse_git)
+    except ImportError:
         __version__ = None
 
 
 import pyarrow.compat as compat
 
-
 # Workaround for https://issues.apache.org/jira/browse/ARROW-2657
 # and https://issues.apache.org/jira/browse/ARROW-2920
 if _sys.platform in ('linux', 'linux2'):
diff --git a/python/setup.py b/python/setup.py
index 3dc59f2..d32b020 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -457,18 +457,53 @@ def _move_shared_libs_unix(build_prefix, build_lib, lib_name):
             os.symlink(lib_filename, link_name)
 
 
-# In the case of a git-archive, we don't have any version information
-# from the SCM to infer a version. The only source is the java/pom.xml.
-#
-# Note that this is only the case for git-archives. sdist tarballs have
-# all relevant information (but not the Java sources).
-if not os.path.exists('../.git') and os.path.exists('../java/pom.xml'):
-    import xml.etree.ElementTree as ET
-    tree = ET.parse('../java/pom.xml')
-    version_tag = list(tree.getroot().findall(
-        '{http://maven.apache.org/POM/4.0.0}version'))[0]
-    os.environ["SETUPTOOLS_SCM_PRETEND_VERSION"] = version_tag.text.replace(
-        "-SNAPSHOT", "a0")
+# If the event of not running from a git clone (e.g. from a git archive
+# or a Python sdist), see if we can set the version number ourselves
+if (not os.path.exists('../.git')
+        and not os.environ.get('SETUPTOOLS_SCM_PRETEND_VERSION')):
+    if os.path.exists('PKG-INFO'):
+        # We're probably in a Python sdist, setuptools_scm will handle fine
+        pass
+    elif os.path.exists('../java/pom.xml'):
+        # We're probably in a git archive
+        import xml.etree.ElementTree as ET
+        tree = ET.parse('../java/pom.xml')
+        version_tag = list(tree.getroot().findall(
+            '{http://maven.apache.org/POM/4.0.0}version'))[0]
+        use_setuptools_scm = False
+        os.environ['SETUPTOOLS_SCM_PRETEND_VERSION'] = \
+            version_tag.text.replace("-SNAPSHOT", "a0")
+    else:
+        raise RuntimeError("""\
+            No reliable source available to get Arrow version.
+
+            This is either because you copied the python/ directory yourself
+            outside of a git clone or source archive, or because you ran
+            `pip install` on the python/ directory.
+
+            * Recommended workaround: first run `python sdist`, then
+              `pip install` the resulting source distribution.
+
+            * If you're looking for an editable (in-place) install,
+              `python setup.py develop` should work fine in place of
+              `pip install -e .`.
+
+            * If you really want to `pip install` the python/ directory,
+              set the SETUPTOOLS_SCM_PRETEND_VERSION environment variable
+              to force the Arrow version to the given value.
+            """)
+
+
+def parse_git(root, **kwargs):
+    """
+    Parse function for setuptools_scm that ignores tags for non-C++
+    subprojects, e.g. apache-arrow-js-XXX tags.
+    """
+    from setuptools_scm.git import parse
+    kwargs['describe_command'] = \
+        "git describe --dirty --tags --long --match 'apache-arrow-[0-9].*'"
+    return parse(root, **kwargs)
+
 
 with open('README.md') as f:
     long_description = f.read()
@@ -486,26 +521,13 @@ install_requires = (
 )
 
 
-def parse_version(root):
-    from setuptools_scm import version_from_scm
-    import setuptools_scm.git
-    describe = (setuptools_scm.git.DEFAULT_DESCRIBE +
-                " --match 'apache-arrow-[0-9]*'")
-    # Strip catchall from the commandline
-    describe = describe.replace("--match *.*", "")
-    version = setuptools_scm.git.parse(root, describe)
-    if not version:
-        return version_from_scm(root)
-    else:
-        return version
-
-
 # Only include pytest-runner in setup_requires if we're invoking tests
 if {'pytest', 'test', 'ptr'}.intersection(sys.argv):
     setup_requires = ['pytest-runner']
 else:
     setup_requires = []
 
+
 setup(
     name="pyarrow",
     packages=['pyarrow', 'pyarrow.tests'],
@@ -524,8 +546,9 @@ setup(
             'plasma_store = pyarrow:_plasma_store_entry_point'
         ]
     },
-    use_scm_version={"root": "..", "relative_to": __file__,
-                     "parse": parse_version},
+    use_scm_version={"root": "..",
+                     "relative_to": __file__,
+                     "parse": parse_git},
     setup_requires=['setuptools_scm', 'cython >= 0.27'] + setup_requires,
     install_requires=install_requires,
     tests_require=['pytest', 'pandas'],