-
Notifications
You must be signed in to change notification settings - Fork 6
xlsx-run-tool #24
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
Merged
Merged
xlsx-run-tool #24
Changes from all commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
f62c91f
updating requirements
dariadiatlova daee49b
adding script to run tool on xlsx file
dariadiatlova 52d971c
adding testing files
dariadiatlova 45b5919
adding tests
dariadiatlova e797191
Requirements for xlsx tool
dariadiatlova 2172286
XLSX run_tool
dariadiatlova 52b28ae
Files to test xlsx run tool
dariadiatlova 6a50db5
XLSX run tool tests
dariadiatlova 5c1c7cf
Update build.yml
dariadiatlova db4eca8
Update build.yml
dariadiatlova 8f2f19f
Update build.yml
dariadiatlova 6ac1154
Clean xlsx
dariadiatlova 2b3fd79
Merge branch 'xlsx_run_tool' of https://github.com/hyperskill/hyperst…
dariadiatlova f0cce19
Tempfiles substituted with regular
dariadiatlova 5db8e3d
File name substituted with absolute path
dariadiatlova b708c1d
Adding new func names
dariadiatlova c5c75d9
Update evaluation tests
dariadiatlova f901771
Files for evaluation testing
dariadiatlova 30ba7b2
Update functionality xlsx-run tool
dariadiatlova 61a054f
Adding MAIN_FOLDER
dariadiatlova 62bce7d
Evaluation tool-interface update
dariadiatlova 90edf16
Updating evaluation tests
dariadiatlova c0eeed2
Change mode for opening file
dariadiatlova 7439faa
Adding file exist exception
dariadiatlova 4641276
Assertation update
dariadiatlova 685d0bb
Adding gitkeep
dariadiatlova 296efac
Adiing gitkeep
dariadiatlova 6acc246
Fixed typing issue
dariadiatlova fe4877f
Resolving conflicts
dariadiatlova efd5dcb
Merge branch 'develop' into xlsx_run_tool
GirZ0n 8082f78
Fixed imports
GirZ0n ab62d8a
Fixed imports
GirZ0n b8d6156
Updated evaluation module
dariadiatlova fa2c376
Added common class with run_tool arguments
dariadiatlova 85973c0
Updated run_tool argnames and several functions
dariadiatlova 11772d6
Updated evaluation tests
dariadiatlova 9ceeb73
Updated evaluation resources
dariadiatlova dc12b8b
Resolving conflicts
dariadiatlova 9653133
Fixed merging issue
dariadiatlova 1a52079
Fixed merging issue
dariadiatlova 4c8a54d
Fixed Flake inspection
dariadiatlova b7187fd
Fixed Flake inspection issue
dariadiatlova 6ec4240
Added util
dariadiatlova 21f4cfd
Added logger to check test output
dariadiatlova 5303706
Added logger to check test output
dariadiatlova 39d3a38
Save artifacts for debugging
dariadiatlova 137f800
Updated tests to save artefacts
dariadiatlova 1686785
Dedugging loggits
dariadiatlova ec560a8
Updated resources
dariadiatlova e6111e1
Remove saved files after debugging
dariadiatlova 31f1235
Added evaluation README.me
dariadiatlova 76ecafe
Updated readme and fixed argname
dariadiatlova 53f45f1
Resolved pull request issues
dariadiatlova f07a717
Resolved pull request issues
dariadiatlova 7b1a14a
Resolved pull request issues
dariadiatlova ede99f8
Resolved pull request issues
dariadiatlova a7fd99f
Updated flags in README.md
dariadiatlova 5dd2adc
Update README.md
dariadiatlova 04123e0
Update README.md
dariadiatlova 9e3873f
Update README.md
dariadiatlova 4ca4610
Update README.md
dariadiatlova bed4b53
Update README.md
dariadiatlova d6bbc11
Added a separate requirements file for evaluation module
dariadiatlova 7535452
Resolved PR issues
dariadiatlova b025607
Merge branch 'xlsx_run_tool' of https://github.com/hyperskill/hyperst…
dariadiatlova 1c96bee
Small fixes after pr
dariadiatlova ca36a3d
Small fixes after pr
dariadiatlova b272821
Update src/python/evaluation/common/util.py
dariadiatlova de2b0ce
Update src/python/evaluation/common/xlsx_util.py
dariadiatlova b712c52
added unique to whitelist
dariadiatlova fb04b4a
Added unique import
dariadiatlova fb7dfba
Update src/python/evaluation/common/util.py
dariadiatlova 82f46d7
Update src/python/evaluation/xlsx_run_tool.py
dariadiatlova 62b510b
removed NoReturn import
dariadiatlova 2c8a3c8
Update src/python/evaluation/evaluation_config.py
dariadiatlova a329e77
Fixed Namespace issue
dariadiatlova 04bc2d7
Update src/python/common/tool_arguments.py
dariadiatlova 9b46709
Fixed error raising
dariadiatlova 12244f8
Fixed typing
dariadiatlova e4cc0c3
Fixed typing
dariadiatlova 275128f
Fixed Typing
dariadiatlova 6f61f6b
Fixed Typing
dariadiatlova 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| openpyxl==3.0.7 | ||
| pandas==1.2.3 | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,3 +27,4 @@ radon==4.5.0 | |
| # extra libraries and frameworks | ||
| django==3.2 | ||
| requests==2.25.1 | ||
| argparse==1.4.0 | ||
Empty file.
This file contains hidden or 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,74 @@ | ||
| from dataclasses import dataclass | ||
| from enum import Enum, unique | ||
| from typing import List, Optional | ||
|
|
||
| from src.python.review.application_config import LanguageVersion | ||
| from src.python.review.inspectors.inspector_type import InspectorType | ||
|
|
||
|
|
||
| @unique | ||
| class VerbosityLevel(Enum): | ||
| """ | ||
| Same meaning as the logging level. Should be used in command-line args. | ||
| """ | ||
| DEBUG = '3' | ||
| INFO = '2' | ||
| ERROR = '1' | ||
| DISABLE = '0' | ||
|
|
||
| @classmethod | ||
| def values(cls) -> List[str]: | ||
| return [member.value for member in VerbosityLevel.__members__.values()] | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ArgumentsInfo: | ||
| short_name: Optional[str] | ||
| long_name: str | ||
| description: str | ||
dariadiatlova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @unique | ||
| class RunToolArgument(Enum): | ||
| VERBOSITY = ArgumentsInfo('-v', '--verbosity', | ||
| 'Choose logging level: ' | ||
| f'{VerbosityLevel.ERROR.value} - ERROR; ' | ||
| f'{VerbosityLevel.INFO.value} - INFO; ' | ||
| f'{VerbosityLevel.DEBUG.value} - DEBUG; ' | ||
| f'{VerbosityLevel.DISABLE.value} - disable logging; ' | ||
| 'default is 0') | ||
|
|
||
| inspectors = [inspector.lower() for inspector in InspectorType.available_values()] | ||
| disabled_inspectors_example = f'-d {inspectors[0].lower()},{inspectors[1].lower()}' | ||
|
|
||
| DISABLE = ArgumentsInfo('-d', '--disable', | ||
| 'Disable inspectors. ' | ||
| f'Available values: {", ".join(inspectors)}. ' | ||
| f'Example: {disabled_inspectors_example}') | ||
|
|
||
| DUPLICATES = ArgumentsInfo(None, '--allow-duplicates', | ||
| 'Allow duplicate issues found by different linters. ' | ||
| 'By default, duplicates are skipped.') | ||
|
|
||
| LANG_VERSION = ArgumentsInfo(None, '--language-version', | ||
| 'Specify the language version for JAVA inspectors.' | ||
| 'Available values are: ' | ||
| f'{LanguageVersion.PYTHON_3.value}, {LanguageVersion.JAVA_8.value}, ' | ||
| f'{LanguageVersion.JAVA_11.value}, {LanguageVersion.KOTLIN.value}.') | ||
|
|
||
| CPU = ArgumentsInfo(None, '--n-cpu', | ||
| 'Specify number of cpu that can be used to run inspectors') | ||
|
|
||
| PATH = ArgumentsInfo(None, 'path', 'Path to file or directory to inspect.') | ||
|
|
||
| FORMAT = ArgumentsInfo('-f', '--format', | ||
| 'The output format. Default is JSON.') | ||
|
|
||
| START_LINE = ArgumentsInfo('-s', '--start-line', | ||
| 'The first line to be analyzed. It starts from 1.') | ||
|
|
||
| END_LINE = ArgumentsInfo('-e', '--end-line', 'The end line to be analyzed or None.') | ||
|
|
||
| NEW_FORMAT = ArgumentsInfo(None, '--new-format', | ||
| 'The argument determines whether the tool ' | ||
| 'should use the new format') | ||
This file contains hidden or 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,31 @@ | ||
| # Hyperstyle evaluation | ||
|
|
||
| This tool allows running the `Hyperstyle` tool on an xlsx table to get code quality for all code fragments. Please, note that your input file should consist of at least 2 obligatory columns to run xlsx-tool on its code fragments: | ||
|
|
||
| - `code` | ||
| - `lang` | ||
|
|
||
| Possible values for column `lang` are: `python3`, `kotlin`, `java8`, `java11`. | ||
|
|
||
| Output file is a new `xlsx` file with 3 columns: | ||
| - `code` | ||
| - `lang` | ||
| - `grade` | ||
| Grade assessment is conducted by [`run_tool.py`](https://github.com/hyperskill/hyperstyle/blob/main/README.md) with default arguments. Avaliable values for column `grade` are: BAD, MODERATE, GOOD, EXCELLENT. It is also possible add fourth column: `traceback` to get full inspectors feedback on each code fragment. More details on enabling traceback column in **Optional Arguments** table. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run the [xlsx_run_tool.py](xlsx_run_tool.py) with the arguments from command line. | ||
|
|
||
| Required arguments: | ||
|
|
||
| `xlsx_file_path` — path to xlsx-file with code samples to inspect. | ||
|
|
||
| Optional arguments: | ||
| Argument | Description | ||
| --- | --- | ||
| |**‑f**, **‑‑format**| The output format. Available values: `json`, `text`. The default value is `json` . Use this argument when `traceback` is enabled, otherwise it will not be used.| | ||
| |**‑tp**, **‑‑tool_path**| Path to run-tool. Default is `src/python/review/run_tool.py` .| | ||
| |**‑tr**, **‑‑traceback**| To include a column with errors traceback into an output file. Default is `False`.| | ||
| |**‑ofp**, **‑‑output_folder_path**| An explicit folder path to store file with results. Default is a parent directory of a folder with xlsx-file sent for inspection. | | ||
| |**‑ofn**, **‑‑output_file_name**| A name of an output file where evaluation results will be stored. Default is `results.xlsx`.| |
Empty file.
Empty file.
This file contains hidden or 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,34 @@ | ||
| from enum import Enum, unique | ||
|
|
||
| from src.python.review.application_config import LanguageVersion | ||
| from src.python.review.common.file_system import Extension | ||
|
|
||
|
|
||
| @unique | ||
| class ColumnName(Enum): | ||
dariadiatlova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CODE = "code" | ||
| LANG = "lang" | ||
| LANGUAGE = "language" | ||
| GRADE = "grade" | ||
|
|
||
|
|
||
| @unique | ||
| class EvaluationArgument(Enum): | ||
dariadiatlova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TRACEBACK = "traceback" | ||
| RESULT_FILE_NAME = "results" | ||
| RESULT_FILE_NAME_EXT = f"{RESULT_FILE_NAME}{Extension.XLSX.value}" | ||
|
|
||
|
|
||
| script_structure_rule = ("Please, make sure your XLSX-file matches following script standards: \n" | ||
| "1. Your XLSX-file should have 2 obligatory columns named:" | ||
| f"'{ColumnName.CODE.value}' & '{ColumnName.LANG.value}'. \n" | ||
| f"'{ColumnName.CODE.value}' column -- relates to the code-sample. \n" | ||
| f"'{ColumnName.LANG.value}' column -- relates to the language of a " | ||
| "particular code-sample. \n" | ||
| "2. Your code samples should belong to the one of the supported languages. \n" | ||
| "Supported languages are: Java, Kotlin, Python. \n" | ||
| f"3. Check that '{ColumnName.LANG.value}' column cells are filled with " | ||
| "acceptable language-names: \n" | ||
| f"Acceptable language-names are: {LanguageVersion.PYTHON_3.value}, " | ||
| f"{LanguageVersion.JAVA_8.value} ," | ||
| f"{LanguageVersion.JAVA_11.value} and {LanguageVersion.KOTLIN.value}.") | ||
This file contains hidden or 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,42 @@ | ||
| import logging.config | ||
| from pathlib import Path | ||
| from typing import Union | ||
|
|
||
| import pandas as pd | ||
| from openpyxl import load_workbook, Workbook | ||
| from src.python.evaluation.evaluation_config import EvaluationConfig | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def remove_sheet(workbook_path: Union[str, Path], sheet_name: str, to_raise_error: bool = False) -> None: | ||
| try: | ||
| workbook = load_workbook(workbook_path) | ||
| workbook.remove(workbook[sheet_name]) | ||
| workbook.save(workbook_path) | ||
|
|
||
| except KeyError as e: | ||
| message = f'Sheet with specified name: {sheet_name} does not exist.' | ||
| if to_raise_error: | ||
| logger.exception(message) | ||
| raise e | ||
| else: | ||
| logger.info(message) | ||
|
|
||
|
|
||
| def create_and_get_workbook_path(config: EvaluationConfig) -> Path: | ||
| workbook = Workbook() | ||
| workbook_path = config.get_output_file_path() | ||
| workbook.save(workbook_path) | ||
| return workbook_path | ||
|
|
||
|
|
||
| def write_dataframe_to_xlsx_sheet(xlsx_file_path: Union[str, Path], df: pd.DataFrame, sheet_name: str, | ||
| mode: str = 'a', to_write_row_names: bool = False) -> None: | ||
| """ | ||
| mode: str Available values are {'w', 'a'}. File mode to use (write or append). | ||
| to_write_row_names: bool Write row names. | ||
| """ | ||
|
|
||
| with pd.ExcelWriter(xlsx_file_path, mode=mode) as writer: | ||
| df.to_excel(writer, sheet_name=sheet_name, index=to_write_row_names) |
This file contains hidden or 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,43 @@ | ||
| import logging.config | ||
| from argparse import Namespace | ||
| from pathlib import Path | ||
| from typing import List, Union | ||
|
|
||
| from src.python.common.tool_arguments import RunToolArgument | ||
| from src.python.evaluation.common.util import EvaluationArgument | ||
| from src.python.review.application_config import LanguageVersion | ||
| from src.python.review.common.file_system import create_directory | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class EvaluationConfig: | ||
| def __init__(self, args: Namespace): | ||
| self.tool_path: Union[str, Path] = args.tool_path | ||
| self.output_format: str = args.format | ||
| self.xlsx_file_path: Union[str, Path] = args.xlsx_file_path | ||
| self.traceback: bool = args.traceback | ||
| self.output_folder_path: Union[str, Path] = args.output_folder_path | ||
| self.output_file_name: str = args.output_file_name | ||
|
|
||
| def build_command(self, inspected_file_path: Union[str, Path], lang: str) -> List[str]: | ||
| command = [LanguageVersion.PYTHON_3.value, | ||
| self.tool_path, | ||
| inspected_file_path, | ||
| RunToolArgument.FORMAT.value.short_name, self.output_format] | ||
|
|
||
| if lang == LanguageVersion.JAVA_8.value or lang == LanguageVersion.JAVA_11.value: | ||
| command.extend([RunToolArgument.LANG_VERSION.value.long_name, lang]) | ||
| return command | ||
|
|
||
| def get_output_file_path(self) -> Path: | ||
| if self.output_folder_path is None: | ||
| try: | ||
| self.output_folder_path = ( | ||
| Path(self.xlsx_file_path).parent.parent / EvaluationArgument.RESULT_FILE_NAME.value | ||
| ) | ||
| create_directory(self.output_folder_path) | ||
| except FileNotFoundError as e: | ||
| logger.error('XLSX-file with the specified name does not exists.') | ||
| raise e | ||
| return Path(self.output_folder_path) / self.output_file_name |
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.
Uh oh!
There was an error while loading. Please reload this page.