From 9f9b0a02b4e66fa3f7b750b9d2dd9e0fadf46ad9 Mon Sep 17 00:00:00 2001 From: Piotr Date: Sun, 3 Feb 2019 20:29:54 +0100 Subject: [PATCH] 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 | 2 ++ lib/carbon/util.py | 6 +----- 8 files changed, 7 insertions(+), 63 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..c672fb105 100644 --- a/lib/carbon/conf.py +++ b/lib/carbon/conf.py @@ -582,6 +582,8 @@ def read_config(program, options, **kwargs): graphite_root = kwargs.get("ROOT_DIR") if graphite_root is None: graphite_root = os.environ.get('GRAPHITE_ROOT') + if graphite_root is None: + graphite_root = sys.prefix if graphite_root is None: raise CarbonConfigException("Either ROOT_DIR or GRAPHITE_ROOT " "needs to be provided.") 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