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

Formatting PR #9

Merged
merged 105 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
7876df7
conforming to pep8 standard
Younis-Ahmed Feb 2, 2024
d4e525b
conforming to pep8 and adding docstring for better readability
Younis-Ahmed Feb 2, 2024
0677f69
Add Betty Fixer main module docstring and pep8 standard
Younis-Ahmed Feb 2, 2024
169a924
Refactor bettyfixer module
Younis-Ahmed Feb 2, 2024
663a3ac
Add dependency_links.txt file
Younis-Ahmed Feb 2, 2024
0b5193f
Add new files and modify existing files
Younis-Ahmed Feb 2, 2024
4aa325a
***Add validation for user input***
Younis-Ahmed Feb 2, 2024
7e7007e
Add functions for handling Betty style tasks
Younis-Ahmed Feb 2, 2024
47a0737
Add error extraction functionality to BettyFixer***
Younis-Ahmed Feb 2, 2024
a6470a4
Fix docstring
Younis-Ahmed Feb 2, 2024
4e469e9
Refactor file handling functions and add comments
Younis-Ahmed Feb 2, 2024
7793bdf
Fix import statement in __init__.py
Younis-Ahmed Feb 2, 2024
b563fe7
Add blank line to backup.py
Younis-Ahmed Feb 2, 2024
4b4263a
Refactor errors_extractor.py for better readability and maintainability
Younis-Ahmed Feb 2, 2024
4a58dac
Fix indentation in extract_line.py
Younis-Ahmed Feb 2, 2024
36451ab
Update README.md
Younis-Ahmed Feb 2, 2024
e0ee9bf
Update README.md
Younis-Ahmed Feb 2, 2024
ef86fc5
Remove dependency_links.txt file
Younis-Ahmed Feb 2, 2024
303db88
Remove bettyfixer entry points
Younis-Ahmed Feb 2, 2024
b7b0a58
Delete bettyfixer.egg-info/PKG-INFO file
Younis-Ahmed Feb 2, 2024
d330ec6
Remove colorama and black from requires.txt
Younis-Ahmed Jan 31, 2024
d5b8828
delete unnecessary files
Younis-Ahmed Jan 31, 2024
eecb3c5
Remove bettyfixer from top_level.txt
Younis-Ahmed Jan 31, 2024
65b4ea1
delete unnecessary files
Younis-Ahmed Jan 31, 2024
a992d88
delete unnecessary files
Younis-Ahmed Jan 31, 2024
d7624b9
delete unnecessary files
Younis-Ahmed Jan 31, 2024
87ab62f
delete unnecessary files
Younis-Ahmed Jan 30, 2024
89a59d6
delete unnecessary files
Younis-Ahmed Jan 30, 2024
71b91ec
delete unnecessary files
Younis-Ahmed Jan 30, 2024
93cef65
delete unnecessary files
Younis-Ahmed Jan 30, 2024
e74aee2
delete unnecessary files
Younis-Ahmed Jan 30, 2024
39f8e93
Merge branch 'features.lintingPEP8' of https://github.com/Younis-Ahme…
Younis-Ahmed Feb 2, 2024
4c4689b
Refactor betty_fixer.py: import statements and function names
Younis-Ahmed Feb 4, 2024
0280f4e
process_errors needs reviewing
Younis-Ahmed Feb 4, 2024
a2084af
Refactor code to create a new file from specified line to end
Younis-Ahmed Feb 4, 2024
ee5c40a
Fix formatting issues in extract_line.py
Younis-Ahmed Feb 4, 2024
b61bc50
Refactor error file processing functions
Younis-Ahmed Feb 4, 2024
bff70f9
Refactor variable names and update comments
Younis-Ahmed Feb 4, 2024
d6c3246
Fix formatting issues in extract_line.py
Younis-Ahmed Feb 4, 2024
6a86411
Fix unused attribute bug in extract_line.py
Younis-Ahmed Feb 4, 2024
792629e
Fix unused attribute extraction in extract_line.py
Younis-Ahmed Feb 4, 2024
b91fda7
Refactor argument extraction in generate_documentation function
Younis-Ahmed Feb 4, 2024
95234a4
Refactor error message extraction in extract_functions_with_no_descri…
Younis-Ahmed Feb 4, 2024
7712e0f
Refactor code for improved performance and readability
Younis-Ahmed Feb 4, 2024
402bedc
Refactor delete_files and autoproto functions
Younis-Ahmed Feb 5, 2024
b24612d
Fix function counter bug in betty_fixer.py
Younis-Ahmed Feb 5, 2024
57339df
Fix unused variable issue in extract_line.py and fix space required a…
Younis-Ahmed Feb 5, 2024
37ca9a2
Add Betty Fixer functionality and improve error handling
Younis-Ahmed Feb 5, 2024
5d8122e
Refactor tag filtering in autoprototype.py
Younis-Ahmed Feb 5, 2024
2dce379
Add specific error handling in create_backup function
Younis-Ahmed Feb 5, 2024
592b4a4
Fix error handling in errors_extractor.py
Younis-Ahmed Feb 5, 2024
2f3aada
Refactor line extraction logic in extract_line.py
Younis-Ahmed Feb 5, 2024
61b7339
Refactor process_errors function
Younis-Ahmed Feb 6, 2024
33c64fe
Fix variable name in process_errors function
Younis-Ahmed Feb 6, 2024
5f3ac3f
Refactor code formatting and fix comments***
Younis-Ahmed Feb 6, 2024
77b5a1c
Refactor file name generation for sequential numbering
Younis-Ahmed Feb 6, 2024
a5da35f
Refactor code formatting and file handling***
Younis-Ahmed Feb 6, 2024
8fa5728
Fix unused variable and exception handling in extract_line.py
Younis-Ahmed Feb 6, 2024
adb384c
Refactor code for improved performance and readability
Younis-Ahmed Feb 6, 2024
bedfeb0
Refactor context extraction in extract_line.py
Younis-Ahmed Feb 6, 2024
52eb3d7
Refactor code for better readability and maintainability
Younis-Ahmed Feb 6, 2024
7de4d2d
Refactor error description variable name in extract_line.py
Younis-Ahmed Feb 6, 2024
675a146
Add recursive-exclude for errors_logs in MANIFEST.in
Younis-Ahmed Feb 6, 2024
6224caa
Fix code formatting and documentation issues
Younis-Ahmed Feb 6, 2024
b8d56d2
Fix code formatting and documentation issues
Younis-Ahmed Feb 6, 2024
a84e17a
Fix bug in login functionality***
Younis-Ahmed Feb 6, 2024
b07302b
Fix code formatting and documentation issues
Younis-Ahmed Feb 6, 2024
2d72472
Add errors_extractor.md with code analysis results
Younis-Ahmed Feb 6, 2024
b0f8660
Refactor code to improve performance and readability
Younis-Ahmed Feb 6, 2024
42fd7f4
Refactor betty_check function and improve code readability
Younis-Ahmed Feb 7, 2024
498d3fc
Refactor Betty Handler module and improve code readability
Younis-Ahmed Feb 7, 2024
717cb0d
Refactor error extraction function
Younis-Ahmed Feb 7, 2024
909d470
Fix space required after specifier in extract_line.py
Younis-Ahmed Feb 7, 2024
5da12d0
Add header file generation functionality
Younis-Ahmed Feb 7, 2024
a18232c
Refactor create_backup function error handling
Younis-Ahmed Feb 7, 2024
f19cc93
Fix clearing of errors.txt file
Younis-Ahmed Feb 7, 2024
2c3e634
Fix code formatting and documentation issues
Younis-Ahmed Feb 7, 2024
fdea477
Fix code style issues in autoprototype.py
Younis-Ahmed Feb 7, 2024
786247b
Fix code formatting and documentation issues
Younis-Ahmed Feb 7, 2024
0a14693
Fix code formatting and documentation issues
Younis-Ahmed Feb 7, 2024
f992e96
Update user authentication logic***
Younis-Ahmed Feb 7, 2024
5cc0138
Refactor function to improve performance***
Younis-Ahmed Feb 7, 2024
4ffff45
Fix code style issues and remove unused files
Younis-Ahmed Feb 7, 2024
da6c726
Fix code style issues and add missing docstrings
Younis-Ahmed Feb 7, 2024
b2d3d12
Fix errors and improve code quality
Younis-Ahmed Feb 7, 2024
31db32f
Refactor code for improved performance and readability
Younis-Ahmed Feb 7, 2024
3d05755
Add Pylint workflow for code analysis
Younis-Ahmed Feb 7, 2024
e30762f
Fix pylint warnings and clean up code
Younis-Ahmed Feb 7, 2024
28302a5
Merge branch 'features.lintingPEP8' of https://github.com/Younis-Ahme…
Younis-Ahmed Feb 7, 2024
417573d
Refactor function name variable in extract_line.py
Younis-Ahmed Feb 7, 2024
4e9f906
Fix Betty style and remove linting errors
Younis-Ahmed Feb 7, 2024
bbf99fc
Update MANIFEST.in and setup.py
Younis-Ahmed Feb 7, 2024
c3b62d1
Update linting workflow to install colorama package
Younis-Ahmed Feb 7, 2024
62e7c39
Update Python versions in linting workflow
Younis-Ahmed Feb 7, 2024
9d36c7b
Add pycodestyle analysis to linting workflow
Younis-Ahmed Feb 7, 2024
0114d64
Update linting.yml to trigger on pull requests as well as pushes
Younis-Ahmed Feb 7, 2024
cac9c7c
Pending changes exported from your codespace
Younis-Ahmed Feb 10, 2024
4868183
Remove betty_handler.py and related functions as it is duplicates fro…
Younis-Ahmed Feb 10, 2024
b07284a
Delete main.c
Younis-Ahmed Feb 17, 2024
8f8548f
Update linting.yml
Younis-Ahmed Feb 18, 2024
5af99a0
Fix betty error message formatting
Younis-Ahmed Feb 19, 2024
0259e4d
description formatting
Younis-Ahmed Feb 19, 2024
ee966e8
remove whitespaces
Younis-Ahmed Feb 19, 2024
7596817
Remove unused devcontainer.json file
Younis-Ahmed Feb 19, 2024
87e54d5
Refactor linting workflow
Younis-Ahmed Feb 19, 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
26 changes: 26 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pylint

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint pycodestyle colorama
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
- name: Analysing the code with pycodestyle
run: |
pycodestyle $(git ls-files '*.py' | grep -v setup.py)
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include README.md
recursive-exclude errors_logs *
exclude pylintrc
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ If you'd like to contribute to Betty Fixer, please follow these steps:



### Creaters: -
### Creators: -
[@Moealsir](https://github.com/Moealsir) <br>
[@Malazmuzamil98](https://github.com/malazmuzamil98)<br>
[@AhedEisa](https://github.com/be-great)
[@AhedEisa](https://github.com/be-great)

### Contributors:
[@Younis-ahmed](https://github.com/Younis-ahmed) <br>
7 changes: 6 additions & 1 deletion bettyfixer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .betty_fixer import *
"""
This module provides the Betty Fixer functionality.
"""

from .betty_fixer import *
# modify_main_files(sys.argv[1:])
163 changes: 123 additions & 40 deletions bettyfixer/autoprototype.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import argparse
"""
This module contains the functions to generate a header file with
the prototypes of the functions in a directory.
"""
import subprocess
import os
import re
from colorama import Fore
import glob
from colorama import Fore


# betty cj
def betty_check():
"""Check if betty is installed and if there are any errors in the files.
Returns:
bool: True if betty is installed and there are no errors,
False otherwise.
"""
try:
c_files = glob.glob("*.c")
result1 = subprocess.run(["betty"] + c_files, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
result1 = subprocess.run(["betty"] + c_files, check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True)

except subprocess.CalledProcessError as e:
print(e)
Expand All @@ -23,78 +32,152 @@ def betty_check():
return result1.returncode == 0


## auto checks errors
def print_check_betty_first():
print(Fore.RED + "You should fix betty Errors first before copy prototype functions into The header file" + Fore.RESET)
"""Prints a message to the user to fix betty errors first."""
print(
Fore.RED + "You should fix betty Errors first before \
copy prototype functions into The header file" + Fore.RESET
)


def print_header_name_missing():
"""Prints a message to the user to provide a header file name."""
print(Fore.RED + "Usage : bettyfixer -H <heahdername>.h" + Fore.RESET)
def print_Ctags_header_error(msg):


def print_ctags_header_error(msg):
"""Prints a message to the user in red color."""
print(Fore.RED + msg + Fore.RESET)


def check_ctags():
"""Check if ctags is installed.
Returns:
bool: True if ctags is installed, False otherwise.
str: Error message if ctags is not installed.
"""
try:
subprocess.run(['ctags', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
subprocess.run(['ctags', '--version'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, check=True)
return True, None
except subprocess.CalledProcessError:
msg = "ctags is not installed. Please install ctags before running this script."
msg = "ctags is not installed. \
Please install ctags before running this script."
return False, msg


def generate_tags(directory):
"""Generate tags for the files in the directory.
Args:
directory (str): Directory path.
Returns:
bool: True if ctags is generated successfully, False otherwise.
"""
try:
subprocess.run(['ctags', '-R', '--c-kinds=+p', '--fields=+S', '--extra=+q', '--languages=c', f'--langmap=c:.c', directory], check=True)
subprocess.run(['ctags', '-R', '--c-kinds=+p',
'--fields=+S', '--extra=+q',
'--languages=c', '--langmap=c:.c',
directory], check=True)
return True
except subprocess.CalledProcessError as e:
print_Ctags_header_error(f"Error generating ctags: {e}")
print_ctags_header_error(f"Error generating ctags: {e}")
return False
def filter_tags(directory,tags_file):
temp_tags_path = os.path.join(directory,'temp_tags')
tags_path = os.path.join(directory,tags_file)

sed_command = r"cat {0} | sed -n 's/^.*\/^\(.*\)/\1/p' | sed 's/\(.*\)\$.*/\1/' | sed 's/;$//' | uniq | sed '/int main(/d' | sed '/.*:/d' | sed 's/$/;/g' > {1}".format(tags_path, temp_tags_path)


def filter_tags(directory, tags_file):
"""
Filter the tags file to get only the function prototypes.
Args:
directory (str): Directory path.
tags_file (str): Tags file name.
Returns:
str: Filtered tags.
"""
temp_tags_path = os.path.join(directory, 'temp_tags')
tags_path = os.path.join(directory, tags_file)

sed_command = (
f"cat {tags_path} | sed -n 's/^.*\\/^(.*)/\\1/p' | "
"sed 's/(.*)\\$.*/\\1/' | sed 's/;$//' | "
"uniq | sed '/int main(/d' | sed '/.*:/d' | "
f"sed 's/$/;/g' > {temp_tags_path}"
)

# Run the sed_command using subprocess
subprocess.run(sed_command, shell=True, check=True)

# Check if the file exists before trying to open it
if os.path.exists(temp_tags_path):
with open(temp_tags_path, 'r') as temp_tags_file:
with open(temp_tags_path, 'r', encoding='utf-8') as temp_tags_file:
filtered_tags = temp_tags_file.read()
return filtered_tags
else:
# Handle the case where the file doesn't exist
msg =f"Error: File {temp_tags_path} does not exist."
print_Ctags_header_error(msg)
return None

# Handle the case where the file doesn't exist
msg = f"Error: File {temp_tags_path} does not exist."
print_ctags_header_error(msg)
return None


def create_header(header_file, filtered_tags):
"""
Create a header file with the filtered tags.
Args:
header_file (str): Header file name.
filtered_tags (str): Filtered tags.
"""
header_name = header_file.split('/')[-1]
header_name =header_name.split('.')
header_name= '_'.join(header_name)
with open(header_file, 'w') as header:
header_name = header_name.split('.')
header_name = '_'.join(header_name)
with open(header_file, 'w', encoding='utf-8') as header:
header.write(f'#ifndef {header_name.upper()}\n')
header.write(f'#define {header_name.upper()}\n\n')
header.write(filtered_tags)
header.write('\n#endif\n')


def delete_files(tags, temp_tags):
command = "rm {0} {1}".format(tags, temp_tags)
"""
Delete the tags and temp_tags files.
Args:
tags (str): Tags file name.
temp_tags (str): Temp tags file name.
"""
command = f"rm {tags} {temp_tags}"
subprocess.run(command, shell=True, check=True)


def check_header_file(header_file):
"""
Check if the header file is valid.
Args:
header_file (str): Header file name.
Returns:
bool: True if the header file is valid, False otherwise.
str: Error message if the header file is invalid.
"""
if not header_file.endswith('.h'):

msg = "Error: Invalid header file. It should have a '.h' extension."
return False , msg
return False, msg
return True, None


def autoproto(directory, header):
check1, msg1=check_header_file(header)
check2, msg2=check_ctags()
if (not check1):
print_Ctags_header_error(msg1)
elif (not check2):
print_Ctags_header_error(msg2)
if generate_tags(directory) != False:
filtered_tags = filter_tags(directory, 'tags')
if filtered_tags != None:
create_header(header, filtered_tags)
delete_files('tags', 'temp_tags')
"""
Generate a header file with the prototypes of
the functions in the directory.
Args:
directory (str): Directory path.
header (str): Header file name.
"""
check1, msg1 = check_header_file(header)
check2, msg2 = check_ctags()
if not check1:
print_ctags_header_error(msg1)
elif not check2:
print_ctags_header_error(msg2)
if generate_tags(directory) is not False:
filtered_tags = filter_tags(directory, 'tags')
if filtered_tags is not None:
create_header(header, filtered_tags)
delete_files('tags', 'temp_tags')
25 changes: 18 additions & 7 deletions bettyfixer/backup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import shutil # Add the import statement for shutil
"""
This module provides a function to create a backup copy of a file.
"""
import shutil


def create_backup(file_path):
"""
Create a backup copy of the original file.
Args:
file_path (str): The path of the file to create a backup of.
"""
try:
# Create a backup copy of the original file
backup_path = file_path + '.bak'
shutil.copy2(file_path, backup_path)
except shutil.SameFileError:
print(
f"Err creating backup {file_path}: Src and dest are same file.")
except FileNotFoundError:
print(f"Error creating backup for {file_path}: File not found.")
except Exception as e:
except IsADirectoryError:
print(f"Error creating backup for {file_path}: Is a directory error.")
except PermissionError:
print(f"Error creating backup for {file_path}: Permission error.")
except OSError as e:
print(f"Unexpected error in create_backup for {file_path}: {e}")




Loading
Loading