pyggi.program module¶
This module contains GranularityLevel and Program class.
-
class
pyggi.program.
GranularityLevel
[source]¶ Bases:
enum.Enum
GranularityLevel represents the granularity levels of program.
-
AST
= 'AST'¶
-
LINE
= 'line'¶
-
-
class
pyggi.program.
Program
(path, granularity_level=<GranularityLevel.LINE: 'line'>, config_file_name='PYGGI_CONFIG')[source]¶ Bases:
object
Program encapsulates the original source code. Currently, PYGGI stores the source code as a list of code lines, as lines are the only supported unit of modifications. For modifications at other granularity levels, this class needs to process and store the source code accordingly (for example, by parsing and storing the AST).
-
CONFIG_FILE_NAME
= 'PYGGI_CONFIG'¶
-
TMP_DIR
= './pyggi_tmp/'¶
-
classmethod
clean_tmp_dir
(tmp_path)[source]¶ Clean the temporary project directory if it exists.
Parameters: tmp_path (str) – The path of directory to clean. Returns: None
-
static
get_file_extension
(file_path)[source]¶ Parameters: file_path (str) – The path of file Returns: file extension Return type: str
-
static
have_the_same_file_extension
(file_path_1, file_path_2)[source]¶ Parameters: - file_path_1 (str) – The path of file 1
- file_path_2 (str) – The path of file 2
Returns: same or not
Return type: bool
-
static
is_java_code
(source_path)[source]¶ Parameters: source_path (str) – The path of the source file Returns: whether the file’s extention is .java or not Return type: bool
-
static
is_python_code
(source_path)[source]¶ Parameters: source_path (str) – The path of the source file Returns: whether the file’s extention is .py or not Return type: bool
-
modification_points
¶ Returns: The list of position of modification points for each target program Return type: dict(str, ?)
-
classmethod
parse
(granularity_level, path, target_files)[source]¶ Parameters: - granularity_level (
program.GranularityLevel
) – The granularity level of a program - path (str) – The project root path
- target_files (list(str)) – The paths to target files from the project root
Returns: The contents of the files, see Hint
Return type: dict(str, list(str))
Hint
- key: the file name
- value: the contents of the file
- granularity_level (
-
print_modification_points
(target_file, indices=None)[source]¶ Print the source of each modification points
Parameters: target_file (str) – The path to target file Returns: None Return type: None
-
select_modification_point
(target_file, method='random')[source]¶ Parameters: - target_file (str) – The modification point is chosen within target_file
- method (str) – The way how to choose a modification point, ‘random’ or ‘weighted’
Returns: The index of modification point
Return type: int
-
set_modification_weights
(target_file, weights)[source]¶ Parameters: - target_file (str) – The path to file
- weights (list(float)) – The modification weight([0,1]) of each modification points
Returns: None
Return type: None
-
tmp_path
¶ Returns: The path of the temporary dirctory Return type: str
-
classmethod
to_source
(granularity_level, contents_of_file)[source]¶ Change contents of file to the source code
Parameters: - granularity_level (
GranularityLevel
) – The parsing level of the program - contents_of_file – The contents of the file which is the parsed form of source code
Returns: The source code
Return type: str
- granularity_level (
-
write_to_tmp_dir
(new_contents)[source]¶ Write new contents to the temporary directory of program
Parameters: new_contents (dict(str, ?)) – The new contents of the program. Refer to apply method of patch.Patch
Return type: None
-