Skip to content

Commit

Permalink
Merge pull request #23 from kirill-markin/refactoring/cleanup
Browse files Browse the repository at this point in the history
Refactoring/cleanup
  • Loading branch information
kirill-markin authored Dec 17, 2024
2 parents 0cba359 + 4d99a1a commit 1817078
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 278 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.8", "3.11", "3.13"]

steps:
- uses: actions/checkout@v4
Expand All @@ -28,6 +28,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Run pylint
run: |
pylint repo_to_text
- name: Run tests
run: |
pytest tests/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ To install `repo-to-text` locally for development, follow these steps:
2. Install the package with development dependencies:

```bash
pip install -e .[dev]
pip install -e ".[dev]"
```

### Requirements
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "repo-to-text"
version = "0.5.3"
version = "0.5.4"
authors = [
{ name = "Kirill Markin", email = "[email protected]" },
]
Expand Down Expand Up @@ -41,4 +41,10 @@ dev = [
"isort",
"build",
"twine",
"pylint",
]

[tool.pylint]
disable = [
"C0303",
]
2 changes: 2 additions & 0 deletions repo_to_text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""This is the main package for the repo_to_text package."""

__author__ = 'Kirill Markin'
__email__ = '[email protected]'
4 changes: 3 additions & 1 deletion repo_to_text/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""This module contains the CLI interface for the repo_to_text package."""

from .cli import create_default_settings_file, parse_args, main

__all__ = ['create_default_settings_file', 'parse_args', 'main']
__all__ = ['create_default_settings_file', 'parse_args', 'main']
41 changes: 30 additions & 11 deletions repo_to_text/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
CLI for repo-to-text
"""

import argparse
import textwrap
import os
Expand All @@ -12,8 +16,11 @@ def create_default_settings_file() -> None:
"""Create a default .repo-to-text-settings.yaml file."""
settings_file = '.repo-to-text-settings.yaml'
if os.path.exists(settings_file):
raise FileExistsError(f"The settings file '{settings_file}' already exists. Please remove it or rename it if you want to create a new default settings file.")

raise FileExistsError(
f"The settings file '{settings_file}' already exists. "
"Please remove it or rename it if you want to create a new default settings file."
)

default_settings = textwrap.dedent("""\
# Details: https://github.com/kirill-markin/repo-to-text
# Syntax: gitignore rules
Expand All @@ -32,7 +39,7 @@ def create_default_settings_file() -> None:
- "README.md"
- "LICENSE"
""")
with open('.repo-to-text-settings.yaml', 'w') as f:
with open('.repo-to-text-settings.yaml', 'w', encoding='utf-8') as f:
f.write(default_settings)
print("Default .repo-to-text-settings.yaml created.")

Expand All @@ -42,13 +49,25 @@ def parse_args() -> argparse.Namespace:
Returns:
argparse.Namespace: Parsed command line arguments
"""
parser = argparse.ArgumentParser(description='Convert repository structure and contents to text')
parser = argparse.ArgumentParser(
description='Convert repository structure and contents to text'
)
parser.add_argument('input_dir', nargs='?', default='.', help='Directory to process')
parser.add_argument('--debug', action='store_true', help='Enable debug logging')
parser.add_argument('--output-dir', type=str, help='Directory to save the output file')
parser.add_argument('--create-settings', '--init', action='store_true', help='Create default .repo-to-text-settings.yaml file')
parser.add_argument(
'--create-settings',
'--init',
action='store_true',
help='Create default .repo-to-text-settings.yaml file'
)
parser.add_argument('--stdout', action='store_true', help='Output to stdout instead of a file')
parser.add_argument('--ignore-patterns', nargs='*', help="List of files or directories to ignore in both tree and content sections. Supports wildcards (e.g., '*').")
parser.add_argument(
'--ignore-patterns',
nargs='*',
help="List of files or directories to ignore in both tree and content sections. "
"Supports wildcards (e.g., '*')."
)
return parser.parse_args()

def main() -> NoReturn:
Expand All @@ -60,7 +79,7 @@ def main() -> NoReturn:
args = parse_args()
setup_logging(debug=args.debug)
logging.debug('repo-to-text script started')

try:
if args.create_settings:
create_default_settings_file()
Expand All @@ -72,9 +91,9 @@ def main() -> NoReturn:
to_stdout=args.stdout,
cli_ignore_patterns=args.ignore_patterns
)

logging.debug('repo-to-text script finished')
sys.exit(0)
except Exception as e:
logging.error(f'Error occurred: {str(e)}')
sys.exit(1)
except (FileNotFoundError, FileExistsError, PermissionError, OSError) as e:
logging.error('Error occurred: %s', str(e))
sys.exit(1)
4 changes: 3 additions & 1 deletion repo_to_text/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""This module contains the core functionality of the repo_to_text package."""

from .core import get_tree_structure, load_ignore_specs, should_ignore_file, save_repo_to_text

__all__ = ['get_tree_structure', 'load_ignore_specs', 'should_ignore_file', 'save_repo_to_text']
__all__ = ['get_tree_structure', 'load_ignore_specs', 'should_ignore_file', 'save_repo_to_text']
Loading

0 comments on commit 1817078

Please sign in to comment.