Skip to content

Commit

Permalink
flake8: re-enable E111,E114 (4-space indent) for most files
Browse files Browse the repository at this point in the history
skip the biggest offenders for now:

      76 ./webapp/tests/test_tags.py
      87 ./webapp/graphite/render/evaluator.py
     103 ./webapp/graphite/browser/views.py
     111 ./webapp/graphite/render/datalib.py
     116 ./webapp/graphite/util.py
     126 ./webapp/tests/test_storage.py
     136 ./webapp/tests/test_finders_remote.py
     142 ./webapp/graphite/dashboard/views.py
     161 ./webapp/graphite/metrics/views.py
     213 ./webapp/tests/test_render_datalib.py
     238 ./webapp/graphite/render/views.py
     261 ./contrib/memcache_whisper.py
     443 ./webapp/tests/test_render_glyph.py
     645 ./webapp/graphite/render/glyph.py
    1110 ./webapp/graphite/render/functions.py

also set changedir for flake8 so per-file ignore paths work
  • Loading branch information
ploxiln committed Apr 12, 2020
1 parent e6f216a commit 7a1b6c5
Show file tree
Hide file tree
Showing 63 changed files with 2,947 additions and 2,903 deletions.
12 changes: 6 additions & 6 deletions bin/run-graphite-devel-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
(options, args) = option_parser.parse_args()

if not args:
option_parser.print_usage()
sys.exit(1)
option_parser.print_usage()
sys.exit(1)

graphite_root = args[0]

python_path = os.path.join(graphite_root, 'webapp')

if options.libs:
libdir = os.path.expanduser(options.libs)
print('Adding %s to your PYTHONPATH' % libdir)
os.environ['PYTHONPATH'] = libdir + ':' + os.environ.get('PYTHONPATH','')
libdir = os.path.expanduser(options.libs)
print('Adding %s to your PYTHONPATH' % libdir)
os.environ['PYTHONPATH'] = libdir + ':' + os.environ.get('PYTHONPATH','')

print("Running Graphite from %s under django development server\n" % graphite_root)

Expand All @@ -40,7 +40,7 @@
]

if options.noreload:
command.append('--noreload')
command.append('--noreload')

print(' '.join(command))

Expand Down
146 changes: 82 additions & 64 deletions check-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,131 +3,149 @@
import sys

if sys.version_info <= (2,7):
# SystemExit defaults to returning 1 when printing a string to stderr
raise SystemExit("You are using python %s, but version 2.7 or greater is "
"required" % sys.version_info)
# SystemExit defaults to returning 1 when printing a string to stderr
raise SystemExit("You are using python %s, but version 2.7 or greater is "
"required" % sys.version_info)

required = 0
optional = 0


# Test for whisper
try:
import whisper
import whisper
except ImportError:
# No? test for ceres
try:
import ceres
# We imported ceres, but not whisper so it's an optional dependency
sys.stderr.write("[OPTIONAL] Unable to import the 'whisper' module. Without it the webapp will be unable to read .wsp files\n")
optional += 1
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'whisper' or 'ceres' modules, please download this package from the Graphite project page and install it.\n")
required += 1
# No? test for ceres
try:
import ceres
# We imported ceres, but not whisper so it's an optional dependency
sys.stderr.write("[OPTIONAL] Unable to import the 'whisper' module. "
"Without it the webapp will be unable to read .wsp files\n")
optional += 1
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'whisper' or 'ceres' modules, "
"please download this package from the Graphite project page and install it.\n")
required += 1


# Test for cairocffi or pycairo
try:
import cairocffi as cairo
import cairocffi as cairo
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'cairocffi' module, attempting to fall back to pycairo\n")
try:
import cairo
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'cairo' module, do you have pycairo installed for python %s?\n" % sys.version_info.major)
cairo = None
required += 1
sys.stderr.write("[REQUIRED] Unable to import the 'cairocffi' module, attempting to fall back to pycairo\n")
try:
import cairo
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'cairo' module, "
"do you have pycairo installed for python %s?\n" % sys.version_info.major)
cairo = None
required += 1


# Test that pycairo has the PNG backend
try:
if cairo:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
del surface
if cairo:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
del surface
except Exception:
sys.stderr.write("[REQUIRED] Failed to create an ImageSurface with cairo, you probably need to recompile cairo with PNG support\n")
required += 1
sys.stderr.write("[REQUIRED] Failed to create an ImageSurface with cairo, "
"you probably need to recompile cairo with PNG support\n")
required += 1


# Test that cairo can find fonts
try:
if cairo:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
context = cairo.Context(surface)
context.font_extents()
del surface, context
if cairo:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
context = cairo.Context(surface)
context.font_extents()
del surface, context
except Exception:
sys.stderr.write("[REQUIRED] Failed to create text with cairo, this probably means cairo cant find any fonts. Install some system fonts and try again\n")
sys.stderr.write("[REQUIRED] Failed to create text with cairo, "
"this probably means cairo cant find any fonts. "
"Install some system fonts and try again\n")


# Test for django
try:
import django
import django
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'django' module, do you have Django installed for python %s?\n" % sys.version_info.major)
django = None
required += 1
sys.stderr.write("[REQUIRED] Unable to import the 'django' module, "
"do you have Django installed for python %s?\n" % sys.version_info.major)
django = None
required += 1


# Test for pytz
try:
import pytz
import pytz
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'pytz' module, do you have pytz module installed for python %s?\n" % sys.version_info.major)
required += 1
sys.stderr.write("[REQUIRED] Unable to import the 'pytz' module, "
"do you have pytz module installed for python %s?\n" % sys.version_info.major)
required += 1


# Test for pyparsing
try:
import pyparsing
import pyparsing
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'pyparsing' module, do you have pyparsing module installed for python %s?\n" % sys.version_info.major)
required += 1
sys.stderr.write("[REQUIRED] Unable to import the 'pyparsing' module, "
"do you have pyparsing module installed for python %s?\n" % sys.version_info.major)
required += 1


# Test for django-tagging
try:
import tagging
import tagging
except ImportError:
sys.stderr.write("[REQUIRED] Unable to import the 'tagging' module, do you have django-tagging installed for python %s?\n" % sys.version_info.major)
required += 1
sys.stderr.write("[REQUIRED] Unable to import the 'tagging' module, "
"do you have django-tagging installed for python %s?\n" % sys.version_info.major)
required += 1


if django and django.VERSION[:2] < (1,8):
sys.stderr.write("[REQUIRED] You have django version %s installed, but version 1.8 or greater is required\n" % django.get_version())
required += 1
sys.stderr.write("[REQUIRED] You have django version %s installed, "
"but version 1.8 or greater is required\n" % django.get_version())
required += 1


# Test for python-memcached
try:
import memcache
import memcache
except ImportError:
sys.stderr.write("[OPTIONAL] Unable to import the 'memcache' module, do you have python-memcached installed for python %s? This feature is not required but greatly improves performance.\n" % sys.version_info.major)
optional += 1
sys.stderr.write("[OPTIONAL] Unable to import the 'memcache' module, "
"do you have python-memcached installed for python %s? "
"This feature is not required but greatly improves performance.\n" % sys.version_info.major)
optional += 1


# Test for python-ldap
try:
import ldap
import ldap
except ImportError:
sys.stderr.write("[OPTIONAL] Unable to import the 'ldap' module, do you have python-ldap installed for python %s? Without python-ldap, you will not be able to use LDAP authentication in the graphite webapp.\n" % sys.version_info.major)
optional += 1
sys.stderr.write("[OPTIONAL] Unable to import the 'ldap' module, "
"do you have python-ldap installed for python %s? "
"Without python-ldap, you will not be able to use "
"LDAP authentication in the graphite webapp.\n" % sys.version_info.major)
optional += 1


# Test for txamqp
try:
import txamqp
import txamqp
except ImportError:
sys.stderr.write("[OPTIONAL] Unable to import the 'txamqp' module, this is required if you want to use AMQP as an input to Carbon. Note that txamqp requires python 2.5 or greater.\n")
optional += 1
sys.stderr.write("[OPTIONAL] Unable to import the 'txamqp' module, "
"this is required if you want to use AMQP as an input to Carbon. "
"Note that txamqp requires python 2.5 or greater.\n")
optional += 1


# Test for python-rrdtool
try:
import rrdtool
import rrdtool
except ImportError:
sys.stderr.write("[OPTIONAL] Unable to import the 'python-rrdtool' module, this is required for reading RRD.\n")
optional += 1
sys.stderr.write("[OPTIONAL] Unable to import the 'python-rrdtool' module, this is required for reading RRD.\n")
optional += 1


# Test for whitenoise
Expand All @@ -147,15 +165,15 @@


if optional:
sys.stderr.write("%d optional dependencies not met. Please consider the optional items before proceeding.\n" % optional)
sys.stderr.write("%d optional dependencies not met. Please consider the optional items before proceeding.\n" % optional)
else:
print("All optional dependencies are met.")
print("All optional dependencies are met.")

if required:
sys.stderr.write("%d necessary dependencies not met. Graphite will not function until these dependencies are fulfilled.\n" % required)
sys.exit(1)
sys.stderr.write("%d necessary dependencies not met. Graphite will not function until these dependencies are fulfilled.\n" % required)
sys.exit(1)
else:
print("All necessary dependencies are met.")
print("All necessary dependencies are met.")


# suppress unused-import warnings
Expand Down
17 changes: 10 additions & 7 deletions contrib/test_aggregator_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

### Basic usage
if len(sys.argv) != 3:
print("Usage: %s 'aggregator rule' 'line item'" % (__file__))
print("\nSample invocation: %s %s %s" %
(__file__, "'<prefix>.<env>.<key>.sum.all (10) = sum <prefix>.<env>.<<key>>.sum.<node>'", 'stats.prod.js.ktime_sum.sum.host2' ))
sys.exit(42)
print("Usage: %s 'aggregator rule' 'line item'" % (__file__))
print("\nSample invocation: %s %s %s" % (
__file__,
"'<prefix>.<env>.<key>.sum.all (10) = sum <prefix>.<env>.<<key>>.sum.<node>'",
'stats.prod.js.ktime_sum.sum.host2'
))
sys.exit(42)

### cli arguments
me, raw_rule, raw_metric = sys.argv
Expand All @@ -36,8 +39,8 @@

print("Raw metric: %s" % raw_metric)
if match:
print("Match dict: %s" % match.groupdict())
print("Result: %s" % rule.output_template % match.groupdict())
print("Match dict: %s" % match.groupdict())
print("Result: %s" % rule.output_template % match.groupdict())

else:
print("ERROR: NO MATCH")
print("ERROR: NO MATCH")
22 changes: 11 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@
# Define a custom autodoc documenter for the render.functions module
# This will remove the requestContext parameter which doesnt make sense in the context of the docs
class RenderFunctionDocumenter(autodoc.FunctionDocumenter):
priority = 10 # Override FunctionDocumenter
priority = 10 # Override FunctionDocumenter

@classmethod
def can_document_member(cls, member, membername, isattr, parent):
return autodoc.FunctionDocumenter.can_document_member(member, membername, isattr, parent) and \
parent.name == 'graphite.render.functions'
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
return autodoc.FunctionDocumenter.can_document_member(member, membername, isattr, parent) \
and parent.name == 'graphite.render.functions'

def format_args(self):
args = autodoc.FunctionDocumenter.format_args(self)
if args is not None:
# Really, a regex sub here is by far the easiest way
return re.sub('requestContext, ','',args)
def format_args(self):
args = autodoc.FunctionDocumenter.format_args(self)
if args is not None:
# Really, a regex sub here is by far the easiest way
return re.sub('requestContext, ','',args)


def setup(app):
app.add_autodocumenter(RenderFunctionDocumenter)
app.add_autodocumenter(RenderFunctionDocumenter)


# -- General configuration -----------------------------------------------------
Expand Down
58 changes: 30 additions & 28 deletions examples/example-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,43 @@

delay = 60
if len(sys.argv) > 1:
delay = int( sys.argv[1] )
delay = int( sys.argv[1] )


def get_loadavg():
# For more details, "man proc" and "man uptime"
if platform.system() == "Linux":
return open('/proc/loadavg').read().strip().split()[:3]
else:
command = "uptime"
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
os.waitpid(process.pid, 0)
output = process.stdout.read().replace(',', ' ').strip().split()
length = len(output)
return output[length - 3:length]
# For more details, "man proc" and "man uptime"
if platform.system() == "Linux":
return open('/proc/loadavg').read().strip().split()[:3]
else:
command = "uptime"
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
os.waitpid(process.pid, 0)
output = process.stdout.read().replace(',', ' ').strip().split()
length = len(output)
return output[length - 3:length]


sock = socket()
try:
sock.connect( (CARBON_SERVER,CARBON_PORT) )
sock.connect( (CARBON_SERVER,CARBON_PORT) )
except Exception:
print("Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT })
sys.exit(1)
print("Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % {
'server': CARBON_SERVER, 'port': CARBON_PORT
})
sys.exit(1)

while True:
now = int( time.time() )
lines = []
#We're gonna report all three loadavg values
loadavg = get_loadavg()
lines.append("system.loadavg_1min %s %d" % (loadavg[0],now))
lines.append("system.loadavg_5min %s %d" % (loadavg[1],now))
lines.append("system.loadavg_15min %s %d" % (loadavg[2],now))
message = '\n'.join(lines) + '\n' #all lines must end in a newline
print("sending message\n")
print('-' * 80)
print(message)
print()
sock.sendall(message)
time.sleep(delay)
now = int( time.time() )
lines = []
#We're gonna report all three loadavg values
loadavg = get_loadavg()
lines.append("system.loadavg_1min %s %d" % (loadavg[0],now))
lines.append("system.loadavg_5min %s %d" % (loadavg[1],now))
lines.append("system.loadavg_15min %s %d" % (loadavg[2],now))
message = '\n'.join(lines) + '\n' #all lines must end in a newline
print("sending message\n")
print('-' * 80)
print(message)
print()
sock.sendall(message)
time.sleep(delay)
Loading

0 comments on commit 7a1b6c5

Please sign in to comment.