Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove /opt/graphite prefix and use setuptools #835

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
12 changes: 0 additions & 12 deletions bin/carbon-aggregator-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 0 additions & 12 deletions bin/carbon-aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 0 additions & 12 deletions bin/carbon-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 3 additions & 12 deletions bin/carbon-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@
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')
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()
Expand All @@ -40,6 +29,8 @@
from carbon.client import CarbonClientManager # noqa
from carbon import log, events # noqa

CONF_DIR = join(sys.prefix, 'conf')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another sys.prefix that should be /opt/graphite?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(actually, this CONF_DIR variable is now unused)

default_relayrules = join('/opt/graphite', 'relay-rules.conf')

option_parser = OptionParser(usage="%prog [options] <host:port:instance> <host:port:instance> ...")
option_parser.add_option('--debug', action='store_true', help="Log debug info to stdout")
Expand Down
12 changes: 0 additions & 12 deletions bin/carbon-relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions lib/carbon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +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:
raise CarbonConfigException("Either ROOT_DIR or GRAPHITE_ROOT "
"needs to be provided.")
graphite_root = '/opt/graphite'

# Default config directory to root-relative, unless overriden by the
# 'GRAPHITE_CONF_DIR' environment variable.
Expand Down
13 changes: 0 additions & 13 deletions lib/carbon/tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions lib/carbon/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
141 changes: 40 additions & 101 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,54 @@
#!/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']) ]
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='[email protected]',
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.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'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='[email protected]',
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 :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
zip_safe=False
)