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

Changes all instances of uppercase c to lowercase #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from contextlib import contextmanager, closing


COALA_KEY = "coala-sublime"
coala_key = "coala-sublime"
Copy link
Member

Choose a reason for hiding this comment

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

nooooo ... CONSTANTS should always be capitalised. That is PEP 8.

I suggest giving this constant a different name. APP_NAME ?



def log(*args, **kwargs):
print(" COALA -", *args, **kwargs)
print(" coala -", *args, **kwargs)


@contextmanager
Expand Down
18 changes: 9 additions & 9 deletions CoalaBackground.py → coalaBackground.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import sublime_plugin
import json
from .Utils import log, COALA_KEY
from .Utils import log, coala_key


class CoalaBackground(sublime_plugin.EventListener):
class coalaBackground(sublime_plugin.EventListener):

def on_selection_modified(self, view):
"""
Show errors in the status line when the carret/selection moves.
This assumes that the output from coala are saved in COALA_OUTPUT.
This assumes that the output from coala are saved in coala_OUTPUT.
"""
output_str = view.settings().get(COALA_KEY + ".output_str", "{}")
output_str = view.settings().get(coala_key + ".output_str", "{}")
output = json.loads(output_str)
last_line = view.settings().get(COALA_KEY + ".last_line", -1)
last_line = view.settings().get(coala_key + ".last_line", -1)
if output:
# Get the currently selected line
new_selected_line = view.rowcol(view.sel()[0].end())[0]

if new_selected_line != last_line: # If line has changed
view.settings().set(COALA_KEY + ".last_line", new_selected_line)
view.settings().set(coala_key + ".last_line", new_selected_line)

# Search through results, and show message (if it exists)
found_result_flag = False
Expand All @@ -31,11 +31,11 @@ def on_selection_modified(self, view):
if new_selected_line == line:
msg = (result["origin"] + ": "
+ result["message"])
view.set_status(COALA_KEY, msg)
view.set_status(coala_key, msg)
found_result_flag = True

if view.get_status(COALA_KEY) and not found_result_flag:
view.erase_status(COALA_KEY)
if view.get_status(coala_key) and not found_result_flag:
view.erase_status(coala_key)

def on_post_save(self, view):
"""
Expand Down
14 changes: 7 additions & 7 deletions CoalaCommand.py → coalaCommand.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sublime_plugin
import sublime
import json
from .CoalaThread import CoalaThread
from .Utils import log, COALA_KEY
from .coalaThread import coalaThread
from .Utils import log, coala_key


def show_output(view):
output_str = view.settings().get(COALA_KEY + ".output_str")
output_str = view.settings().get(coala_key + ".output_str")
if not output_str:
return
output = json.loads(output_str)
Expand All @@ -23,12 +23,12 @@ def show_output(view):
view.text_point(code_region["start"]["line"]-1, 0))
regions.append(line)

view.add_regions(COALA_KEY, regions, COALA_KEY, "dot", region_flag)
view.add_regions(coala_key, regions, coala_key, "dot", region_flag)


class CoalaCommand(sublime_plugin.TextCommand):
class coalaCommand(sublime_plugin.TextCommand):
"""
The CoalaCommand inherits the TextCommand from sublime_plugin and can be
The coalaCommand inherits the TextCommand from sublime_plugin and can be
executed using `view.run_command("coala")` - which executes the `run()`
function by default.
"""
Expand All @@ -37,7 +37,7 @@ def run(self, edit, **kwargs):
file_name = self.view.file_name()
log("Trying to run coala on", file_name)
if file_name:
thread = CoalaThread(self.view, show_output)
thread = coalaThread(self.view, show_output)
thread.start()
self.progress_tracker(thread)
else:
Expand Down
14 changes: 7 additions & 7 deletions CoalaThread.py → coalaThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import datetime
import time

from .Utils import log, COALA_KEY
from .Utils import log, coala_key


class CoalaThread(threading.Thread):
class coalaThread(threading.Thread):

def __init__(self,
view,
Expand Down Expand Up @@ -45,15 +45,15 @@ def __init__(self,
threading.Thread.__init__(self)

def run(self):
running = self.view.settings().get(COALA_KEY + ".running", False)
running = self.view.settings().get(coala_key + ".running", False)
now = time.time()
timeout_seconds = datetime.timedelta(minutes=2).total_seconds()
if running and now - running < timeout_seconds:
log("Earler coala thread still running since", running,
"for", now - running)
return

self.view.settings().set(COALA_KEY + ".running", now)
self.view.settings().set(coala_key + ".running", now)
command = ["coala-json"]
options = []

Expand Down Expand Up @@ -94,15 +94,15 @@ def run(self):
else:
log("Exited with:", retval)
stdout_file.close()
self.view.settings().set(COALA_KEY + ".running", False)
self.view.settings().set(coala_key + ".running", False)

def process_output(self, output_str):
view_id = self.view.id()
# Save output to the view's setting - the setting is not common to all
# views, and is only for this view. Save the string as the Hash of
# results cannot be saved by sublime as the int it too large.
self.view.settings().set(COALA_KEY + ".output_str", output_str)
self.view.settings().set(coala_key + ".output_str", output_str)
self.callback(self.view)

def no_output(self):
self.view.erase_regions(COALA_KEY)
self.view.erase_regions(coala_key)
2 changes: 1 addition & 1 deletion tests/UtilsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_retrieve_stdout(self):
def test_log(self):
with retrieve_stdout() as sio:
log("test")
self.assertEqual(sio.getvalue(), " COALA - test\n")
self.assertEqual(sio.getvalue(), " coala - test\n")


if __name__ == '__main__':
Expand Down