Skip to content

Commit e87d3dd

Browse files
committed
Merge latest develop
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2 parents ca5a866 + b14ca7b commit e87d3dd

24 files changed

Lines changed: 756 additions & 38 deletions
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: "\U0001F41B License Detection Bug report"
3+
about: Create a Report for a License Detection Bug
4+
title: ''
5+
labels: 'bug', 'license scan', 'new and improved data'
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
Please fill out as much of the below template and delete unnecessary text.
12+
Sample License Detection Bug Reports
13+
- https://github.com/nexB/scancode-toolkit/issues/2126
14+
- https://github.com/nexB/scancode-toolkit/issues/2266
15+
Markdown Styling - https://commonmark.org/help/
16+
-->
17+
18+
### Description
19+
20+
> Please leave a brief description of the License Detection Bug:
21+
22+
23+
### Where to get the File/Package
24+
25+
> Link to Public Repository/Package Index, if there are multiple files that has license detection errors
26+
> Also list some example files. If the bug is in a single file then link to the file.
27+
28+
29+
30+
## Scan Reports
31+
32+
> What scancode command was used?
33+
34+
35+
> Scan Outputs (Preferably of a whole file in [json-pretty-print](https://scancode-toolkit.readthedocs.io/en/latest/cli-reference/output-format.html#json-pp-file))
36+
> Note:-
37+
> If possible please use the `--license-text` and `--license-text-diagonostics` [command line options](https://scancode-toolkit.readthedocs.io/en/latest/cli-reference/basic-options.html#license-text-diagnostics-options)
38+
> as it helps understand which parts were wrongly matched and gives us more insight into the bug
39+
> Upload your results.json file on this issue [like this](https://docs.github.com/en/enterprise/2.16/user/github/managing-your-work-on-github/file-attachments-on-issues-and-pull-requests)
40+
41+
42+
43+
### System/Scancode Configuration
44+
45+
> For bug reports, it really helps us to know:
46+
47+
* What OS are you running on?
48+
> (Windows/MacOS/Linux)
49+
50+
51+
* What version of scancode-toolkit was used to generate the scan file?
52+
> `./scancode --version`
53+
54+
55+
* What installation method was used to install/run scancode?
56+
> (pip/source download/other)
57+
58+
59+
## Links to Rule or excerpts of Rule Texts (If Possible)
60+
61+
> Which Licenses/Rules were wrongly matched (if Applicable)
62+
>
63+
> [Rule Directory](https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules) and [License Directory](https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses)
64+
65+
66+
67+
## Select the Relevant Issue Category(s)
68+
69+
> [ ] - Unselected, [x] - Selected
70+
71+
- [ ] Unknown License
72+
- [ ] False Positive
73+
- [ ] Multiple Detections, Some Wrong
74+
- [ ] License Version Mismatch
75+
- [ ] New License
76+
- [ ] Change in License/Rule Attributes
77+
- [ ] Edit existing Rule
78+
- [ ] From [`scancode-results-analyzer`](https://github.com/nexB/scancode-results-analyzer)
79+
80+
81+
## Comments on the License Detection Bug
82+
83+
> What should have been detected instead, why is it a bug.
84+
85+
86+
87+
## Comments (if any) on How to Add a New Rule/Modify an existing Rule for solving this Bug
88+
89+
> Refer the documentation page at [Add new license](https://scancode-toolkit.readthedocs.io/en/latest/how-to-guides/add_new_license.html) and [Add new rule](https://scancode-toolkit.readthedocs.io/en/latest/how-to-guides/add_new_license_detection_rule.html)
90+
91+
92+
<!--
93+
Your help makes ScanCode Toolkit better! We *deeply* appreciate your help in improving ScanCode Toolkit.
94+
-->

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@ pyvenv.cfg
7979
lib64
8080
tcl
8181
/.env
82+
83+
*.orig

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ v20.x (next)
55
------------
66

77
- Adopt calendar versioning for scancode version numbers
8+
- Updated scancode.bat to handle % signs in the arguments #1876
9+
- Support officially Python 64 bits on Windows 64 bits #335
10+
- Drop support for Python 32 bits on Windows #335
11+
- Update configuration and boostrap scripts
12+
- Drop support for Python 2 #295
13+
814

915

1016
v3.2.3 (2020-10-27)

INSTALL.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Installation
33
============
44

5-
There are 3 main ways you can `install ScanCode <https://scancode-toolkit.readthedocs.io/en/latest/getting-started/install.html>`_.
5+
There are 4 main ways you can `install ScanCode <https://scancode-toolkit.readthedocs.io/en/latest/getting-started/install.html>`_.
66

77
- Installation as an Application: Downloading Releases (Recommended)
8+
- Docker Installation
89
- Installation as a library: via pip
910
- Installation from Source Code: Git Clone
1011

@@ -32,14 +33,30 @@ Installation as an Application : Downloading Releases
3233
- Linux/Mac : ``./scancode --help``
3334
- Windows : ``scancode --help``
3435

36+
Docker Installation
37+
-------------------
38+
39+
#. Download the Source Code as an archive from the `GitHub releases <https://github.com/nexB/scancode-toolkit/releases>`_ and unzip it, or via `git clone`.
40+
41+
#. Build the docker image from the `scancode-toolkit` directory.::
42+
43+
docker build -t scancode-toolkit .
44+
45+
#. Mount current working directory and run scan on mounted folder::
46+
47+
docker run -v $PWD/:/project scancode-toolkit -clpeui --json-pp /project/result.json /project
48+
49+
Note that the parameters *before* ``scancode-toolkit`` are used for docker,
50+
those after will be forwarded to scancode.
51+
3552
Installation as a library: via pip
3653
----------------------------------
3754

3855
#. Create a Python 3.6 Virtual Environment and activate the same::
3956

4057
virtualenv -p /usr/bin/python3.6 venv-scancode && source venv-scancode/bin/activate
4158

42-
#. Run ``pip install scancode-toolkit``
59+
#. Run ``pip install scancode-toolkit[full]``
4360

4461
Installation from Source Code: Git Clone
4562
----------------------------------------

docs/source/contribute/cut_new_release.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ How to cut a new release:
4242
- Run twine with ``twine upload dist/<path to the built wheel>``
4343
- Once uploaded check the published release at https://pypi.python.org/pypi/scancode-toolkit/
4444
- Then create a new fresh local virtualenv and test the wheel installation with:
45-
``pip install scancode-toolkit``
45+
``pip install scancode-toolkit[full]``

docs/source/getting-started/install.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Installation via Docker:
246246
------------------------
247247

248248
You can install Scancode Toolkit by building a Docker image from the included Dockerfile.
249+
The prerequisite is a working `docker installation <https://docs.docker.com/engine/install/>`_.
249250

250251
Download the ScanCode-Toolkit Source Code
251252
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -258,7 +259,7 @@ Build the Docker image
258259
^^^^^^^^^^^^^^^^^^^^^^
259260

260261
The ``docker build`` command needs to run in the directory of the source code,
261-
make sure to ``cd`` into the correct directory.
262+
make sure to ``cd`` into the correct directory.::
262263

263264
cd scancode-toolkit
264265
docker build -t scancode-toolkit .
@@ -268,17 +269,17 @@ Run using Docker
268269

269270
The docker image will forward all arguments it receives directly to the ``scancode`` command.
270271

271-
Display help:
272+
Display help::
272273

273274
docker run scancode-toolkit --help
274275

275-
Mount current working directory and run scan on mounted folder:
276+
Mount current working directory and run scan on mounted folder::
276277

277278
docker run -v $PWD/:/project scancode-toolkit -clpeui --json-pp /project/result.json /project
278279

279280
This will mount your current working from the host into ``/project`` in the container
280281
and then scan the contents. The output ``result.json`` will be written back to your
281-
corrent working directory on the host.
282+
current working directory on the host.
282283

283284
Note that the parameters *before* ``scancode-toolkit`` are used for docker,
284285
those after will be forwarded to scancode.
@@ -361,7 +362,7 @@ For more information on Python virtualenv, visit this `page <https://docs.python
361362

362363
source venv-scancode/bin/activate
363364

364-
#. Run ``pip install scancode-toolkit`` to install the latest version of Scancode.
365+
#. Run ``pip install scancode-toolkit[full]`` to install the latest version of Scancode.
365366

366367
.. NOTE::
367368

docs/source/getting-started/newcomer.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ Before you start using Scancode
8282
is created.
8383

8484
:ref:`app_install`
85+
:ref:`docker_install`
8586
:ref:`pip_install`
8687
:ref:`source_code_install`
8788

8889

8990
#. Now you can either follow the instructions for the recommended :ref:`app_install` method ,
90-
or run ``pip install scancode-toolkit`` like that in the :ref:`pip_install` documentation.
91+
or run ``pip install scancode-toolkit[full]`` like that in the :ref:`pip_install` documentation.
9192
Alternatively, you can also :ref:`source_code_install`.
9293

9394
#. Run ``scancode -h`` to make sure Scancode was installed properly.

docs/source/tutorials/how_to_run_a_scan.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Setting up Scancode Toolkit
3636

3737
Get ScanCode Toolkit from ``pip``::
3838

39-
pip install scancode-toolkit
39+
pip install scancode-toolkit[full]
4040

4141
.. Note::
4242

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
from setuptools import find_packages
1616
from setuptools import setup
1717

18-
version = '20.10.27'
18+
version = '20.12.03'
1919

2020

2121
def read(*names, **kwargs):
2222
import os
2323
return open(
2424
os.path.join(os.path.dirname(__file__), *names),
25-
# encoding=kwargs.get('encoding', 'utf8')
2625
).read()
2726

2827

@@ -123,14 +122,17 @@ def read(*names, **kwargs):
123122
'colorama >= 0.3.9',
124123
'pluggy >= 0.4.0, < 1.0',
125124
'attrs >= 18.1, !=20.1.0',
126-
'typing >=3.6, < 3.7',
125+
# Importing typing causes errors after python 3.6.
126+
# See https://github.com/python/typing/issues/573
127+
'typing >=3.6, < 3.7; python_version < "3.7"',
127128

128129
# scancode outputs
129130
'jinja2 >= 2.7.0, < 3.0.0',
130131
'MarkupSafe >= 0.23',
131132
'simplejson',
132133
'spdx_tools >= 0.6.0',
133134
'unicodecsv',
135+
'jsonstreams >= 0.5.0',
134136

135137
# ScanCode caching and locking
136138
'yg.lockfile >= 2.3, < 3.0.0',

src/formattedcode/output_json.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from collections import OrderedDict
2929

30-
import simplejson
30+
import jsonstreams
3131
from six import string_types
3232

3333
from commoncode.system import py2
@@ -95,8 +95,7 @@ def is_enabled(self, output_json, **kwargs):
9595
return output_json
9696

9797
def process_codebase(self, codebase, output_json, **kwargs):
98-
results = get_results(codebase, as_list=False, **kwargs)
99-
write_json(results, output_file=output_json, pretty=False)
98+
write_results(codebase, output_file=output_json, pretty=False, **kwargs)
10099

101100

102101
@output_impl
@@ -115,33 +114,48 @@ def is_enabled(self, output_json_pp, **kwargs):
115114
return output_json_pp
116115

117116
def process_codebase(self, codebase, output_json_pp, **kwargs):
118-
results = get_results(codebase, as_list=False, **kwargs)
119-
write_json(results, output_file=output_json_pp, pretty=True)
117+
write_results(codebase, output_file=output_json_pp, pretty=True, **kwargs)
120118

121119

122-
def write_json(results, output_file, pretty=False, **kwargs):
120+
def write_results(codebase, output_file, pretty=False, **kwargs):
123121
"""
124-
Write `results` to the `output_file` opened file-like object.
122+
Write headers, files, and other attributes from `codebase` to `output_file`
123+
124+
Enable JSON indentation if `pretty` is True
125125
"""
126-
# NOTE: we write as encoded, binary bytes, not as unicode, decoded text on py2
127-
kwargs = dict(iterable_as_array=True, encoding='utf-8')
126+
# Set indentation for JSON output if `pretty` is True
127+
# We use a separate dict for jsonstream kwargs since we are passing
128+
# this function's kwargs as arguments to OutputPlugin.get_files()
128129
if pretty:
129-
kwargs.update(dict(indent=2 * space))
130+
jsonstreams_kwargs = dict(indent=2, pretty=True)
130131
else:
131-
kwargs.update(dict(separators=(comma, colon,)))
132-
133-
close_of = False
134-
135-
136-
try:
137-
if isinstance(output_file, string_types):
138-
output_file = open(output_file, mode)
139-
close_of = True
140-
output_file.write(simplejson.dumps(results, **kwargs))
141-
output_file.write(eol)
142-
finally:
143-
if close_of:
144-
output_file.close()
132+
jsonstreams_kwargs = dict(indent=None, pretty=False)
133+
134+
# If `output_file` is a path string, open the file at path `output_file` and use it as `output_file`
135+
close_fd = False
136+
if isinstance(output_file, string_types):
137+
output_file = open(output_file, mode)
138+
close_fd = True
139+
140+
# Begin writing JSON to `output_file`
141+
with jsonstreams.Stream(jsonstreams.Type.object, fd=output_file, close_fd=close_fd, **jsonstreams_kwargs) as s:
142+
# Write headers
143+
codebase.add_files_count_to_current_header()
144+
codebase_headers = codebase.get_headers()
145+
s.write('headers', codebase_headers)
146+
147+
# Write attributes
148+
if codebase.attributes:
149+
for attribute_key, attribute_value in codebase.attributes.to_dict().items():
150+
s.write(attribute_key, attribute_value)
151+
152+
# Write files
153+
codebase_files = OutputPlugin.get_files(codebase, **kwargs)
154+
if py3:
155+
# OutputPlugin.get_files() returns a `map()`, which isn's JSON
156+
# serializable in Python 3
157+
codebase_files = list(codebase_files)
158+
s.write('files', codebase_files)
145159

146160

147161
def get_results(codebase, as_list=False, **kwargs):
@@ -169,4 +183,3 @@ def get_results(codebase, as_list=False, **kwargs):
169183
logger_debug(pformat(files))
170184

171185
return results
172-

0 commit comments

Comments
 (0)