From bedb234dfffd1a1d18549b69828b404ad15aecd2 Mon Sep 17 00:00:00 2001 From: Piotr Date: Mon, 7 Jan 2019 22:11:05 +0100 Subject: [PATCH 1/8] Use setuptools and don't install in /opt/graphite anymore Don't install in /opt/graphite anymore, this is just strange and causes nothing but trouble. Setuptools does not support it either. Switch to setuptools to get rid of following warnings: UserWarning: Unknown distribution option: 'install_requires' UserWarning: Unknown distribution option: 'long_description_content_type' --- setup.py | 141 +++++++++++++++++-------------------------------------- 1 file changed, 43 insertions(+), 98 deletions(-) diff --git a/setup.py b/setup.py index 4e74e2fdb..75fe949a3 100644 --- a/setup.py +++ b/setup.py @@ -1,115 +1,60 @@ #!/usr/bin/env python -from __future__ import with_statement - import os from glob import glob -try: - from ConfigParser import ConfigParser, DuplicateSectionError # Python 2 -except ImportError: - from configparser import ConfigParser, DuplicateSectionError # Python 3 - - -# Graphite historically has an install prefix set in setup.cfg. Being in a -# configuration file, it's not easy to override it or unset it (for installing -# graphite in a virtualenv for instance). -# The prefix is now set by ``setup.py`` and *unset* if an environment variable -# named ``GRAPHITE_NO_PREFIX`` is present. -# While ``setup.cfg`` doesn't contain the prefix anymore, the *unset* step is -# required for installations from a source tarball because running -# ``python setup.py sdist`` will re-add the prefix to the tarball's -# ``setup.cfg``. -cf = ConfigParser() - -with open('setup.cfg', 'r') as f: - orig_setup_cfg = f.read() - f.seek(0) - cf.readfp(f, 'setup.cfg') - -if os.environ.get('GRAPHITE_NO_PREFIX'): - cf.remove_section('install') -else: - print('#' * 80) - print('') - print('Carbon\'s default installation prefix is "/opt/graphite".') - print('') - print('To install Carbon in the Python\'s default location run:') - print('$ GRAPHITE_NO_PREFIX=True python setup.py install') - print('') - print('#' * 80) - try: - cf.add_section('install') - except DuplicateSectionError: - pass - if not cf.has_option('install', 'prefix'): - cf.set('install', 'prefix', '/opt/graphite') - if not cf.has_option('install', 'install-lib'): - cf.set('install', 'install-lib', '%(prefix)s/lib') +from setuptools import setup -with open('setup.cfg', 'w') as f: - cf.write(f) - -if os.environ.get('USE_SETUPTOOLS'): - from setuptools import setup - setup_kwargs = dict(zip_safe=0) -else: - from distutils.core import setup - setup_kwargs = dict() - - -storage_dirs = [ ('storage/ceres/dummy.txt', []), ('storage/whisper/dummy.txt',[]), - ('storage/lists',[]), ('storage/log/dummy.txt',[]), - ('storage/rrd/dummy.txt',[]) ] -conf_files = [ ('conf', glob('conf/*.example')) ] +storage_dirs = [('storage/ceres/dummy.txt', []), ('storage/whisper/dummy.txt', []), + ('storage/lists', []), ('storage/log/dummy.txt', []), + ('storage/rrd/dummy.txt', [])] +conf_files = [('conf', glob('conf/*.example'))] install_files = storage_dirs + conf_files # Let's include redhat init scripts, despite build platform # but won't put them in /etc/init.d/ automatically anymore -init_scripts = [ ('examples/init.d', ['distro/redhat/init.d/carbon-cache', - 'distro/redhat/init.d/carbon-relay', - 'distro/redhat/init.d/carbon-aggregator']) ] +init_scripts = [('examples/init.d', ['distro/redhat/init.d/carbon-cache', + 'distro/redhat/init.d/carbon-relay', + 'distro/redhat/init.d/carbon-aggregator'])] install_files += init_scripts + def read(fname): with open(os.path.join(os.path.dirname(__file__), fname)) as f: return f.read() -try: - setup( - name='carbon', - version='1.2.0', - url='http://graphiteapp.org/', - author='Chris Davis', - author_email='chrismd@gmail.com', - license='Apache Software License 2.0', - description='Backend data caching and persistence daemon for Graphite', - long_description=read('README.md'), - long_description_content_type='text/markdown', - packages=['carbon', 'carbon.aggregator', 'twisted.plugins'], - package_dir={'' : 'lib'}, - scripts=glob('bin/*'), - package_data={ 'carbon' : ['*.xml'] }, - data_files=install_files, - install_requires=['Twisted', 'txAMQP', 'cachetools', 'urllib3'], - classifiers=( - 'Intended Audience :: Developers', - 'Natural Language :: English', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - ), - **setup_kwargs - ) -finally: - with open('setup.cfg', 'w') as f: - f.write(orig_setup_cfg) + +setup( + name='carbon', + version='1.2.0', + url='http://graphiteapp.org/', + author='Chris Davis', + author_email='chrismd@gmail.com', + license='Apache Software License 2.0', + description='Backend data caching and persistence daemon for Graphite', + long_description=read('README.md'), + long_description_content_type='text/markdown', + packages=['carbon', 'carbon.aggregator', 'twisted.plugins'], + package_dir={'': 'lib'}, + scripts=glob('bin/*'), + package_data={'carbon': ['*.xml']}, + data_files=install_files, + install_requires=['Twisted', 'txAMQP', 'cachetools', 'urllib3'], + classifiers=( + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'License :: OSI Approved :: Apache Software License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + ), + zip_safe=False +) From 8982e0ac1a56b7ba60af6398e2ba76b879aba580 Mon Sep 17 00:00:00 2001 From: Piotr Date: Thu, 31 Jan 2019 14:32:36 +0100 Subject: [PATCH 2/8] setup.py: make classifiers a list Warning: 'classifiers' should be a list, got type 'tuple' --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 75fe949a3..8a39ba9a4 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ def read(fname): package_data={'carbon': ['*.xml']}, data_files=install_files, install_requires=['Twisted', 'txAMQP', 'cachetools', 'urllib3'], - classifiers=( + classifiers=[ 'Intended Audience :: Developers', 'Natural Language :: English', 'License :: OSI Approved :: Apache Software License', @@ -55,6 +55,6 @@ def read(fname): 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', - ), + ], zip_safe=False ) From ca40f75f77350f28ca2ffe2131d31600adf68bb2 Mon Sep 17 00:00:00 2001 From: Piotr Date: Sun, 3 Feb 2019 20:29:54 +0100 Subject: [PATCH 3/8] Remove manipulation of paths and environments fallback to sys.prefix if GRAPHITE_ROOT is not set, instead of the directory above the location where the binaries are installed. --- .gitignore | 2 ++ bin/carbon-aggregator-cache.py | 12 ------------ bin/carbon-aggregator.py | 12 ------------ bin/carbon-cache.py | 12 ------------ bin/carbon-client.py | 12 ++---------- bin/carbon-relay.py | 12 ------------ lib/carbon/conf.py | 3 +-- lib/carbon/tests/test_conf.py | 13 ------------- lib/carbon/util.py | 6 +----- 9 files changed, 6 insertions(+), 78 deletions(-) diff --git a/.gitignore b/.gitignore index 8b1d83fdc..d1f93f612 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ storage _trial_temp htmlcov *.swp +lib/twisted/plugins/dropin.cache +lib/carbon.egg-info/ diff --git a/bin/carbon-aggregator-cache.py b/bin/carbon-aggregator-cache.py index 3293af610..3346dfba2 100755 --- a/bin/carbon-aggregator-cache.py +++ b/bin/carbon-aggregator-cache.py @@ -13,18 +13,6 @@ See the License for the specific language governing permissions and limitations under the License.""" -import sys -import os.path - -# Figure out where we're installed -BIN_DIR = os.path.dirname(os.path.abspath(__file__)) -ROOT_DIR = os.path.dirname(BIN_DIR) - -# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from -# source. -LIB_DIR = os.path.join(ROOT_DIR, "lib") -sys.path.insert(0, LIB_DIR) - from carbon.util import run_twistd_plugin # noqa from carbon.exceptions import CarbonConfigException # noqa diff --git a/bin/carbon-aggregator.py b/bin/carbon-aggregator.py index 3293af610..3346dfba2 100755 --- a/bin/carbon-aggregator.py +++ b/bin/carbon-aggregator.py @@ -13,18 +13,6 @@ See the License for the specific language governing permissions and limitations under the License.""" -import sys -import os.path - -# Figure out where we're installed -BIN_DIR = os.path.dirname(os.path.abspath(__file__)) -ROOT_DIR = os.path.dirname(BIN_DIR) - -# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from -# source. -LIB_DIR = os.path.join(ROOT_DIR, "lib") -sys.path.insert(0, LIB_DIR) - from carbon.util import run_twistd_plugin # noqa from carbon.exceptions import CarbonConfigException # noqa diff --git a/bin/carbon-cache.py b/bin/carbon-cache.py index 3293af610..3346dfba2 100755 --- a/bin/carbon-cache.py +++ b/bin/carbon-cache.py @@ -13,18 +13,6 @@ See the License for the specific language governing permissions and limitations under the License.""" -import sys -import os.path - -# Figure out where we're installed -BIN_DIR = os.path.dirname(os.path.abspath(__file__)) -ROOT_DIR = os.path.dirname(BIN_DIR) - -# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from -# source. -LIB_DIR = os.path.join(ROOT_DIR, "lib") -sys.path.insert(0, LIB_DIR) - from carbon.util import run_twistd_plugin # noqa from carbon.exceptions import CarbonConfigException # noqa diff --git a/bin/carbon-client.py b/bin/carbon-client.py index 05163480d..f3aa0583d 100755 --- a/bin/carbon-client.py +++ b/bin/carbon-client.py @@ -14,20 +14,12 @@ limitations under the License.""" import sys -from os.path import dirname, join, abspath, exists +from os.path import join, exists from optparse import OptionParser -# Figure out where we're installed -BIN_DIR = dirname(abspath(__file__)) -ROOT_DIR = dirname(BIN_DIR) -CONF_DIR = join(ROOT_DIR, 'conf') +CONF_DIR = join(sys.prefix, 'conf') default_relayrules = join(CONF_DIR, 'relay-rules.conf') -# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from -# source. -LIB_DIR = join(ROOT_DIR, 'lib') -sys.path.insert(0, LIB_DIR) - try: from twisted.internet import epollreactor epollreactor.install() diff --git a/bin/carbon-relay.py b/bin/carbon-relay.py index 3293af610..3346dfba2 100755 --- a/bin/carbon-relay.py +++ b/bin/carbon-relay.py @@ -13,18 +13,6 @@ See the License for the specific language governing permissions and limitations under the License.""" -import sys -import os.path - -# Figure out where we're installed -BIN_DIR = os.path.dirname(os.path.abspath(__file__)) -ROOT_DIR = os.path.dirname(BIN_DIR) - -# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from -# source. -LIB_DIR = os.path.join(ROOT_DIR, "lib") -sys.path.insert(0, LIB_DIR) - from carbon.util import run_twistd_plugin # noqa from carbon.exceptions import CarbonConfigException # noqa diff --git a/lib/carbon/conf.py b/lib/carbon/conf.py index 7082ad178..891fc5ac2 100644 --- a/lib/carbon/conf.py +++ b/lib/carbon/conf.py @@ -583,8 +583,7 @@ def read_config(program, options, **kwargs): if graphite_root is None: graphite_root = os.environ.get('GRAPHITE_ROOT') if graphite_root is None: - raise CarbonConfigException("Either ROOT_DIR or GRAPHITE_ROOT " - "needs to be provided.") + graphite_root = sys.prefix # Default config directory to root-relative, unless overriden by the # 'GRAPHITE_CONF_DIR' environment variable. diff --git a/lib/carbon/tests/test_conf.py b/lib/carbon/tests/test_conf.py index 8449d3b90..6c50b5b6f 100644 --- a/lib/carbon/tests/test_conf.py +++ b/lib/carbon/tests/test_conf.py @@ -5,7 +5,6 @@ from os.path import dirname, join from unittest import TestCase from carbon.conf import get_default_parser, parse_options, read_config -from carbon.exceptions import CarbonConfigException class FakeParser(object): @@ -101,18 +100,6 @@ def makeFile(self, content=None, basename=None, dirname=None): return path - def test_root_dir_is_required(self): - """ - At minimum, the caller must provide a 'ROOT_DIR' setting. - """ - try: - read_config("carbon-foo", FakeOptions(config=None)) - except CarbonConfigException as e: - self.assertEqual("Either ROOT_DIR or GRAPHITE_ROOT " - "needs to be provided.", str(e)) - else: - self.fail("Did not raise exception.") - def test_config_is_not_required(self): """ If the '--config' option is not provided, it defaults to diff --git a/lib/carbon/util.py b/lib/carbon/util.py index 1b5bd5938..5c10d4cf1 100644 --- a/lib/carbon/util.py +++ b/lib/carbon/util.py @@ -9,7 +9,7 @@ import __builtin__ from hashlib import sha256 -from os.path import abspath, basename, dirname +from os.path import basename import socket from time import sleep, time from twisted.python.util import initgroups @@ -71,10 +71,6 @@ def run_twistd_plugin(filename): from carbon.conf import get_parser from twisted.scripts.twistd import ServerOptions - bin_dir = dirname(abspath(filename)) - root_dir = dirname(bin_dir) - os.environ.setdefault('GRAPHITE_ROOT', root_dir) - program = basename(filename).split('.')[0] # First, parse command line options as the legacy carbon scripts used to From 74a0f938c012dba37bf1244ff8eb1faa0f651b62 Mon Sep 17 00:00:00 2001 From: Piotr Date: Fri, 24 Apr 2020 21:15:08 +0200 Subject: [PATCH 4/8] remove duplicate entry in .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9ff07f70b..b5b15c856 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ storage _trial_temp htmlcov *.swp -lib/twisted/plugins/dropin.cache .eggs/ *.egg-info/ lib/twisted/plugins/dropin.cache From 05b9ce9ae8c786b04bc69c0de130c78abe9cc221 Mon Sep 17 00:00:00 2001 From: Piotr Date: Fri, 24 Apr 2020 22:47:19 +0200 Subject: [PATCH 5/8] restore graphite_root to /opt/graphite --- bin/carbon-client.py | 5 ++--- lib/carbon/conf.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/carbon-client.py b/bin/carbon-client.py index f3aa0583d..085ae8080 100755 --- a/bin/carbon-client.py +++ b/bin/carbon-client.py @@ -17,9 +17,6 @@ from os.path import join, exists from optparse import OptionParser -CONF_DIR = join(sys.prefix, 'conf') -default_relayrules = join(CONF_DIR, 'relay-rules.conf') - try: from twisted.internet import epollreactor epollreactor.install() @@ -32,6 +29,8 @@ from carbon.client import CarbonClientManager # noqa from carbon import log, events # noqa +CONF_DIR = join(sys.prefix, 'conf') +default_relayrules = join('/opt/graphite', 'relay-rules.conf') option_parser = OptionParser(usage="%prog [options] ...") option_parser.add_option('--debug', action='store_true', help="Log debug info to stdout") diff --git a/lib/carbon/conf.py b/lib/carbon/conf.py index 88d79e10e..3035d1b9d 100644 --- a/lib/carbon/conf.py +++ b/lib/carbon/conf.py @@ -603,7 +603,7 @@ def read_config(program, options, **kwargs): if graphite_root is None: graphite_root = os.environ.get('GRAPHITE_ROOT') if graphite_root is None: - graphite_root = sys.prefix + graphite_root = '/opt/graphite' # Default config directory to root-relative, unless overriden by the # 'GRAPHITE_CONF_DIR' environment variable. From 02202578fc167c4ac67b90d5adcc205930b36f35 Mon Sep 17 00:00:00 2001 From: Piotr Date: Fri, 24 Apr 2020 22:50:50 +0200 Subject: [PATCH 6/8] Don't install sys-v initscripts --- setup.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 7e6564fda..92ef3f638 100644 --- a/setup.py +++ b/setup.py @@ -12,18 +12,12 @@ install_files = storage_dirs + conf_files -# Let's include redhat init scripts, despite build platform -# but won't put them in /etc/init.d/ automatically anymore -init_scripts = [('examples/init.d', ['distro/redhat/init.d/carbon-cache', - 'distro/redhat/init.d/carbon-relay', - 'distro/redhat/init.d/carbon-aggregator'])] -install_files += init_scripts - def read(fname): with open(os.path.join(os.path.dirname(__file__), fname)) as f: return f.read() + setup( name='carbon', version='1.2.0', From 402e1159743447f180bba13817bdb1448e8f4db3 Mon Sep 17 00:00:00 2001 From: Piotr Date: Sat, 25 Apr 2020 11:16:09 +0200 Subject: [PATCH 7/8] remove unused variable --- bin/carbon-client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/carbon-client.py b/bin/carbon-client.py index 085ae8080..933f914e3 100755 --- a/bin/carbon-client.py +++ b/bin/carbon-client.py @@ -29,7 +29,6 @@ from carbon.client import CarbonClientManager # noqa from carbon import log, events # noqa -CONF_DIR = join(sys.prefix, 'conf') default_relayrules = join('/opt/graphite', 'relay-rules.conf') option_parser = OptionParser(usage="%prog [options] ...") From 7eb8ced438c0187d2017c2947d65974491a2241c Mon Sep 17 00:00:00 2001 From: Piotr Date: Sat, 25 Apr 2020 11:59:38 +0200 Subject: [PATCH 8/8] remove unused import --- bin/carbon-client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/carbon-client.py b/bin/carbon-client.py index 933f914e3..8bf3a5dc4 100755 --- a/bin/carbon-client.py +++ b/bin/carbon-client.py @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License.""" -import sys from os.path import join, exists from optparse import OptionParser