Skip to content

Add is_notice flag to the --classify option #3822 #4142

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

aayushkdev
Copy link
Contributor

@aayushkdev aayushkdev commented Feb 11, 2025

Fixes #3822

Added is_notice flag to --classify for detecting package notice files

The --classify option now includes an is_notice flag to help identify package notice files. Currently, detection is based only on file names.

  • Recognizes key legal files with "notice" in their lowercase file name.
  • Updated documentation.
  • Added tests to verify the changes.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁
  • Updated documentation pages (if applicable)
  • Updated CHANGELOG.rst (if applicable)

@aayushkdev aayushkdev closed this Feb 11, 2025
@aayushkdev aayushkdev force-pushed the 3822-add-is_notice-flag-classify branch from 49e93f0 to a9f7ed3 Compare February 11, 2025 13:33
@aayushkdev aayushkdev reopened this Feb 11, 2025
@aayushkdev aayushkdev force-pushed the 3822-add-is_notice-flag-classify branch 5 times, most recently from ba6181f to f8eed11 Compare February 15, 2025 16:31
Copy link
Member

@AyanSinhaMahapatra AyanSinhaMahapatra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks++ @aayushkdev see review comments for your consideration, this is looking great otherwise.

@@ -64,6 +64,17 @@ def test_set_classification_flags_is_package_data_file(self):
set_classification_flags(res)
assert res.is_manifest


def test_set_classification_flags_is_notice(self):
test_dir = self.get_test_loc('classify/notice')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add another test for package_NOTICE in an example here as mentioned in #3822 (comment) (please always read the original issue and all the comments there carefully for more details), I don't think we are getting this logic correctly yet here. This could also be an issue in how we determine the is_legal flag, nevertheless it would be nice to also address this in the PR.

Copy link
Contributor Author

@aayushkdev aayushkdev Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I’ve added package_NOTICE.txt in the test, but just a quick note: the comment example used the Resource class, which caused check_resource_name_start_and_end to return false. However, the is_legal and is_notice checks use ScannedResource from the Codebase class, which works as expected and returns true for notice files with an extension, the tests that I have added also work for notice files with an extension.

That said, if I’m mistaken in my approach, I’m happy to go ahead and add the suggested tests just need a clarification on this.

@@ -334,7 +334,7 @@ def tally_codebase_key_files(codebase, field='tallies', **kwargs):
# filter to get only key files
key_files = (res for res in codebase.walk(topdown=True)
if (res.is_file and res.is_top_level
and (res.is_readme or res.is_legal or res.is_manifest)))
and (res.is_readme or res.is_legal or res.is_manifest or res.is_notice)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? doesn't is_legal includes is_notice too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right I have removed it, that was an oversight from me

@@ -1934,6 +1934,7 @@ files:
is_readme: no
is_top_level: yes
is_key_file: no
is_notice: no
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find any example of is_notice: True in any of the tests here. Could you add a NOTICE file somewhere in the full scancode scan tests so we can test for this?

Copy link
Contributor Author

@aayushkdev aayushkdev Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be mistaken, but from what I understand, the formattedcode tests are designed to scan only code files, not key files. and since there are no existing test cases for key files within formattedcode, I have not added a test case there.

but I have added a new test for notice in multiple_package_data in summarycode as there was no testcase there for notice

@aayushkdev aayushkdev force-pushed the 3822-add-is_notice-flag-classify branch 2 times, most recently from 1e892b7 to fa3961e Compare April 6, 2025 12:22
@aayushkdev aayushkdev force-pushed the 3822-add-is_notice-flag-classify branch from fa3961e to a7b5827 Compare April 6, 2025 13:00
@aayushkdev
Copy link
Contributor Author

aayushkdev commented Apr 6, 2025

Hey @AyanSinhaMahapatra these failed tests pass on my system I don't think their failing has to do anything with the pr.

also please let me know if there are any other changes you would like me to make in the pr.
thanks

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.

Add is_notice flag to the --classify option
2 participants