-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Set up pre-commit hooks and collect documentation files
- Add GitHub Actions workflow for linting code - Update .gitignore to exclude logs directory - Configure pre-commit hooks for code formatting and linting - Refactor main.py: - Extract codebase directory validation to separate function - Implement collect_documentation_files function to gather .md and .txt files - Skip files and directories specified in .gitignore - Add logging and setup logger - Update main function to handle CLI arguments and call collect_documentation_files
- Loading branch information
Showing
4 changed files
with
114 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Lint code | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-20.04 | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.x" | ||
- name: Run pre-commit | ||
uses: pre-commit/[email protected] |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.venv | ||
**/__pycache__ | ||
/.venv | ||
**/__pycache__ | ||
/logs |
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,18 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 24.4.0 | ||
hooks: | ||
- id: black | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort |
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 |
---|---|---|
@@ -1,46 +1,85 @@ | ||
""" 1. The directory path of the codebase to be analyzed | ||
2. The output directory for the generated reports | ||
To implement this step, we'll break it down into smaller tasks: | ||
1. Create a command-line interface (CLI) for the program | ||
2. Prompt the user to enter the codebase directory path | ||
3. Validate the provided codebase directory path | ||
4. Prompt the user to enter the output directory path | ||
5. Validate the provided output directory path | ||
6. Store the user input for later use in the program """ | ||
|
||
import argparse | ||
import os | ||
|
||
from codypy import log_message, setup_logger | ||
from pathspec import PathSpec | ||
|
||
|
||
def validate_codebase_dir(codebase_dir): | ||
if not os.path.exists(codebase_dir): | ||
raise argparse.ArgumentTypeError(f"Codebase directory '{codebase_dir}' does not exist.") | ||
|
||
git_dir = os.path.join(codebase_dir, '.git') | ||
raise argparse.ArgumentTypeError( | ||
f"Codebase directory '{codebase_dir}' does not exist." | ||
) | ||
|
||
git_dir = os.path.join(codebase_dir, ".git") | ||
if not os.path.isdir(git_dir): | ||
raise argparse.ArgumentTypeError(f"Codebase directory '{codebase_dir}' is not a local GitHub repository.") | ||
|
||
raise argparse.ArgumentTypeError( | ||
f"Codebase directory '{codebase_dir}' is not a local GitHub repository." | ||
) | ||
|
||
return codebase_dir | ||
|
||
def main(): | ||
# Create a command-line interface (CLI) for the program | ||
parser = argparse.ArgumentParser(description='CodyArchitect') | ||
parser.add_argument('codebase_dir', type=validate_codebase_dir, help='Path to the codebase directory') | ||
parser.add_argument('--output_dir', '-o', help='Path to the output directory for generated reports') | ||
|
||
# Prompt the user to enter the codebase directory path | ||
args = parser.parse_args() | ||
|
||
# Store the user input for later use in the program | ||
codebase_dir = args.codebase_dir | ||
output_dir = args.output_dir | ||
|
||
|
||
def collect_documentation_files(codebase_dir): | ||
documentation_files = [] | ||
gitignore_path = os.path.join(codebase_dir, ".gitignore") | ||
gitignore_spec = None | ||
|
||
if os.path.exists(gitignore_path): | ||
with open(gitignore_path, "r") as gitignore_file: | ||
gitignore_spec = PathSpec.from_lines("gitwildmatch", gitignore_file) | ||
|
||
for root, dirs, files in os.walk(codebase_dir): | ||
if gitignore_spec: | ||
dirs[:] = [ | ||
d for d in dirs if not gitignore_spec.match_file(os.path.join(root, d)) | ||
] | ||
|
||
for file in files: | ||
file_path = os.path.join(root, file) | ||
if gitignore_spec and gitignore_spec.match_file(file_path): | ||
continue | ||
|
||
if file.endswith(".md") or file.endswith(".txt"): | ||
documentation_files.append(file_path) | ||
|
||
return documentation_files | ||
|
||
|
||
def main(codebase_dir=None, output_dir=None): | ||
if codebase_dir is None: | ||
# Create a command-line interface (CLI) for the program | ||
parser = argparse.ArgumentParser(description="CodyArchitect") | ||
parser.add_argument( | ||
"codebase_dir", | ||
type=validate_codebase_dir, | ||
help="Path to the codebase directory", | ||
) | ||
parser.add_argument( | ||
"--output_dir", | ||
"-o", | ||
help="Path to the output directory for generated reports", | ||
) | ||
|
||
# Prompt the user to enter the codebase directory path | ||
args = parser.parse_args() | ||
|
||
# Store the user input for later use in the program | ||
codebase_dir = args.codebase_dir | ||
output_dir = args.output_dir | ||
|
||
# If the user did not provide an output directory path, create one in the codebase directory | ||
if not output_dir: | ||
output_dir = os.path.join(codebase_dir, '.codyarchitect') | ||
output_dir = os.path.join(codebase_dir, ".codyarchitect") | ||
if not os.path.exists(output_dir): | ||
os.makedirs(output_dir) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
documentation_files = collect_documentation_files(codebase_dir) | ||
log_message("Main: ", f"{documentation_files}") | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
setup_logger("CodyArchitect", "logs") | ||
codebase_dir = "." | ||
main(codebase_dir) |