Skip to content

Commit

Permalink
Don't consider files that MATLAB wouldn't
Browse files Browse the repository at this point in the history
In project mode, further exclude files that would not be considered
by MATLAB.
  • Loading branch information
florianschanda committed Nov 18, 2020
1 parent 54422a1 commit 1c676f8
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 12 deletions.
52 changes: 52 additions & 0 deletions docs/cli.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,58 @@ <h3>Project mode</h3>
directories/files you're responsible for.
</div>

<div>
Please note that MISS_HIT will <i>not</i> consider files and
directories that would be invisible to MATLAB in project
mode. Consider for example a projet layout like this:
<pre>
/
miss_hit.cfg
file1.m
foo/
file2.m
+bar/
file3.m
</pre>
</div>

<div>
The configuration file contains the following information:
<pre>entrypoint "Potato" {}</pre>
</div>

<div>
When running MISS_HIT without project mode, all files are
considered. However, when running MISS_HIT in project mode,
only files <tt>file1.m</tt> and <tt>file3.m</tt> are
considered. File <tt>file2.m</tt> is not considered because
directory <tt>foo</tt> is not on the path, as declared in our
entrypoint.
</div>

<div>
If you want to include <tt>file2.m</tt> in your analysis, then
you have to include that directory in your entry point, like
so:
<pre>
entrypoint "Potato" {
paths {
".",
"foo"
}
}
</pre>
</div>

<div>
This behaviour is consistent with how MATLAB deals with its
search path. For more information consult:
<ul>
<li><a href="https://www.mathworks.com/help/matlab/matlab_env/files-and-folders-that-matlab-accesses.html"><img src="assets/external-link.svg"> Files and Folders that MATLAB Accesses</a></li>
<li><a href="https://www.mathworks.com/help/matlab/matlab_oop/organizing-classes-in-folders.html"><img src="assets/external-link.svg"> Folders Containing Class Definitions</a></li>
</ul>
</div>

<h3>Common options</h3>
<div>
All MISS_HIT tools (except mh_diff) have these options. Some
Expand Down
44 changes: 32 additions & 12 deletions miss_hit_core/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,30 +221,50 @@ def execute(mh, options, extra_options, back_end, process_slx=True):
"not exist." %
options.entry_point)

# Get PATH
item_list = n_ep.get_path()

if options.debug_show_path:
print("Using the following PATH:")
for path in n_ep.get_path():
for path in item_list:
print("> %s" % os.path.relpath(path))

item_list = n_ep.get_path()

# If the user has supplied files/dirs to analyze, we only
# do that if they are part of _this_ entrypoint.
if options.files:
items_in_path = set()
for path_root in item_list:
for path, _, files in os.walk(path_root):
items_in_path.add(os.path.normpath(path))
for f in files:
items_in_path.add(
# Determine relevant files based on these
# directories. This is a bit more complex than
# "everything".
#
# See
# https://www.mathworks.com/help/matlab/matlab_env/files-and-folders-that-matlab-accesses.html

items_in_path = set()
files_in_path = set()
for path_root in item_list:
for path, dirs, files in os.walk(path_root):
items_in_path.add(os.path.normpath(path))
for f in files:
if f.endswith(".m") or f.endswith(".slx"):
files_in_path.add(
os.path.normpath(os.path.join(path, f)))
irrelevant_dirs = set(d for d in dirs
if not (d.startswith("+") or
d.startswith("@")))
for idir in irrelevant_dirs:
dirs.remove(idir)
items_in_path |= files_in_path

if options.files:
# If the user has supplied files/dirs to analyze, we
# only do that if they are part of _this_ entrypoint.
item_list = list(options.files)
for item in item_list:
if os.path.abspath(item) not in items_in_path:
mh.command_line_error("'%s' is not part of "
"entry point %s" %
(item, options.entry_point))
else:
# Otherwise we look at all applicable files on the
# path.
item_list = list(sorted(files_in_path))

else:
# Without an entry point, we build a minimally sufficient
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/projects/irrelevant/+good/irrelevant/bad.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if just ++ not ++ matlab
1 change: 1 addition & 0 deletions tests/projects/irrelevant/@thing/irrelevant/bad.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if just ++ not ++ matlab
Empty file.
9 changes: 9 additions & 0 deletions tests/projects/irrelevant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
When using an entry-point, we should not pick up files from our path
that MATLAB wouldn't pick up either.

See:
* https://www.mathworks.com/help/matlab/matlab_env/files-and-folders-that-matlab-accesses.html
* https://www.mathworks.com/help/matlab/matlab_oop/organizing-classes-in-folders.html

Specifically if a subdirectory not starting with + or @ is in a
directory on the path, we do not consider it.
1 change: 1 addition & 0 deletions tests/projects/irrelevant/cmdline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--entry-point=potato
1 change: 1 addition & 0 deletions tests/projects/irrelevant/irrelevant/bad.m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if just ++ not ++ matlab
3 changes: 3 additions & 0 deletions tests/projects/irrelevant/miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project_root

entrypoint "potato" {}
11 changes: 11 additions & 0 deletions tests/projects/irrelevant/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== STYLE ===
MISS_HIT Style Summary: 2 file(s) analysed, everything seems fine
=== LINT ===
MISS_HIT Lint Summary: 2 file(s) analysed, everything seems fine
=== METRICS ===
=== Code metric by file:

* Code metrics for file /home/flosch/miss_hit/tests/projects/irrelevant/+good/good.m:

* Code metrics for file /home/flosch/miss_hit/tests/projects/irrelevant/@thing/thing.m:
MISS_HIT Metric Summary: 2 file(s) analysed, everything seems fine

0 comments on commit 1c676f8

Please sign in to comment.