Package: python-code-outline
Python Code Structure Report GeneratorThis Python script generates a text-based report of the code structure for all Python files in a given folder. It's useful for getting a quick overview of the code structure of a Python project. This can be particularly helpful for ChatGPT/Large Language Model (LLM) applications where you need to ask high-level questions about your codebase.Example ReportUsageTo use this script, run thepython_report_generator.pyfile and provide the path to the folder containing the Python files you want to analyze. You can also optionally specify a name for the report file, which defaults toreport.txtif not provided, and a path to the ignore file. The ignore file should be a.gitignorefile or a file with the same format as a.gitignorefile. If provided, the script will parse the ignore patterns from the file and exclude the matching files and folders from the report.pythonpython_code_outline/python_report_generator.py/path/to/folder--report_file_pathcustom_report.txt--ignore_file_path/path/to/folder/.gitignoreIf the--report_file_pathoption is not specified, the report will be written toreport.txtby default.pythonpython_code_outline/python_report_generator.py/path/to/folderUsage as a pip moduleAfter installing the package via pip, you can import and use the functionality in your own code as well. For example:""" Generate a report of the python code outline of a folder. """frompython_code_outlineimportget_report# Define the root folderROOT_FOLDER="/path/to/folder"# Specify the report and ignore file paths (optional)REPORT_FILE_PATH="custom_report.txt"IGNORE_FILE_PATH="/path/to/folder/.gitignore"# Generate the reportREPORT=python_report_generator.get_report(ROOT_FOLDER,IGNORE_FILE_PATH)# Write the report to a filewithopen(REPORT_FILE_PATH,"w",encoding="utf-8")asfile:file.write(REPORT)print(f"Report generated successfully to{REPORT_FILE_PATH}.")Please replace "/path/to/folder" with the path to the folder you want to analyze, and update the report and ignore file paths as necessary.OutputThe script will generate a text-based report of the code structure for each Python file in the specified folder. The report includes information about imports, classes, functions, and variables in each file.Optional Parameters--report_file_path: The name of the report file. Defaults toreport.txtif not provided.--ignore_file_path: The path to the ignore file. If provided, the script will parse the ignore patterns from the file and exclude the matching files and folders from the report.RequirementsThis script requires Python 3.x to run.InstallationThis project usesPoetryfor dependency management. To install the dependencies, first install Poetry by following theofficial installation guide, and then run the following command in the project directory:poetryinstallThis will create a virtual environment and install the required dependencies.You can install this module using pip:pipinstallpython-code-outlineor with poetrypoetryaddpython-code-outlineThis command will download the package from PyPI and install it in your current Python environment.Running TestsThis project usespytestfor testing. To run the tests, first activate the virtual environment created by Poetry:poetryshellThen, run the tests using the following command:pytestChecking Test CoverageThis project uses thepytest-covpackage to generate test coverage reports. Here's how to use it:First, you need to install thepytest-covpackage if it's not already installed.pipinstallpytest-covorpoetryaddpytest-covIf you're using Poetry, you can also addpytest-covto yourpyproject.tomlfile and runpoetry installto install it.After installingpytest-cov, you can use it to run your tests and collect coverage data. If you're usingpytestfor testing, you can use the following command:pytest--cov=python_code_outlineThis command tellspytestto collect coverage data for thepython_code_outlinemodule during the test run.Once you've collected coverage data, you can generate a report by running:coveragereportThis will print a coverage report to the terminal, showing the code coverage for each module in your project.If you want a more detailed view, you can generate an HTML report using:coveragehtmlThis will generate anhtmlcovdirectory in your project directory. Inside this directory, you'll find anindex.htmlfile. You can open this file in a web browser to view a detailed coverage report that shows which lines of each file were covered by the tests.If you're finished checking coverage and want to clear the collected data, you can use the command:coverageeraseThis will delete the.coveragedata file, clearing the collected coverage data.Remember that code coverage is a useful tool for finding untested parts of your code, but achieving 100% code coverage doesn't necessarily mean your testing is perfect. It's important to write meaningful tests and not just strive for high coverage percentages.ContributingContributions are welcome! Please feel free to submit a pull request or open an issue on theGitHub repository.LicenseThis project is licensed under the MIT License. See theLICENSEfile for details.