Skip to content

Commit

Permalink
fix: providing_args removal codemod added (openedx#413)
Browse files Browse the repository at this point in the history
Co-authored-by: Usama Sadiq <usama.sadiq@arbisoft.com>
  • Loading branch information
zubairshakoorarbisoft and UsamaSadiq authored Aug 9, 2023
1 parent 77c249d commit 3c0180b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions edx_repo_tools/codemods/django42/remove_providing_args_arg.py
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()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def is_requirement(line):
'tag_release = edx_repo_tools.release.tag_release:main',
'modernize_tox_django42 = edx_repo_tools.codemods.django42.tox_moderniser_django42:main',
'modernize_github_actions_django42 = edx_repo_tools.codemods.django42.github_actions_modernizer_django42:main',
'remove_providing_args = edx_repo_tools.codemods.django42.remove_providing_args_arg:main',
],
},
package_data={
Expand Down

0 comments on commit 3c0180b

Please sign in to comment.