Skip to content

Commit

Permalink
Removed references to negative value for depth
Browse files Browse the repository at this point in the history
Updated docs, Added trailing comma in cli.py

Signed-off-by: Hanif Ali <alihanif016@gmail.com>
  • Loading branch information
zenocodes committed Jul 28, 2020
1 parent 356f168 commit b0d490c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
11 changes: 3 additions & 8 deletions docs/source/cli-reference/core-options.rst
Expand Up @@ -126,18 +126,13 @@ Comparing Progress Message Options
----------------------------------

Normally, the scan takes place upto the maximum level of nesting of directories possible. But
using the ``--max-depth`` option, the depth of the scan can be limited. This can reduce the time
taken for the scan when deeper directories are not relevant.
using the ``--max-depth`` option, you can specify the maximum level of directories to scan,
including and below the root location. This can reduce the time taken for the scan when deeper
directories are not relevant.

Note that the ``--max-depth`` option will be ignored if you are scanning from a JSON file using
the ``--from-json`` option. In that case, the original depth is used.

Some INTEGER values of the ``--max-depth INTEGER`` option:

- **4** - Scan only upto 4 levels of subdirectories
- **0** - Default, Scan upto maximum levels of subdirectories (no depth limit)
- **-1** - Same effect as when set to 0

An example usage::

scancode -clieu --json-pp results.json samples --max-depth 3
Expand Down
6 changes: 3 additions & 3 deletions docs/source/rst_snippets/core_options.rst
Expand Up @@ -24,9 +24,9 @@ All "Core" Scan Options
and disable on-disk caching. Use -1 to use
only on-disk caching. [Default: 10000]

--max-depth INTEGER Maximum nesting of subdirectories to scan.
Positive value indicates a fixed depth of scan
while a negative value means no depth limit.
--max-depth INTEGER Descend at most INTEGER levels of directories
including and below the starting point. INTEGER
must be positive or zero for no limit.
[Default: 0]

.. include:: /rst_snippets/note_snippets/core_indep.rst
2 changes: 1 addition & 1 deletion src/scancode/cli.py
Expand Up @@ -877,7 +877,7 @@ def echo_func(*_args, **_kwargs):
full_root=full_root,
strip_root=strip_root,
max_in_memory=max_in_memory,
max_depth=max_depth
max_depth=max_depth,
)
except:
msg = 'ERROR: failed to collect codebase at: %(input)r' % locals()
Expand Down
15 changes: 5 additions & 10 deletions src/scancode/resource.py
Expand Up @@ -138,17 +138,12 @@ def depth_walk(root_location, max_depth, skip_ignored=lambda x: False, error_han
# Find root directory depth using path separator's count
root_dir_depth = root_location.count(os.path.sep)

# Default behaviour. current_depth is always less than max_depth so that
# os_walk keeps running. When max_depth is limited, the current_depth is
# changed in each iteration and compared with max_depth
current_depth = -2

for top, dirs, files in os_walk(root_location, topdown=True, onerror=error_handler):
# If depth is limited
if max_depth > 0:
# If depth is limited (non-zero)
if max_depth:
current_depth = top.count(os.path.sep) - root_dir_depth

if skip_ignored(top) or current_depth >= max_depth:
if skip_ignored(top) or (max_depth and current_depth >= max_depth):
# we clear out `dirs` and `files` to prevent `os_walk` from visiting
# the files and subdirectories of directories we are ignoring or
# are not in the specified nesting level
Expand Down Expand Up @@ -285,8 +280,8 @@ def __init__(self, location,
memory. Beyond this number, Resource are saved on disk instead. -1 means
no memory is used and 0 means unlimited memory is used.
`max_depth` is the maximum level of nesting of subdirectories that the
scan will go. A value of 0 or negative means no limit.
`max_depth` is the maximum depth of subdirectories to descend below and
including `location`.
"""
self.original_location = location
self.full_root = full_root
Expand Down

0 comments on commit b0d490c

Please sign in to comment.