{"id":21651806,"url":"https://github.com/dev-vivekkumarverma/tree-shaking-and-dead-code-eliminator-using-ast","last_synced_at":"2026-05-20T10:44:48.950Z","repository":{"id":230349363,"uuid":"779146609","full_name":"dev-vivekkumarverma/Tree-Shaking-and-Dead-Code-Eliminator-using-AST","owner":"dev-vivekkumarverma","description":"Tree-shacking and Dead-code elimination using Abstract Syntax Tree (AST) in python.","archived":false,"fork":false,"pushed_at":"2024-03-29T06:26:28.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T04:00:06.796Z","etag":null,"topics":["abstract-syntax-tree","dead-code-elimination","project-cleaner","python","python3","tree-shaking"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev-vivekkumarverma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-29T06:25:32.000Z","updated_at":"2024-06-21T10:16:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"ad5b2626-4e05-46f5-8a80-86a41621061e","html_url":"https://github.com/dev-vivekkumarverma/Tree-Shaking-and-Dead-Code-Eliminator-using-AST","commit_stats":null,"previous_names":["dev-vivekkumarverma/ast-python-","dev-vivekkumarverma/tree-shaking-and-dead-code-eliminator-using-ast"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2FTree-Shaking-and-Dead-Code-Eliminator-using-AST","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2FTree-Shaking-and-Dead-Code-Eliminator-using-AST/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2FTree-Shaking-and-Dead-Code-Eliminator-using-AST/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2FTree-Shaking-and-Dead-Code-Eliminator-using-AST/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-vivekkumarverma","download_url":"https://codeload.github.com/dev-vivekkumarverma/Tree-Shaking-and-Dead-Code-Eliminator-using-AST/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244547602,"owners_count":20470103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-syntax-tree","dead-code-elimination","project-cleaner","python","python3","tree-shaking"],"created_at":"2024-11-25T07:49:36.925Z","updated_at":"2026-05-20T10:44:48.910Z","avatar_url":"https://github.com/dev-vivekkumarverma.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Modifying Import Statements Using AST\n\n## About the Project\n\nThis project aims to automate the modification of import statements in multiple Python projects that share common utility files. Often, when deploying individual projects, it's preferable to include utility files within each project rather than sharing a common utility folder. This tool facilitates this process by modifying import statements to reference utility files within the project itself.\n\nThe tool is implemented using the Abstract Syntax Tree (AST) module in Python, along with the `os` and `shutil` modules for file manipulation.\n\n## How It Works\n\nThe tool traverses through the Python source files of each project and identifies import statements using the AST module. It then modifies import statements that reference utility files from a shared folder to instead reference utility files present within the project itself. This ensures that each project maintains its own copy of utility files and does not rely on a shared folder during deployment.\n\nHere's a brief overview of how the tool works:\n\n```python\nimport os\nimport shutil\nimport ast\n\n# Define function to process each Python file\ndef process_file(path: str, filename: str) -\u003e tuple:\n    # Implement processing logic here...\n\n# Iterate over files in the directory and process each Python file\nfor root, dirs, files in os.walk(\"./\"):\n    for filename in files:\n        if not root.startswith(\"./proj\"):\n            continue\n        is_error, result = process_file(root, filename)\n        if is_error:\n            print(f\"ERROR: {result}\")\n            break\n        else:\n            print(f\"RESULT: {os.path.join(root, filename)} - {result}\")\n\n```\n\n## How to Use\n\n1. **Clone the Repository**: Clone or download this repository to your local machine.\n2. **Folder Structure**: Ensure your project folder structure follows the layout described below:\n   ```\n   root\n   ├── proj1\n   │   └── main.py\n   ├── proj2\n   │   └── main.py\n   ├── projN\n   │   └── main.py\n   ├── utility\n   │   ├── file1.py\n   │   └── file2.py\n   ├── build.ipynb\n   └── Working with AST.py\n   ```\n3. **Run the Script**: Navigate to the root folder where all the projects are located. Run the `build.ipynb` Jupyter notebook or the `Working with AST.py` Python script.\n4. **View Results**: After execution, check the modified Python source files in each project folder to verify that the import statements have been updated correctly.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-vivekkumarverma%2Ftree-shaking-and-dead-code-eliminator-using-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-vivekkumarverma%2Ftree-shaking-and-dead-code-eliminator-using-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-vivekkumarverma%2Ftree-shaking-and-dead-code-eliminator-using-ast/lists"}