Skip to content

Commit

Permalink
Remove manipulation of paths and environments
Browse files Browse the repository at this point in the history
fallback to sys.prefix if GRAPHITE_ROOT is not set, instead of the directory above
the location where the binaries are installed.
  • Loading branch information
piotr1212 committed Feb 3, 2019
1 parent 8982e0a commit ca40f75
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ storage
_trial_temp
htmlcov
*.swp
lib/twisted/plugins/dropin.cache
lib/carbon.egg-info/
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
12 changes: 2 additions & 10 deletions bin/carbon-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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 @@ -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.
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

0 comments on commit ca40f75

Please sign in to comment.