Repository: rucio/rucio

Issue:
Possibility to make a pip install directly from git url
Motivation
----------
To be able to install directly from master.


Discussion:
the openstack package pbr is nice for this and can be used (or at least as a source of inspiration)

cf. http://git.openstack.org/cgit/openstack-dev/pbr/tree/pbr/version.py




Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,13 +1,23 @@
-# Copyright European Organization for Nuclear Research (CERN)
+# Copyright 2012-2018 CERN for the benefit of the ATLAS collaboration.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
-# You may not use this file except in compliance with the License.
-# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
 #
 # Authors:
-# - Vincent Garonne, <vincent.garonne@cern.ch>, 2011-2017
-# - Mario Lassnig, <mario.lassnig@cern.ch>, 2012-2013
-# - Martin Barisits, <martin.barisits@cern.ch>, 2016-2017
+# - Mario Lassnig <mario.lassnig@cern.ch>, 2012-2014
+# - Vincent Garonne <vgaronne@gmail.com>, 2012-2018
+# - Martin Barisits <martin.barisits@cern.ch>, 2012-2017
+# - Wen Guan <wguan.icedew@gmail.com>, 2014
+# - Thomas Beermann <thomas.beermann@cern.ch>, 2014
 
 '''
 Setup.py which moves kerberos modules in extra dependencies to be buildthedocs compliant.
@@ -31,7 +41,6 @@
 
 try:
     from setuptools import setup, find_packages
-#    from setuptools.command.sdist import sdist
 except ImportError:
     from ez_setup import use_setuptools
     use_setuptools()
@@ -52,15 +61,51 @@
 
 scripts = glob.glob('bin/rucio*')
 
-# Arguments to the setup script to build stable release
 copy_args = sys.argv[1:]
 if '--release' in copy_args:
     IsRelease = True
     copy_args.remove('--release')
 
-# If Sphinx is installed on the box running setup.py,
-# enable setup.py to build the documentation, otherwise,
-# just ignore it
+# Flags to know if the installation is done through pip and against git
+using_pip = os.path.basename(os.path.dirname(__file__)).startswith('pip-')
+using_git = os.path.isdir('.git')
+
+
+def run_git_command(cmd):
+    """
+    Run a git command in path and return output"
+
+    :param cmd: the git command.
+    :return: Output of the git command.
+    """
+    output = subprocess.Popen(["/bin/sh", "-c", cmd], stdout=subprocess.PIPE)
+    return output.communicate()[0].strip()
+
+
+if using_pip and using_git:
+    git_version_cmd = '''git describe --dirty=-dev`date +%s`'''
+    pkg_version = run_git_command(git_version_cmd)
+    branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
+    branch_nick = run_git_command(branch_nick_cmd)
+    revid_cmd = "git rev-parse HEAD"
+    revid = run_git_command(revid_cmd)
+    revno_cmd = "git --no-pager log --oneline | wc -l"
+    revno = run_git_command(revno_cmd)
+    version_file = open("lib/rucio/vcsversion.py", 'w')
+    version_file.write("""'''\n"""
+                       """This file is automatically generated by setup.py, So don't edit it. :)\n"""
+                       """'''\n"""
+                       """VERSION_INFO = {\n"""
+                       """    'final': False,\n"""
+                       """    'version': '%s',\n"""
+                       """    'branch_nick': '%s',\n"""
+                       """    'revision_id': '%s',\n"""
+                       """    'revno': %s\n"""
+                       """}""" % (pkg_version, branch_nick, revid, revno))
+    version_file.close()
+else:
+    pkg_version = version.version_string()
+
 cmdclass = {}
 
 try:
@@ -151,7 +196,7 @@ def get_file_list(self):
 
 setup(
     name=name,
-    version=version.version_string(),
+    version=pkg_version,
     packages=packages,
     package_dir={'': 'lib'},
     data_files=data_files,


Test patch: