File Exchange

image thumbnail

exportToZip: Identifies the dependencies of an M-file and creates a ZIP file

version 1.2.0.1 (3.62 KB) by

Files inside $matlabroot/toolbox are omitted, providing a useful way to package your work

4.35714
15 Ratings

6 Downloads

Updated

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The function "mydepfun" determines the dependencies of an
M-file, ignoring files inside the MATLAB "toolbox" directory. Skipping these files gives significant performance improvements over calling "depfun" directly, especially in MATLAB installations which include multiple toolboxes. The assumption is the same as that in "mypath.m", i.e. that most of us do our work in directories outside $matlabroot/toolbox.
The function "exportToZip" creates a ZIP file containing all the dependencies identified by "mydepfun" for one or more MATLAB functions. This simplifies the process of passing your work to another user, or uploading it to MATLAB Central, by reducing both the effort required and the likelihood of a file being missed out.

The limitations of "depfun" apply: for example, that dependencies introduced by calls such as "eval('peaks')" are not identified. An additional limitation is that if files in the MATLAB toolbox directory somehow depend on files *outside* that directory (e.g.
if you have overloaded toolbox functions), these dependencies will not be picked up as they would by "depfun" itself.

The directory hierarchy is preserved by "exportToZip", which means that all required files must be on the same drive so that a "common root directory" can be determined.

Comments and Ratings (18)

Thomas Null

As Joerg said, line 70, but transpose the output.
replace
list = depfun(func,'-toponly','-quiet');
with
list = matlab.codetools.requiredFilesAndProducts(func,'toponly').';

mylyu

mylyu (view profile)

Great tool, but not compatible with matlab version > 2014 or functions not in the same disk. Joerg's solution does not work for me either. I look forward to an update. Thanks.

Joerg

Joerg (view profile)

Great work, cool tool.

I am using Matlab 2015b and
DEPFUN has been removed.

To get it work, replace call to depfun() in file "mydepfun.m" with "matlab.codetools.requiredFilesAndProducts()"

i.e.
in file "mydepfun.m", line 70
<- list = depfun(func,'-toponly','-quiet');
+> list = matlab.codetools.requiredFilesAndProducts(func,'toponly');

dk

dk (view profile)

Makes packing m files so easy.

Jack

Jack (view profile)

This should really be part of Matlab -- it Just Works.

Just a quick shout out: if you want to include object-orientated code in your .zip, by default depfun and "mydepfun" won't find private methods of your objects. This is because they'll never be on your path (by definition) and you'll get errors like "error using depfun > next_arg_file. The file 'privateMethod' does not exist".

The solution to this is to change line 39 of exportToZip to read

req{i} = matlab.codetools.requiredFilesAndProducts(funcname{i});

which can handle objects properly.

Simply great

Michael Völker

great work! but you should change

if ~isempty(dirname) && dirname(1)=='@'

to

if ~isempty(dirname) && (dirname(1)=='@' || dirname(1)=='+')

to handle packages correctly as well

Thomas Vanaret

Thomas Vanaret (view profile)

In function "mydepfun", subfunction "i_function_name" may be corrected as following to treat correctly "private" directories :

function func = i_function_name(f)
% Identifies the function name for the specified file,
% including the class name where appropriate. Does not
% work for UDD classes, e.g. @rtw/@rtw

[dirname,funcname] = fileparts(f);
[ignore,dirname] = fileparts(dirname);

% [TV] patch for 'private' functions
if strcmp(dirname, 'private')
[ignore, private_parent] = fileparts(ignore);
dirname = private_parent;
funcname = [ 'private' filesep funcname ];
end
% /[TV] patch for 'private' functions

if ~isempty(dirname) && dirname(1)=='@'
func = [ dirname filesep funcname ];
else
func = funcname;
end

Thomas Vanaret

Thomas Vanaret (view profile)

"private" directories not treated by "i_function_name" subfunction, what causes errors / incorrect results

See "getFileDependencies" in Matlab FEX

per isakson

exportToZip cannot handle packages(?)

??? Error using ==> depfun>next_arg_file at 1423
The file 'MemmapAdapter' does not exist.
....
Error in ==> mydepfun>i_scan at 69
list = depfun(func,'-toponly','-quiet');

where 'MemmapAdapter' is an m-file in a package.

Is "packages" on your TODO-list?

/per

dk

dk (view profile)

Brett Shoelson

Brett Shoelson (view profile)

I second mut ante's observation, and his suggestion for improvement. This function, which has earned a spot on my shortcut bar, fails in certain cases because of case sensitivity. I replaced all instances of STRNCMP with STRNCMPI in subfunction i_root_directory, and the problem went away.

Thierry Dalon

Comment on Tim Tam comment:
look at the option 'recursive' of mydepfun.
exporttoZip uses this option so you get all dependencies.

Tim Tam

mydepfun does not appear to find dependencies of dependencies ? When I used ML's depfun it returned 30 non-toolbox m files (plus one custom DLL), while your mydepfun returned only 13 m files.

Murphy O'Brien

Great! This is just what I needed. It's perfect for releasing code to a user and also a handy way of making a new directory without all the useless files that somehow get created on the way.

mut ante

hi: i have the habit of mixing upper and lower case when writing important folder names... the function worked properlly after changing the string comparison functions to the corresponding ignore case functions... well this is admissible in a win system, but.... thx for this function

Updates

1.2.0.1

Updated license

1.2

Added copyright notice and upgraded string comparisons to strncmpi, which eliminates warnings from M-Lint.

1.1

Review

MATLAB Release
MATLAB 7.2 (R2006a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video