mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From klue...@apache.org
Subject [mesos] branch master updated: Updated Python library to properly import submodules.
Date Tue, 16 Oct 2018 11:48:23 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new c6d7d55  Updated Python library to properly import submodules.
c6d7d55 is described below

commit c6d7d5593a9792411a876a97303989fc3db7441b
Author: Armand Grillet <agrillet@mesosphere.io>
AuthorDate: Tue Oct 16 07:35:02 2018 -0400

    Updated Python library to properly import submodules.
    
    The primary change was to add imports in '__init__.py' so that when
    doing an 'import mesos' from some code using this module, we are
    able to access submodules (e.g. 'mesos.http') as part of this.
    
    In the process of making this change, we ran into the error pointed out
    in variant 6 at the following link, for how to properly set the version
    of a python module both in the code itself, and in its package
    definition via setup.py.
    
    https://packaging.python.org/guides/single-sourcing-package-version/
    
    We decided to change to method 1 from this link to address this problem.
    
    Review: https://reviews.apache.org/r/69047/
---
 src/python/lib/mesos/__init__.py |  4 ++++
 src/python/lib/setup.py          | 26 +++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/python/lib/mesos/__init__.py b/src/python/lib/mesos/__init__.py
index 40219c5..bbe82e2 100644
--- a/src/python/lib/mesos/__init__.py
+++ b/src/python/lib/mesos/__init__.py
@@ -19,3 +19,7 @@ Client library for the Mesos HTTP ReST API
 """
 
 __version__ = '0.0.0.dev'
+
+__all__ = ['exceptions', 'http']
+from . import exceptions
+from . import http
diff --git a/src/python/lib/setup.py b/src/python/lib/setup.py
index 08f854f..e959237 100644
--- a/src/python/lib/setup.py
+++ b/src/python/lib/setup.py
@@ -18,9 +18,10 @@
 Setup script for the mesos package
 """
 
-from setuptools import find_packages, setup
+import os
+import re
 
-from mesos import __version__
+from setuptools import find_packages, setup
 
 
 def read_requirements(filename="requirements.in"):
@@ -34,6 +35,25 @@ def read_requirements(filename="requirements.in"):
     with open(filename) as f:
         return f.readlines()
 
+def find_version(*relative_path_parts):
+    """
+    Find the version string in a file relative to the current directory.
+
+    :param relative_path_parts: list of path parts relative
+                                to the current directory where
+                                the file containing the __version__
+                                string lives
+    :type relative_path_parts: list[str]
+    :rtype: str
+    """
+    currdir = os.path.abspath(os.path.dirname(__file__))
+    version_file = os.path.join(currdir, *relative_path_parts)
+
+    with open(version_file, 'r') as f:
+        match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M)
+        if not match:
+            raise RuntimeError("Unable to find version string.")
+        return match.group(1)
 
 setup(
     author='Apache Mesos',
@@ -44,6 +64,6 @@ setup(
     license='apache',
     name='mesos',
     packages=find_packages(),
-    version=__version__,
+    version=find_version('mesos', '__init__.py'),
     zip_safe=False,
 )


Mime
View raw message