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

Refactoring/13 documentation and formatting #30

Merged
merged 29 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e1b161
Implementing suggested bug fixes to the POC.
MobiTikula Aug 2, 2024
0a0498d
Updating README.md with new section `Expected Output`.
MobiTikula Aug 8, 2024
96a1a5a
Removing Todos from the project. Improving action input logic.
MobiTikula Aug 8, 2024
f06dc31
action.yml and README.md files updated for current state of POC.
MobiTikula Aug 9, 2024
be75de8
Constants handling improved to have all project constants on one plac…
MobiTikula Aug 9, 2024
f6802f3
First phase of pylint refactoring.
MobiTikula Aug 12, 2024
d678e81
Second phase of linting the project.
MobiTikula Aug 12, 2024
0677c53
Third phase of linting the project.
MobiTikula Aug 12, 2024
7c0f8c1
Last phase of linting the project.
MobiTikula Aug 12, 2024
b3e3d99
Code format checked with BLACK: The Uncompromising Code Formatter.
MobiTikula Aug 13, 2024
eb6b679
Adding the class docstrings documentation to the project.
MobiTikula Aug 14, 2024
e465f58
Adding the module docstrings documentation to the project.
MobiTikula Aug 14, 2024
a22f30e
Method docstring documentation added to the project.
MobiTikula Aug 14, 2024
c39b54b
Solving merge conflicts.
MobiTikula Aug 28, 2024
0b29d27
Docstrings update for liv-generator-model.
MobiTikula Aug 28, 2024
7708806
Docstrings update for liv-generator-utils.
MobiTikula Aug 28, 2024
d5e2d21
Docstrings update based on the new standards.
MobiTikula Aug 28, 2024
b9e4d68
Formating project with black tool.
MobiTikula Aug 29, 2024
5db1778
Review comments implemented into POC.
MobiTikula Aug 29, 2024
0bdbf9b
Updated README.md for using a Black formatting tool.
MobiTikula Aug 30, 2024
c807e2c
Updated README.md for using a Black formatting tool.
MobiTikula Aug 30, 2024
9c49482
Updated README.md for using tools.
MobiTikula Aug 30, 2024
b70f0e9
Comments suggestions added.
MobiTikula Sep 2, 2024
56d941e
Black workflow added.
MobiTikula Sep 2, 2024
a9def3f
CI black wrong commit.
MobiTikula Sep 2, 2024
830ccc6
CI black workflow implemented.
MobiTikula Sep 2, 2024
3cdfef6
Update static_analysis_and_tests.yml
MobiTikula Sep 2, 2024
fdafc07
Bug fixes.
MobiTikula Sep 2, 2024
1324bc6
Merge remote-tracking branch 'origin/refactoring/13-Documentation-and…
MobiTikula Sep 2, 2024
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
24 changes: 23 additions & 1 deletion .github/workflows/static_analysis_and_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,31 @@ jobs:
echo "Success: Pylint score is above 9.5 (project score: $PYLINT_SCORE)."
fi

code-format-check:
runs-on: ubuntu-latest
name: Black Format Check
steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Check code format with Black
id: check-format
run: |
black --check $(git ls-files '*.py')
Copy link
Collaborator

Choose a reason for hiding this comment

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

why it is here also? It's duplicated, perhaps it's enough if black step is in the job analysis and then you can remove code-format-check completely - unless there is a good reason for its existence?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This block of code was not supposed to be there twice. Our idea is to have black tool as separate workflow, since it has different goal than pylint. Changed in: fdafc07.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It was my idea. There are two possible reasons for job failure.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok then, as the duplication was removed now, I'll approve as there is nothing else at the moment :) GJ!


python-tests:
runs-on: ubuntu-latest
name: Python tests
name: Python Tests
steps:
- name: Checkout repository
uses: actions/[email protected]
Expand Down
8 changes: 2 additions & 6 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const-naming-style=UPPER_CASE

# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=-1
docstring-min-length=5

# Naming style matching correct function names.
function-naming-style=snake_case
Expand Down Expand Up @@ -426,11 +426,7 @@ confidence=HIGH,
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
# TODO: Remove after this PR
disable=C0116,
C0115,
C0114,
raw-checker-failed,
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
Expand Down
72 changes: 62 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Project Setup](#project-setup)
- [Run Scripts Locally](#run-scripts-locally)
- [Run Pylint Check Locally](#run-pylint-check-locally)
- [Run Black Tool Locally](#run-black-tool-locally)
- [Run unit test](#run-unit-test)
- [Deployment](#deployment)
- [Features](#features)
Expand Down Expand Up @@ -150,7 +151,7 @@ Configure the action by customizing the following parameters based on your needs
]'
```

### Features de/activation
### Features De/Activation
- **project-state-mining** (optional, `default: false`)
- **Description**: Enables or disables the mining of project state data from [GitHub Projects](https://docs.github.com/en/issues/planning-and-tracking-with-projects/learning-about-projects/about-projects).
- **Usage**: Set to true to activate.
Expand Down Expand Up @@ -187,7 +188,7 @@ The Living Documentation Generator action provides a key output that allows user
## Expected Output
The Living Documentation Generator is designed to produce an Issue Summary page (index.md) along with multiple detailed single issue pages.

### Index page example
### Index Page Example

```markdown
# Issue Summary page
Expand All @@ -209,7 +210,7 @@ Here, you'll find a summarized list of all these issues, their brief description
These values can vary from project to project.
- The `---` symbol is used to indicate that an issue has no required project data.

### Issue page example
### Issue Page Example

```markdown
# FEAT: Advanced Book Search
Expand Down Expand Up @@ -255,7 +256,7 @@ pip install -r requirements.txt
## Run Scripts Locally
If you need to run the scripts locally, follow these steps:

### Create the shell script
### Create the Shell Script
Create the shell file in the root directory. We will use `run_script.sh`.
```shell
touch run_script.sh
Expand All @@ -265,7 +266,7 @@ Add the shebang line at the top of the sh script file.
#!/bin/sh
```

### Set the environment variables
### Set the Environment Variables
Set the configuration environment variables in the shell script following the structure below.
Also make sure that the GITHUB_TOKEN is configured in your environment variables.
```
Expand Down Expand Up @@ -305,7 +306,7 @@ chmod +x run_script.sh
```

## Run Pylint Check Locally
This project uses Pylint tool for static code analysis.
This project uses [Pylint](https://pypi.org/project/pylint/) tool for static code analysis.
Pylint analyses your code without actually running it.
It checks for errors, enforces, coding standards, looks for code smells etc.

Expand Down Expand Up @@ -338,20 +339,71 @@ Example:
pylint living_documentation_generator/generator.py
```

## Run unit test
### Expected Output
This is the console expected output example after running the tool:
```
************* Module main
main.py:30:0: C0116: Missing function or method docstring (missing-function-docstring)

------------------------------------------------------------------
Your code has been rated at 9.41/10 (previous run: 8.82/10, +0.59)
```

## Run Black Tool Locally
This project uses the [Black](https://github.com/psf/black) tool for code formatting.
Black aims for consistency, generality, readability and reducing git diffs.
The coding style used can be viewed as a strict subset of PEP 8.

The project root file `pyproject.toml` defines the Black tool configuration.
In this project we are accepting the line length of 120 characters.

Follow these steps to format your code with Black locally:

### Set Up Python Environment
From terminal in the root of the project, run the following command:

```shell
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

This command will also install a Black tool, since it is listed in the project requirements.

### Run Black
Run Black on all files that are currently tracked by Git in the project.
```shell
black $(git ls-files '*.py')
```

To run Black on a specific file, follow the pattern `black <path_to_file>/<name_of_file>.py`.

Example:
```shell
black living_documentation_generator/generator.py
```

### Expected Output
This is the console expected output example after running the tool:
```
All done! ✨ 🍰 ✨
1 file reformatted.
```

## Run Unit Test
TODO - check this chapter and update by latest state
### Launch unit tests
### Launch Unit Tests
```
pytest
```

### To run specific tests or get verbose output:
### To Run Specific Tests or Get Verbose Output:
```
pytest -v # Verbose mode
pytest path/to/test_file.py # Run specific test file
```

### To check Test Coverage:
### To Check Test Coverage:
```
pytest --cov=../scripts
```
Expand Down
55 changes: 48 additions & 7 deletions living_documentation_generator/action_inputs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
#
# Copyright 2024 ABSA Group Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""
This module contains an Action Inputs class methods,
which are essential for running the GH action.
"""

import json
import logging
import sys
Expand All @@ -10,6 +31,10 @@


class ActionInputs:
"""
A class representing all the action inputs. It is responsible for loading, managing
and validating the inputs required for running the GH Action.
"""

def __init__(self):
self.__github_token: str = ""
Expand All @@ -19,31 +44,40 @@ def __init__(self):

@property
def github_token(self) -> str:
"""Getter of the GitHub authorization token."""
return self.__github_token

@property
def is_project_state_mining_enabled(self) -> bool:
"""Getter of the project state mining switch."""
return self.__is_project_state_mining_enabled

@property
def repositories(self) -> list[ConfigRepository]:
"""Getter of the list of repositories to fetch from."""
return self.__repositories

@property
def output_directory(self) -> str:
"""Getter of the output directory."""
return self.__output_directory

def load_from_environment(self, validate: bool = True) -> 'ActionInputs':
def load_from_environment(self, validate: bool = True) -> "ActionInputs":
"""
Load the action inputs from the environment variables and validate them if needed.

@param validate: Switch indicating if the inputs should be validated.
@return: The instance of the ActionInputs class.
"""
self.__github_token = get_action_input(GITHUB_TOKEN)
self.__is_project_state_mining_enabled = (get_action_input(PROJECT_STATE_MINING, "false")
.lower() == "true")
out_path = get_action_input(OUTPUT_PATH, './output')
self.__is_project_state_mining_enabled = get_action_input(PROJECT_STATE_MINING, "false").lower() == "true"
out_path = get_action_input(OUTPUT_PATH, "./output")
self.__output_directory = make_absolute_path(out_path)
repositories_json = get_action_input(REPOSITORIES, "")

logger.debug('Is project state mining allowed: %s.', self.is_project_state_mining_enabled)
logger.debug('JSON repositories to fetch from: %s.', repositories_json)
logger.debug('Output directory: %s.', self.output_directory)
logger.debug("Is project state mining allowed: %s.", self.is_project_state_mining_enabled)
logger.debug("JSON repositories to fetch from: %s.", repositories_json)
logger.debug("Output directory: %s.", self.output_directory)

# Validate inputs
if validate:
Expand All @@ -64,6 +98,13 @@ def load_from_environment(self, validate: bool = True) -> 'ActionInputs':
return self

def validate_inputs(self, repositories_json: str) -> None:
"""
Validate the input attributes of the action.

@param repositories_json: The JSON string containing the repositories to fetch.
@return: None
"""

# Validate correct format of input repositories_json
try:
json.loads(repositories_json)
Expand Down
Loading