diff --git a/.github/workflows/tag-and-release.yml b/.github/workflows/tag-and-release.yml index 2b7257a..7e134cd 100644 --- a/.github/workflows/tag-and-release.yml +++ b/.github/workflows/tag-and-release.yml @@ -8,6 +8,8 @@ on: jobs: tag-and-release: runs-on: ubuntu-latest + outputs: + new_version: ${{ steps.bump_version.outputs.NEW_VERSION }} steps: - name: Checkout uses: actions/checkout@v3 @@ -76,9 +78,8 @@ jobs: python -m pip install --upgrade pip pip install build - name: Build package + env: + PACKAGE_VERSION: ${{ needs.tag-and-release.outputs.new_version }} run: python -m build - name: Publish package - uses: pypa/gh-action-pypi-publish@v1.9.0 - # with: - # user: ${{ secrets.PYPI_PASSWORD }} - # password: ${{ secrets.PYPI_PASSWORD }} \ No newline at end of file + uses: pypa/gh-action-pypi-publish@v1.9.0 \ No newline at end of file diff --git a/code_collator/collate.py b/code_collator/collate.py index 6e8f0de..e69110c 100644 --- a/code_collator/collate.py +++ b/code_collator/collate.py @@ -12,6 +12,7 @@ def setup_logging(): force=True ) + def is_binary_file(filepath): """Check if a file is binary.""" try: @@ -22,6 +23,7 @@ def is_binary_file(filepath): logging.error("Error reading file %s: %s", filepath, e) return False + def read_gitignore(path): """Read the .gitignore file and return patterns to ignore.""" gitignore_path = os.path.join(path, '.gitignore') @@ -45,6 +47,7 @@ def should_ignore(file_path, ignore_patterns): return True return any(fnmatch(file_path, pattern) for pattern in ignore_patterns) + def collate_codebase(path, output_file): """Aggregate the codebase into a single Markdown file.""" ignore_patterns = read_gitignore(path) @@ -57,7 +60,7 @@ def collate_codebase(path, output_file): if should_ignore(file_path, ignore_patterns): logging.info("Ignored file %s", file_path) continue - + output.write(f"## {file_path}\n\n") is_binary = is_binary_file(file_path) logging.info("File %s is binary: %s", file_path, is_binary) @@ -76,19 +79,27 @@ def collate_codebase(path, output_file): logging.info("Collated codebase written to %s", output_file) except Exception as e: logging.error("Error writing to output file %s: %s", output_file, e) - + + def main(): """Parse arguments and initiate codebase collation.""" setup_logging() parser = argparse.ArgumentParser(description="Aggregate codebase into a single Markdown file.") - parser.add_argument('-p', '--path', type=str, default='.', help="Specify the path to the codebase directory (default: current directory)") - parser.add_argument('-o', '--output', type=str, default='collated-code.md', help="Specify output file (default: collated-code.md)") - + parser.add_argument( + '-p', + '--path', + type=str, + default='.', + help="Specify the path to the codebase directory (default: current directory)") + parser.add_argument('-o', '--output', type=str, default='collated-code.md', + help="Specify output file (default: collated-code.md)") + args = parser.parse_args() - + logging.info("Starting code collation for directory: %s", args.path) collate_codebase(args.path, args.output) logging.info("Code collation completed.") + if __name__ == "__main__": main() diff --git a/setup.py b/setup.py index d5b3b1e..0c4dbf3 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,12 @@ from setuptools import setup, find_packages import pathlib -import subprocess +import os here = pathlib.Path(__file__).parent.resolve() def get_version(): - try: - version = subprocess.check_output(['git', 'describe', '--tags', '--always']).decode().strip() - return version.lstrip('v') - except subprocess.CalledProcessError: - return '0.0.0' + version = os.environ.get('PACKAGE_VERSION', '0.0.0') + return version setup( name="code-collator",