bugGNU Octave - Bugs: bug #45410, report a warning if a +package...

 
 

bug #45410: report a warning if a +package directory is added to the path

Submitter:  Richard <crobar>
Submitted:  Thu 25 Jun 2015 09:19:04 PM UTC
   
 
Category:  Interpreter Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Richard Crozier Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 01 Sep 2017 10:38:17 PM UTC, comment #11: 

I added a warning to Octave when adding package directories to the path.  See cset (http://hg.savannah.gnu.org/hgweb/octave/rev/8785b3717140).  I created a new warning ID "Octave:addpath-pkg".  If you want identical behavior to Matlab you can use


warning ("error", "Octave:addpath-pkg");


I didn't bother to set this option when Octave is invoked with --traditional, but someone could if they really feel bothered about it.

Rik <rik5>
Group administrator
Tue 30 Jun 2015 05:52:22 PM UTC, comment #10: 

Well, I guess TMW have decided that if they state that you should not add directories of a certain type to the path, they should prevent it from happening, and warn you that it's not been done.

It can be helpful when automatically adding a load of directories to a path (which is exactly what my initialisation script does, stripping version control directories).

Richard <crobar>
Tue 30 Jun 2015 04:20:14 PM UTC, comment #9: 

If the user explicitly adds a directory to the path, then we should add it to the path. Maybe we can also print a warning but why prevent it if that's what the user wants to do?

Carnë Draug <carandraug>
Group Member
Tue 30 Jun 2015 02:15:28 PM UTC, comment #8: 

I can confirm that adding a "+package" folder to the path issues a warning and does not add the folder as a result.


>> path   % note path before
>> addpath('C:\...\+foo')
Warning: Package directories not allowed in MATLAB path: C:\...\+foo
> In path (line 109)
  In addpath (line 86)
>> path   % note path after


Perhaps they should have issued an error instead..

(Tested in latest R2015a)

Amro <amro_octave>
Tue 30 Jun 2015 02:06:53 PM UTC, comment #7: 

@mtmiller
Done, see bug #45444

Feel free to delete my previous comment in this thread.

Amro <amro_octave>
Tue 30 Jun 2015 01:37:57 PM UTC, comment #6: 

So the remaining bug here is that Matlab reports a warning if a +-directory is added to the path. Are you sure that the directory is not added to the path? To me a warning message means that something was done anyway.

Mike Miller <mtmiller>
Group Member
Tue 30 Jun 2015 01:34:56 PM UTC, comment #5: 

Amro, please report that as a separate bug for private functions inside namespace and class directories.

Mike Miller <mtmiller>
Group Member
Fri 26 Jun 2015 01:48:02 PM UTC, comment #4: 

I wasn't sure if I should create a new bug or just update the current one, but here is an actual issue related to path, packages and classes, and private functions:


./testdir/+foo/
./testdir/+foo/bar.m
./testdir/+foo/private/baz.m


where "bar.m" is a function that calls a private function "baz.m".


function x = bar()
    x = baz();
end


and


function x = baz()
    x = pi;
end


In Octave the following fails (while it works fine in MATLAB):


>> addpath('C:\testdir')
>> foo.bar()
error: 'baz' undefined near line 2 column 9
error: called from
    bar at line 2 column 7


I had to explicitly add the private folder to the path for it to work:


>> addpath('C:\testdir\+foo\private')
>> foo.bar
ans =  3.1416





Similarly, private functions inside @-class folders:


./testdir/@MyClass/
./testdir/@MyClass/MyClass.m
./testdir/@MyClass/private/myfunc.m


Trying to call "myfun.m" from class methods will generate a similar 'undefined function' error...

Amro <amro_octave>
Fri 26 Jun 2015 01:44:50 PM UTC, comment #3: 

I wasn't sure if I should create a new bug or just update the current one, but here is an actual issue related to path, packages/classes, and private functions:


./testdir/+foo/
./testdir/+foo/bar.m
./testdir/+foo/private/baz.m
-verbatim+

where "bar.m" is a function that calls a private function "baz.m".

+verbatim+
function x = bar()
    x = baz();
end
-verbatim+

and

+verbatim+
function x = baz()
    x = pi;
end
-verbatim+

In Octave the following fails (while it works fine in MATLAB):

+verbatim+
>> addpath('C:\testdir')
>> foo.bar
error: 'baz' undefined near line 2 column 9
error: called from
    bar at line 2 column 7


I had to explicitly add the private folder to the path for it to work:


>> addpath('C:\testdir\+foo\private')
>> foo.bar
ans =  3.1416





Similarly, private functions inside @-class folders:


./testdir/@MyClass/
./testdir/@MyClass/MyClass.m
./testdir/@MyClass/private/myfunc.m
-verbatim+

Trying to call "myfun.m" from class methods will generate a similar 'undefined function' error...

Amro <amro_octave>
Fri 26 Jun 2015 07:30:49 AM UTC, comment #2: 

Actually you're right, sorry, I was seeing a bug in my own code. I should have investigated more carefully.

However, there is still a possible minor bug regarding matlab compatibility. In Matlab addpath prevents adding the +directory to the path, you get a warning and the path is not addded:


>> addpath ('/home/rcrozier/src/xfemm-svn/mfemm/+mfemmdeps')
Warning: Package directories not allowed in MATLAB path: /home/rcrozier/src/xfemm-svn/mfemm/+mfemmdeps
(Type "warning off MATLAB:dispatcher:pathWarning" to suppress this warning.)

> In path (line 109)
  In addpath (line 86)
>>


In octave nothing prevents you from adding it to the path. I've no idea if it's an issue.

Richard <crobar>
Fri 26 Jun 2015 12:29:26 AM UTC, comment #1: 

Thanks for your bug report. I'm not sure what you mean by this. The directory containing the +package directory does need to be added to the path, but not the +package directory itself.


$ ls -lR ~/testdir
/home/mike/testdir:
total 4
drwxr-x--- 2 mike mike 4096 Jun 25 20:25 +foo

/home/mike/testdir/+foo:
total 12
-rw-r----- 1 mike mike 42 Jun 25 20:25 bar.m
$ octave
octave:1> foo.bar
error: 'foo' undefined near line 1 column 1
octave:1> addpath ~/testdir
octave:2> foo.bar
ans =  3.1416


Are you seeing something different? Are you expecting something different?

Mike Miller <mtmiller>
Group Member
Thu 25 Jun 2015 09:19:04 PM UTC, original submission:  


In Octave +package directories must be on the path.

However, in Matlab they must explicitly not be added to path, and addpath refuses to add them. They are more like private directories in this respect.

Richard <crobar>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by amro_octave (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by crobar (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-09-01 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2015-06-30 mtmiller Severity3 - Normal 2 - Minor
        Summaryin Octave +package directories must be on path, in ML they must not be added to path report a warning if a +package directory is added to the path
    2015-06-26 mtmiller CategoryNone Interpreter
        StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code