setup.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. import os
  18. from os.path import dirname
  19. from setuptools import find_packages, setup
  20. AMBARI_COMMON_PYTHON_FOLDER = "ambari-common/src/main/python"
  21. AMBARI_SERVER_TEST_PYTHON_FOLDER = "ambari-server/src/test/python"
  22. AMBARI_COMMON_TEST_PYTHON_FOLDER = "ambari-common/src/test/python"
  23. def get_ambari_common_packages():
  24. return find_packages(AMBARI_COMMON_PYTHON_FOLDER, exclude=["*.tests", "*.tests.*", "tests.*", "tests"])
  25. def get_ambari_server_stack_package():
  26. return ["stacks.utils"]
  27. def get_extra_common_packages():
  28. return ["urlinfo_processor", "ambari_jinja2", "ambari_jinja2._markupsafe", "mock", "mock.test"]
  29. def create_package_dir_map():
  30. package_dirs = {}
  31. ambari_common_packages = get_ambari_common_packages()
  32. for ambari_common_package in ambari_common_packages:
  33. package_dirs[ambari_common_package] = AMBARI_COMMON_PYTHON_FOLDER + '/' + ambari_common_package.replace(".", "/")
  34. ambari_server_packages = get_ambari_server_stack_package()
  35. for ambari_server_package in ambari_server_packages:
  36. package_dirs[ambari_server_package] = AMBARI_SERVER_TEST_PYTHON_FOLDER + '/' + ambari_server_package.replace(".", "/")
  37. package_dirs["ambari_jinja2"] = AMBARI_COMMON_PYTHON_FOLDER + "/ambari_jinja2/ambari_jinja2"
  38. package_dirs["ambari_jinja2._markupsafe"] = AMBARI_COMMON_PYTHON_FOLDER + "/ambari_jinja2/ambari_jinja2/_markupsafe"
  39. package_dirs["urlinfo_processor"] = AMBARI_COMMON_PYTHON_FOLDER + "/urlinfo_processor"
  40. package_dirs["mock"] = AMBARI_COMMON_TEST_PYTHON_FOLDER + "/mock"
  41. package_dirs["mock.test"] = AMBARI_COMMON_TEST_PYTHON_FOLDER + "/mock/tests"
  42. return package_dirs
  43. __version__ = "3.0.0.0-SNAPSHOT"
  44. def get_version():
  45. """
  46. Obtain ambari version during the build from pom.xml, which will be stored in PKG-INFO file.
  47. During installation from pip, pom.xml is not included in the distribution but PKG-INFO is, so it can be used
  48. instead of pom.xml file. If for some reason both are not exists use the default __version__ variable.
  49. All of these can be overridden by AMBARI_VERSION environment variable.
  50. """
  51. base_dir = dirname(__file__)
  52. if "AMBARI_VERSION" in os.environ:
  53. return os.environ["AMBARI_VERSION"]
  54. elif os.path.exists(os.path.join(base_dir, 'pom.xml')):
  55. from xml.etree import ElementTree as et
  56. ns = "http://maven.apache.org/POM/4.0.0"
  57. et.register_namespace('', ns)
  58. tree = et.ElementTree()
  59. tree.parse(os.path.join(base_dir, 'pom.xml'))
  60. parent_version_tag = tree.getroot().find("{%s}version" % ns)
  61. return parent_version_tag.text if parent_version_tag is not None else __version__
  62. elif os.path.exists(os.path.join(base_dir, 'PKG-INFO')):
  63. import re
  64. version = None
  65. version_re = re.compile('^Version: (.+)$', re.M)
  66. with open(os.path.join(base_dir, 'PKG-INFO')) as f:
  67. version = version_re.search(f.read()).group(1)
  68. return version if version is not None else __version__
  69. else:
  70. return __version__
  71. """
  72. Example usage:
  73. - build package with specific version:
  74. python setup.py sdist -d "my/dist/location"
  75. - build and install package with specific version:
  76. python setup.py sdist -d "my/dist/location" install
  77. - build and upload package with specific version:
  78. python setup.py sdist -d "my/dist/location" upload -r "http://localhost:8080"
  79. Installing from pip:
  80. - pip install --extra-index-url=http://localhost:8080 ambari-python==2.7.1.0 // 3.0.0.0-SNAPSHOT is the snapshot version
  81. """
  82. setup(
  83. name = "ambari-python",
  84. version = get_version(),
  85. author = "Apache Software Foundation",
  86. author_email = "dev@ambari.apache.org",
  87. description = ("Framework for provison/manage/monitor Hadoop clusters"),
  88. license = "AP2",
  89. keywords = "hadoop, ambari",
  90. url = "https://ambari.apache.org",
  91. packages = get_ambari_common_packages() + get_ambari_server_stack_package() + get_extra_common_packages(),
  92. package_dir = create_package_dir_map(),
  93. install_requires=[
  94. 'coilmq==1.0.1'
  95. ],
  96. include_package_data = True,
  97. long_description="The Apache Ambari project is aimed at making Hadoop management simpler by developing software for provisioning, managing, and monitoring Apache Hadoop clusters. "
  98. "Ambari provides an intuitive, easy-to-use Hadoop management web UI backed by its RESTful APIs."
  99. )