forked from openedx/repo-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: providing_args removal codemod added (openedx#413)
Co-authored-by: Usama Sadiq <usama.sadiq@arbisoft.com>
- Loading branch information
1 parent
77c249d
commit 3c0180b
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
edx_repo_tools/codemods/django42/remove_providing_args_arg.py
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,46 @@ | ||
import os | ||
import re | ||
import click | ||
|
||
def remove_providing_args(root_dir): | ||
# Regex pattern to match the lines containing providing_args | ||
pattern = r"(.*)[,\s]*providing_args\s*=\s*\[.*?\](.*)" | ||
|
||
# Traverse all Python files in the root directory | ||
for root, _, files in os.walk(root_dir): | ||
for file in files: | ||
if file.endswith(".py"): | ||
file_path = os.path.join(root, file) | ||
updated_lines = [] | ||
|
||
# Open the file and read its content | ||
with open(file_path, "r") as f: | ||
lines = f.readlines() | ||
|
||
# Process each line in the file | ||
for line in lines: | ||
# Check if the line contains providing_args | ||
match = re.match(pattern, line) | ||
if match: | ||
# Remove the providing_args argument along with any preceding comma or whitespace | ||
updated_line = match.group(1).rstrip(", \t") + match.group(2) + "\n" | ||
updated_lines.append(updated_line) | ||
else: | ||
updated_lines.append(line) | ||
|
||
# Write the updated content back to the file | ||
with open(file_path, "w") as f: | ||
f.writelines(updated_lines) | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
'--root_dir', default='.', | ||
help="Path to root of project") | ||
def main(root_dir): | ||
remove_providing_args(root_dir) | ||
print("Providing_args removed from the specified lines.") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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