Skip to content

Commit a355433

Browse files
committed
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.
1 parent 8982e0a commit a355433

File tree

9 files changed

+6
-77
lines changed

9 files changed

+6
-77
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ storage
1414
_trial_temp
1515
htmlcov
1616
*.swp
17+
lib/twisted/plugins/dropin.cache
18+
lib/carbon.egg-info/

bin/carbon-aggregator-cache.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License."""
1515

16-
import sys
17-
import os.path
18-
19-
# Figure out where we're installed
20-
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
21-
ROOT_DIR = os.path.dirname(BIN_DIR)
22-
23-
# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from
24-
# source.
25-
LIB_DIR = os.path.join(ROOT_DIR, "lib")
26-
sys.path.insert(0, LIB_DIR)
27-
2816
from carbon.util import run_twistd_plugin # noqa
2917
from carbon.exceptions import CarbonConfigException # noqa
3018

bin/carbon-aggregator.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License."""
1515

16-
import sys
17-
import os.path
18-
19-
# Figure out where we're installed
20-
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
21-
ROOT_DIR = os.path.dirname(BIN_DIR)
22-
23-
# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from
24-
# source.
25-
LIB_DIR = os.path.join(ROOT_DIR, "lib")
26-
sys.path.insert(0, LIB_DIR)
27-
2816
from carbon.util import run_twistd_plugin # noqa
2917
from carbon.exceptions import CarbonConfigException # noqa
3018

bin/carbon-cache.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License."""
1515

16-
import sys
17-
import os.path
18-
19-
# Figure out where we're installed
20-
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
21-
ROOT_DIR = os.path.dirname(BIN_DIR)
22-
23-
# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from
24-
# source.
25-
LIB_DIR = os.path.join(ROOT_DIR, "lib")
26-
sys.path.insert(0, LIB_DIR)
27-
2816
from carbon.util import run_twistd_plugin # noqa
2917
from carbon.exceptions import CarbonConfigException # noqa
3018

bin/carbon-client.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@
1414
limitations under the License."""
1515

1616
import sys
17-
from os.path import dirname, join, abspath, exists
17+
from os.path import join, exists
1818
from optparse import OptionParser
1919

20-
# Figure out where we're installed
21-
BIN_DIR = dirname(abspath(__file__))
22-
ROOT_DIR = dirname(BIN_DIR)
23-
CONF_DIR = join(ROOT_DIR, 'conf')
20+
CONF_DIR = join(sys.prefix, 'conf')
2421
default_relayrules = join(CONF_DIR, 'relay-rules.conf')
2522

26-
# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from
27-
# source.
28-
LIB_DIR = join(ROOT_DIR, 'lib')
29-
sys.path.insert(0, LIB_DIR)
30-
3123
try:
3224
from twisted.internet import epollreactor
3325
epollreactor.install()

bin/carbon-relay.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License."""
1515

16-
import sys
17-
import os.path
18-
19-
# Figure out where we're installed
20-
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
21-
ROOT_DIR = os.path.dirname(BIN_DIR)
22-
23-
# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from
24-
# source.
25-
LIB_DIR = os.path.join(ROOT_DIR, "lib")
26-
sys.path.insert(0, LIB_DIR)
27-
2816
from carbon.util import run_twistd_plugin # noqa
2917
from carbon.exceptions import CarbonConfigException # noqa
3018

lib/carbon/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@ def read_config(program, options, **kwargs):
583583
if graphite_root is None:
584584
graphite_root = os.environ.get('GRAPHITE_ROOT')
585585
if graphite_root is None:
586-
raise CarbonConfigException("Either ROOT_DIR or GRAPHITE_ROOT "
587-
"needs to be provided.")
586+
graphite_root = sys.prefix
588587

589588
# Default config directory to root-relative, unless overriden by the
590589
# 'GRAPHITE_CONF_DIR' environment variable.

lib/carbon/tests/test_conf.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,6 @@ def makeFile(self, content=None, basename=None, dirname=None):
101101

102102
return path
103103

104-
def test_root_dir_is_required(self):
105-
"""
106-
At minimum, the caller must provide a 'ROOT_DIR' setting.
107-
"""
108-
try:
109-
read_config("carbon-foo", FakeOptions(config=None))
110-
except CarbonConfigException as e:
111-
self.assertEqual("Either ROOT_DIR or GRAPHITE_ROOT "
112-
"needs to be provided.", str(e))
113-
else:
114-
self.fail("Did not raise exception.")
115-
116104
def test_config_is_not_required(self):
117105
"""
118106
If the '--config' option is not provided, it defaults to

lib/carbon/util.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import __builtin__
1010

1111
from hashlib import sha256
12-
from os.path import abspath, basename, dirname
12+
from os.path import basename
1313
import socket
1414
from time import sleep, time
1515
from twisted.python.util import initgroups
@@ -71,10 +71,6 @@ def run_twistd_plugin(filename):
7171
from carbon.conf import get_parser
7272
from twisted.scripts.twistd import ServerOptions
7373

74-
bin_dir = dirname(abspath(filename))
75-
root_dir = dirname(bin_dir)
76-
os.environ.setdefault('GRAPHITE_ROOT', root_dir)
77-
7874
program = basename(filename).split('.')[0]
7975

8076
# First, parse command line options as the legacy carbon scripts used to

0 commit comments

Comments
 (0)