Skip to content

Fix greedy regex in BR removal, alignment detection, and subdirectory license matching#14

Open
Shrey-N wants to merge 7 commits intohroncok:mainfrom
Shrey-N:patch-1
Open

Fix greedy regex in BR removal, alignment detection, and subdirectory license matching#14
Shrey-N wants to merge 7 commits intohroncok:mainfrom
Shrey-N:patch-1

Conversation

@Shrey-N
Copy link
Copy Markdown
Contributor

@Shrey-N Shrey-N commented Mar 29, 2026

This PR addresses edge case bugs discovered:

  • Fix greedy regex in remove_setuptools_br:

    • Bug: The rich regex \({setuptools}\s+.+\) was too greedy. It could swallow subsequent parenthesis blocks, unintentionally deleting other dependencies on the same BuildRequires line.
    • Fix: Replaced .+ with [^)]+ to ensure the match stops at the very next closing parenthesis.
  • Fix empty tag handling in alignment_of:

    • Bug: The tag_re regex required a non space character (\S) at the end of the line. alignment_of failed on tags with trailing spaces but no value (e.g., Name: \n), causing messy specfile formatting during substitutions like %py_provides.
    • Fix: Dropped the trailing \S requirement, allowing the alignment logic to capture spacing for empty tags.
  • Improve %license detection for files in subdirectories (add_pyproject_files):

    • Bug: The fnmatch logic originally matched against the entire token path. If an RPM utilized something like %license XwhyZ-3.2.1/LICENSE, it would fail the glob match against LICEN[CS]E* and wouldn't append the -l flag to %pyproject_save_files.
    • Fix: Now matches the pattern against token.split("/")[-1] (the basename of the file), correctly identifying licenses inside standard subdirectories.

@hroncok
Copy link
Copy Markdown
Owner

hroncok commented Mar 29, 2026

I'm not sure about the lice se fix. That would only work if the macros are called from within a subdirectory. Can we detect that?

@Shrey-N
Copy link
Copy Markdown
Contributor Author

Shrey-N commented Mar 29, 2026

Point we can detect that by scanning the %install section for pushd / cd commands occurring before the %pyproject_install call.
I will update the logic to only use the basename for licenses when we're inside that subdirectory context. Otherwise, we'll stay conservative and only move top level licenses to -l.

@Shrey-N
Copy link
Copy Markdown
Contributor Author

Shrey-N commented Mar 29, 2026

I updated license detection to be context aware by scanning for pushd/cd in %install.

Also now includes fixes for:

Shrey-N added 3 commits March 29, 2026 22:34
Refactor macro handling by introducing _find_macro_end function to improve readability and maintainability.
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

Successfully merging this pull request may close these issues.

2 participants