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

License Header Not Updating or Removing Properly #2360

Open
atakanny opened this issue Feb 19, 2025 · 0 comments
Open

License Header Not Updating or Removing Properly #2360

atakanny opened this issue Feb 19, 2025 · 0 comments

Comments

@atakanny
Copy link

When running update_license_header.py, some files that already have a license header are not being updated or removed as expected. The script is supposed to replace existing license headers with the new one or remove them if the --delete flag is used. However, in certain cases, the header remains unchanged.

Steps to Reproduce:

Run the script on a directory containing files with an existing license header:

python update_license_header.py -d ./test_directory

Check the modified files. Some files retain the old license header instead of getting updated.

Run the script with the --delete flag:

python update_license_header.py -d ./test_directory --delete

Observe that in some files, the license header is not removed.

Expected Behavior:

The script should replace any existing license header with the new one.

When using --delete, the license header should be completely removed.

Actual Behavior:

Some files do not have their license headers updated or removed as expected.

Possible Cause:

The regex pattern used to match existing headers may not correctly capture all variations of the license header format.

re.sub() might not be correctly modifying the file content in all cases.

Suggested Fix:

Improve the regex pattern to handle different variations of the license header more effectively:

pattern = re.compile(
r'(["']{3}|/[])\n(*)~.?~(*)\n(["']{3}|[]/)(\r\n|\r|\n)',
re.DOTALL | re.MULTILINE
)

Ensure re.sub() correctly modifies the content by checking the result before writing it back to the file.

Environment:

OS: [e.g., Ubuntu 22.04, Windows 10]

Python version: [e.g., 3.8, 3.10]

Script version: [commit hash or version number if applicable]

Additional Information:Any additional details, logs, or related issues can be added here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant