-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file is the center of --green-mode and contains the underlying core of this mode of coala-quickstart. * green_mode(): The master method which calls all the underlying methods in this file and many others. Some broad actions that it performs: * Creates `.project_data.yaml` to store the directory and file structure of the project, deletes it in the end. Further commits may change this behaviour and add code to reuse this data generated. * Calls the QuickstartBear to traverse the file_dict and guess some setting values on its own. * Calls the methods to provide some other information about settings of some bears which can't be detected by traversing the file_dict eg. settings based on the names of files. * Calls the methods to test each bear for each file for all the values for each setting until a green setting is found for a bear. * Will call the methods to create section object and write `.coafile` in further commits. * bear_test_fun(): Calls the methods to get all possible combinations of values to bear settings and supply these to other underlying methods to test them for each bear. * run_test_on_each_bear(): Prints a message about which bear, the tests are running on and calls local_bear_test() or global_bear_test() depending on the type of bear to guess the green setting values from the combination of all values. * local_bear_test(), global_bear_test(): Run coala repetitively on the bear in a multiprocessing environment and return the green settings found. * check_bear_results(): Checks whether the result objects returned by the bear are 0 or if they lie in the ignore scope of the code to testify whether the current bear settings are green. * get_kwargs(): Produces combinations of all setting values for the bears which are given one by one to the bear to run upon. * get_setting_type(): Detects the type of a bear argument, i.e. whether it accepts boolean values or something like int which falls under the category of infinite set of values, whether some setting requires a config file of a specific linter or whether an argument accepts some discrete set of values. * run_quickstartbear(): Runs QuickstartBear to guess some setting values from the file_dict and write the results to `.project_data.yaml`. * find_min_of_setting()/find_max_of_setting(): Are helper functions for bear settings that run in coordination with per file results of QuickstartBear to get the project minima/maxima value of that particular setting. * generate_complete_filename_list(): From the file/directory structure written to the `.project_data.yaml` gets only the list of files. * initialize_project_data(): Initializes the `.project_data.yaml` by writing to the file/directory structure of the project with file names as items of a list but directories as dicts again as sub items of a list. * Some other helper methods for some basic operations are also created. Apart from the changes to green_mode.py a method that is added to Utilities.py is: contained_in(): Detects whether the first argument which must be a SourceRange object is contained absolutely inside the other SourceRange object with closed boundaries. Tests are added for each method except the final green_mode() method. coala_quickstart.py: The arguments: * MAX_NUM_OF_OPTIONAL_ARGS_ALLOWED_FOR_GREEN_MODE * MAX_NUM_OF_VALUES_OF_OPTIONAL_ARGS_ALLOWED_FOR_GREEN_MODE are introduced.
- Loading branch information
Showing
14 changed files
with
1,198 additions
and
3 deletions.
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,68 @@ | ||
settings_key = 'green_mode_infinite_value_settings' | ||
|
||
|
||
def find_max_of_setting(setting, value, contents): | ||
""" | ||
Generates 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 max value of. | ||
:param value: | ||
The current value to be compared against the | ||
supposedly max value stored in contents. | ||
:param contents: | ||
The python object to be written to 'PROJECT_DATA' | ||
which contains the max value of the setting which was | ||
encountered uptil now. | ||
:return: | ||
The contents with the max value of the setting encountered | ||
uptil now after comparing it with the current value recieved | ||
by the function. | ||
""" | ||
found = False | ||
position = None | ||
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 value > current_val: | ||
contents[settings_key][position][setting] = value | ||
return contents | ||
|
||
|
||
def find_min_of_setting(setting, value, contents): | ||
""" | ||
Generates min 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. | ||
: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 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
Oops, something went wrong.