Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: providing_args removal codemod added #413

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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