-
Notifications
You must be signed in to change notification settings - Fork 76
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
Tillgreenmodecore #288
Merged
Merged
Tillgreenmodecore #288
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
settings_key = 'green_mode_infinite_value_settings' | ||
|
||
|
||
def find_max_min_of_setting(setting, value, contents, operator): | ||
""" | ||
Generates min/max value of a setting where this | ||
function is called upon for every value generated for | ||
every file in the project (excluding ignored files). | ||
:param setting: | ||
The setting for which to find the min value of. | ||
:param value: | ||
The current value to be compared against the | ||
supposedly min value stored in contents. | ||
:param contents: | ||
The python object to be written to 'PROJECT_DATA' | ||
which contains the min value of the setting which was | ||
encountered uptil now. | ||
:param operator: | ||
Either the less than or greater than operator. | ||
:return: | ||
The contents with the min value of the setting encountered | ||
uptil now after comparing it with the current value recieved | ||
by the function. | ||
""" | ||
found = False | ||
for index, item in enumerate(contents[settings_key]): | ||
if isinstance(item, dict) and setting in item: | ||
found = True | ||
position = index | ||
if not found: | ||
contents[settings_key].append({setting: value}) | ||
return contents | ||
current_val = contents[settings_key][position][setting] | ||
if operator(value, current_val): | ||
contents[settings_key][position][setting] = value | ||
return contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import os | ||
from copy import deepcopy | ||
|
||
from coala_quickstart.generation.Utilities import ( | ||
append_to_contents, | ||
) | ||
from coala_quickstart.green_mode.green_mode import ( | ||
settings_key, | ||
) | ||
|
||
|
||
class Node: | ||
def __init__(self, character, parent=None): | ||
self.count = 1 | ||
self.character = character | ||
self.children = {} | ||
self.parent = parent | ||
|
||
def insert(self, string, idx): | ||
if idx >= len(string): | ||
return | ||
code = ord(string[idx]) # ASCII code | ||
ch = string[idx] | ||
if ch in self.children: | ||
self.children[ch].count += 1 | ||
else: | ||
self.children[ch] = Node(string[idx], self) | ||
self.children[ch].insert(string, idx + 1) | ||
|
||
|
||
class Trie: | ||
""" | ||
Creates a Trie data structure for storing names of files. | ||
""" | ||
|
||
def __init__(self): | ||
self.root = Node('') | ||
|
||
def insert(self, string): | ||
self.root.insert(string, 0) | ||
|
||
# Just a wrapper function. | ||
def get_prefixes(self, min_length, min_files): | ||
""" | ||
Discovers prefix from the Trie. Prefix shorter than the | ||
min_length or matching against files lesser than the | ||
min_files are not stored. Returns the prefixes in sorted | ||
order. | ||
""" | ||
self.prefixes = {} | ||
self._discover_prefixes(self.root, [], min_length, 0, min_files) | ||
return sorted(self.prefixes.items(), key=lambda x: (x[1], x[0]), | ||
reverse=True) | ||
|
||
def _discover_prefixes(self, node, prefix, min_length, len, min_files): | ||
""" | ||
Performs a DFA search on the trie. Discovers the prefixes in the trie | ||
and stores them in the self.prefixes dictionary. | ||
""" | ||
if node.count < min_files and node.character != '': | ||
return | ||
if len >= min_length: | ||
current_prefix = ''.join(prefix) + node.character | ||
to_delete = [] | ||
for i in self.prefixes: | ||
if i in current_prefix: | ||
to_delete.append(i) | ||
for i in to_delete: | ||
self.prefixes.pop(i) | ||
self.prefixes[''.join(prefix) + node.character] = node.count | ||
orig_prefix = deepcopy(prefix) | ||
for ch, ch_node in node.children.items(): | ||
prefix.append(node.character) | ||
if (not ch_node.count < node.count) or orig_prefix == []: | ||
self._discover_prefixes(ch_node, prefix, min_length, len + 1, | ||
min_files) | ||
prefix.pop() | ||
|
||
|
||
def get_files_list(contents): | ||
""" | ||
Generates a list which contains only files from | ||
the entire project from the directory and file | ||
structure written to '.project_data.yaml'. | ||
:param contents: | ||
The python object containing the file and | ||
directory structure written to '.project_data.yaml'. | ||
:return: | ||
The list of all the files in the project. | ||
""" | ||
file_names_list = [] | ||
for item in contents: | ||
if not isinstance(item, dict): | ||
file_names_list.append(item) | ||
else: | ||
file_names_list += get_files_list( | ||
item[next(iter(item))]) | ||
return file_names_list | ||
|
||
|
||
def check_filename_prefix_postfix(contents, min_length_of_prefix=6, | ||
min_files_for_prefix=5): | ||
""" | ||
Checks whether the project has some files with filenames | ||
having certain prefix or postfix. | ||
:param contents: | ||
The python object containing the file and | ||
directory structure written to '.project_data.yaml'. | ||
:param min_length_of_prefix: | ||
The minimum length of prefix for it green_mode to | ||
consider as a valid prefix. | ||
:param min_files_for_prefix: | ||
The minimum amount of files a prefix to match against | ||
for green_mode to consider it as a valid prefix. | ||
:return: | ||
Update contents value with the results found out | ||
from the file/directory structure in .project_data.yaml. | ||
""" | ||
file_names_list = get_files_list(contents['dir_structure']) | ||
file_names_list = [os.path.splitext(os.path.basename(x))[ | ||
0] for x in file_names_list] | ||
file_names_list_reverse = [os.path.splitext( | ||
x)[0][::-1] for x in file_names_list] | ||
trie = Trie() | ||
for file in file_names_list: | ||
trie.insert(file) | ||
prefixes = trie.get_prefixes(min_length_of_prefix, min_files_for_prefix) | ||
trie_reverse = Trie() | ||
for file in file_names_list_reverse: | ||
trie_reverse.insert(file) | ||
suffixes = trie_reverse.get_prefixes( | ||
min_length_of_prefix, min_files_for_prefix) | ||
if len(suffixes) == 0: | ||
suffixes = [('', 0)] | ||
if len(prefixes) == 0: | ||
prefixes = [('', 0)] | ||
prefix_list, suffix_list = [], [] | ||
for prefix, freq in prefixes: | ||
prefix_list.append(prefix) | ||
for suffix, freq in suffixes: | ||
suffix_list.append(suffix[::-1]) | ||
contents = append_to_contents(contents, 'filename_prefix', prefix_list, | ||
settings_key) | ||
contents = append_to_contents(contents, 'filename_suffix', suffix_list, | ||
settings_key) | ||
|
||
return contents |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entire core is excluded from coverage??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no its just the master function which calls other functions. Each individual method is tested with 100% coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it needed too many mocks of methods like
os.walk()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80 lines ... fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recheck #274 & #273 above, and
INFO_SETTING_MAPS =
below, and maybe others below also which were your code that wasnt covered.on a separate branch, try removing those rules and see what the coverage looks like. Maybe it has increased in those areas to the point that a little effort will make those rules redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response at https://gitter.im/coala/coala-bears?at=5b6f97f4937eee24230624ae