scancode-toolkit icon indicating copy to clipboard operation
scancode-toolkit copied to clipboard

Use gentoo licenses as a test data set

Open pombredanne opened this issue 10 years ago • 12 comments

See https://gitweb.gentoo.org/repo/gentoo.git/tree/licenses

pombredanne avatar Aug 22 '16 12:08 pombredanne

@pombredanne I would like to work on in this issue.

vikrant97 avatar Mar 04 '17 07:03 vikrant97

@pombredanne I want to confirm that for this issue I just have to add the gentoo/gentoo/licenses list to the existing data set of aboutcode source code.

vikrant97 avatar Mar 04 '17 07:03 vikrant97

The approach should be

  1. run the license detection on the dataset

  2. for each file that is is not detected 100% there are two cases possible:

2.1 this is a new license: then create a new license. each new license creation should go in its own PR. for new licenses, the key should be all ascii, lowercase. Suggest one with each new license and we can discuss in the PR which would be the best.

2.2 this is a new variant of an existing license: then add a new rule and a test

And each and every file in the dataset should be pushed as a new test in tests/licensedcode/data/licenses

So my suggestion is to start small, one gentoo file at a time, not all at once: otherwise this would be too much work to review at once for us: small bites are best

pombredanne avatar Mar 06 '17 16:03 pombredanne

See https://github.com/nexB/scancode-toolkit/wiki/How-to:-Add-new-license-rules-for-enhanced-detection

For a license the principle is the same, but you need a .yml and .LICENSE file pair for each license.

So see it all in action consider the for instance the files for the apache-1.0 licenses

  • the reference license with its data and text file:

    • data file ass YAML: https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/src/licensedcode/data/licenses/apache-1.0.yml
    • license text: https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/src/licensedcode/data/licenses/apache-1.0.LICENSE
  • example of an additional detection rule for this license:

    • https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/src/licensedcode/data/rules/apache-1.0.RULE
    • https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/src/licensedcode/data/rules/apache-1.0.yml
  • other example of an additional rule for this license:

    • https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/src/licensedcode/data/rules/apache-1.0_1.RULE
    • https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/src/licensedcode/data/rules/apache-1.0_1.RULE
  • and example of a detection test, here detecting two licenses at once:

    • file to test : https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/tests/licensedcode/data/licenses/apache-1.0.txt
    • expected detection results for this file: https://github.com/nexB/scancode-toolkit/blob/06cd94c127b82549382c61d3adec47e930923db1/tests/licensedcode/data/licenses/apache-1.0.yml

See also the FAQ of course https://github.com/nexB/scancode-toolkit/wiki/FAQ

And to put it all in context the internal design of the license detection is document here: https://github.com/nexB/scancode-toolkit/blob/develop/src/licensedcode/README.rst

pombredanne avatar Apr 18 '17 18:04 pombredanne

As you stated i ran the scan(for Zurich Instruments license) with additional arguments and got this as output.

1.https://gist.github.com/aj4ayushjain/d5731fac7fec5581a80ad1130db926fd Which is as expected.So, we should put all license one rule under "Propriertary" key where all the proprietary license will be covered?

2.Regarding the script(data driven framework) for license scan the standarization of this script(for all ) seems tough any suggestion ie each license is stored differently on each website

aj4ayushjain avatar Mar 27 '19 01:03 aj4ayushjain

@aj4ayushjain

  1. you should create a new proprietary license rule for the this Zurich license full text. See the many examples in scancode-toolkit/src/data/rules and submit a PR

  2. I am not sure what you mean but here is a way to craft ~700+ new tests for a start:

  • fetch and copy all the licenses
git clone --depth=10 git://git.gentoo.org/repo/gentoo.git
mv gentoo/licenses/ ~/scancode-toolkit/tests/licensedcode/data/gentoo_licenses/
  • add a txt extension to each license text and create bare .yml expectation file for each license:
cd ~/scancode-toolkit/tests/licensedcode/data/gentoo_licenses/
for f in *
  do
    echo "notes: a license from Gentoo" > $f.yml 
    mv $f $f.txt
  done
  • Edit ``/scancode-toolkit/tests/licensedcode/test_detection_datadriven.py` and add this at the bottom.
class TestsGentooLicensesDataDriven(unittest.TestCase):
    # licenses from gentoo
    pass

build_tests(
    join(TEST_DIR, 'gentoo_licenses'),
    clazz=TestsGentooLicensesDataDriven, regen=True)
  • run these new tests once: py.test -vvs -n4 tests/licensedcode -k TestsGentooLicensesDataDriven

  • remove the regen flag: clazz=TestsGentooLicensesDataDriven, regen=False)

  • review now all the generated yaml expectation files. Eventually rerun detection by hand with the --license-diag and --license-text on each of them if the license is not correctly detected than create new rules and/or update the yml file and/or create new licenses in some cases.

pombredanne avatar Mar 27 '19 11:03 pombredanne

@aj4ayushjain ping? is this something that you are working on or not?

pombredanne avatar Apr 05 '19 15:04 pombredanne

@pombredanne Ping ! I got caught up in writing the gsoc proposal and after 2-3 days i will continue working on this .

aj4ayushjain avatar Apr 06 '19 04:04 aj4ayushjain

As you instructed i created the test file and .yml but running py.test -vvs -n4 tests/licensedcode -k TestsGentooLicensesDataDriven gives error as image Couldn't figure it out.

aj4ayushjain avatar Apr 16 '19 13:04 aj4ayushjain

Each test file needs to have a counterpart YAML data file that contains the test expectations. The convention was to have a test file name.foo with a data file name.yml This has changed since and now we use name.foo with a data file name.foo.yml So the code to create basic empty YAML is out of date and should be:

for f in *
  do
    echo "notes: a license from Gentoo" > $f.txt.yml
    mv $f $f.txt
  done

pombredanne avatar Apr 16 '19 16:04 pombredanne

hi i would like to contribute to this issue. is it available?

dakshaladia avatar Feb 29 '20 11:02 dakshaladia

Great! You can go ahead it's available.

aj4ayushjain avatar Feb 29 '20 12:02 aj4ayushjain