octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autoloading of toolboxes?


From: David Bateman
Subject: Re: Autoloading of toolboxes?
Date: Tue, 30 Jan 2007 12:02:58 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

David Bateman wrote:
> Bill Denney wrote:
>   
>> David Bateman wrote:
>>     
>>> However, ideally there should be some means to avoid autoloading
>>> particularly of globally installed packages...
>>>       
>> How does this sound:
>>
>> * There is a file in the package directory that defines if the package
>> is supposed to be auto-loaded as I previously described.
>>     
> That wouldn't be too hard to do.. However for convenience Whether to
> autoload the package by default should be in the DESCRIPTION file, and
> should be able to be overloaded at the time of installation by the
> installer.
>
>   
>> * If there is a global package directory and a local package directory
>> with the same name, absence or presence of the file in the local
>> directory overrides the global package directory's file.
>>     
>
> The local package should always take precedence, as a particular user
> installed it for their own use. However, as it stands, I can see how
> there might be a local and global version of a package with a scenario like
>
> 1) User 1 installs package locally, then logs out
> 2) User 2 installs package globally
> 3) User 1 logs in and find themselves with a local and global version of
> the same package
>
> Unfortunately, looking at pkg.m it doesn't treat this case as
> pkg.m(installed_packages) returns both versions of the package, with the
> local version first.. Therefore the global version will override the
> local version as it will be added on the path at the head of the path
> after the local version...
>
> I think we have to have the attached patch to address this issue. This
> patch makes the list of installed packages unique with the local
> packages taking precedence and so the pkg("load",...) command will only
> load the local package in the above case
>
>   
>> To me that a) leaves it in user control, b) shouldn't be too hard to
>> implement, and c) doesn't seem too fragile (assuming that packages
>> just use their package name as the directory name since that won't
>> change between versions).
>>     
> I think it is necessary, and will do something for it along these lines...
>
> Regards
> David
>
>   
Consider this updated version of the patch.. It adds an "Autoload" field
to the DESCRIPTION file. If this is present and has a case insensitive
value of "yes", "true" or "on", then the package will by default be
marked as autoloaded by "pkg install <pkg>". If the field "Autoload" is
absent or if it isn't one of the above values then the default is not to
autoload the package.

This behavior can be overriden by the person installing the package at
the time of installation with the "-auto" or "-noauto" options to "pkg".
The patch also adds the line

## PKG_ADD: pkg ("load", "auto");

to pkg.m and so all packages that are marked as autoloaded will be
loaded when octave starts...

This patch includes the previous patch to treat the possible duplication
of package installed locally and globally. If this patch is accepted, I
propose the add the "Autoload: yes" field to all octave-forge packages
in main/

Regards
David



-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./scripts/pkg/pkg.m.orig29  2007-01-30 10:17:04.716505759 +0100
--- ./scripts/pkg/pkg.m 2007-01-30 11:55:24.203026700 +0100
***************
*** 33,38 ****
--- 33,46 ----
  ## dependency checking. That way it is possible to install a package even
  ## if it depends on another package that's not installed on the system.
  ## @strong{Use this option with care.}
+ ##
+ ## If @var{option} is @code{-noauto} the package manager will not
+ ## automatically load the installed package when starting Octave,
+ ## even if the package requests that it is.
+ ##
+ ## If @var{option} is @code{-auto} the package manager will
+ ## automatically load the installed package when starting Octave,
+ ## even if the package requests that it isn't.
  ## @item uninstall
  ## Uninstall named packages.  For example,
  ## @example
***************
*** 114,119 ****
--- 122,128 ----
  ## @end deftypefn
  
  ## PKG_ADD: mark_as_command pkg
+ ## PKG_ADD: pkg ("load", "auto");
  
  function [local_packages, global_packages] = pkg(varargin)
      ## Installation prefix (XXX: what should these be on windows?)
***************
*** 137,147 ****
--- 146,161 ----
      endif
      files = {};
      deps = true;
+     auto = 0;
      action = "none";
      for i = 1:length(varargin)
          switch (varargin{i})
              case "-nodeps"
                  deps = false;
+             case "-noauto"
+               auto = -1;
+             case "-auto"
+               auto = 1;
              case {"list", "install", "uninstall", "load", "unload", ...
                    "prefix", "local_list", "global_list"}
                  action = varargin{i};
***************
*** 166,172 ****
              if (length(files) == 0)
                  error("You must specify at least one filename when calling 
'pkg install'");
              endif
!             install(files, deps, prefix, local_list, global_list);
          case "uninstall"
              if (length(files) == 0)
                  error("You must specify at least one package when calling 
'pkg uninstall'");
--- 180,186 ----
              if (length(files) == 0)
                  error("You must specify at least one filename when calling 
'pkg install'");
              endif
!             install(files, deps, auto, prefix, local_list, global_list);
          case "uninstall"
              if (length(files) == 0)
                  error("You must specify at least one package when calling 
'pkg uninstall'");
***************
*** 174,180 ****
              uninstall(files, deps, local_list, global_list);
          case "load"
              if (length(files) == 0)
!                 error("You must specify at least one package or 'all' when 
calling 'pkg load'");
              endif
              load_packages(files, deps, local_list, global_list);
          case "unload"
--- 188,194 ----
              uninstall(files, deps, local_list, global_list);
          case "load"
              if (length(files) == 0)
!               error("You must specify at least one package, 'all' or 'auto' 
when calling 'pkg load'");
              endif
              load_packages(files, deps, local_list, global_list);
          case "unload"
***************
*** 218,224 ****
      endswitch
  endfunction
  
! function install(files, handle_deps, prefix, local_list, global_list)
      global_install = issuperuser();
   
      # Check that the directory in prefix exist. If it doesn't: create it!
--- 232,252 ----
      endswitch
  endfunction
  
! function auto = isautoload(desc)
!   auto = false;
!   if (isfield(desc{1},"autoload"))
!     a = desc{1}.autoload;
!     if ((isnumeric(a) && a > 0) || 
!       (ischar(a) && (strcmp(tolower(a),"true") || 
!                      strcmp(tolower(a),"on") || 
!                      strcmp(tolower(a),"yes") ||
!                      strcmp(tolower(a),"1"))))
!       auto = true;
!     endif
!   endif
! endfunction
! 
! function install(files, handle_deps, autoload, prefix, local_list, 
global_list)
      global_install = issuperuser();
   
      # Check that the directory in prefix exist. If it doesn't: create it!
***************
*** 400,405 ****
--- 428,442 ----
        endif
      endfor
  
+     ## If the package requested that it is autoloaded, or the installer
+     ## requested that it is, then mark the package as autoloaded.
+     for i = length(descriptions):-1:1
+       if (autoload > 0 || (autoload == 0 && isautoload(descriptions(i))))
+       fclose(fopen(fullfile(descriptions{i}.dir, "packinfo", 
+                             ".autoload"),"wt"));
+       endif
+     endfor
+ 
      ## Add the packages to the package list
      try
            if (global_install)
***************
*** 1094,1100 ****
          global_packages = {};
      end_try_catch
      installed_packages = {local_packages{:} global_packages{:}};        
!     
      ## Should we return something?
      if (nargout == 2)
          out1 = local_packages;
--- 1131,1157 ----
          global_packages = {};
      end_try_catch
      installed_packages = {local_packages{:} global_packages{:}};        
! 
!     ## Eliminate duplicates in the installed package list.
!     ## Locally installed packages take precedence
!     dup = [];
!     for i=1:length(installed_packages)
!       if (find(dup,i))
!       continue;
!       endif
!       for j=(i+1):length(installed_packages)
!         if (find(dup,j))
!         continue;
!         endif
!         if (strcmp(installed_packages{i}.name,installed_packages{j}.name))
!         dup = [dup, j];
!       endif
!       endfor
!     endfor
!     if (! isempty(dup))
!       installed_packages(dup) = [];
!     endif  
!   
      ## Should we return something?
      if (nargout == 2)
          out1 = local_packages;
***************
*** 1162,1167 ****
--- 1219,1232 ----
      ## load all
      if (length(files) == 1 && strcmp(files{1}, "all"))
          dirs = pdirs;
+     ## load auto
+     elseif (length(files) == 1 && strcmp(files{1}, "auto"))
+       dirs = {};
+       for i = 1:length(installed_packages)
+         if (exist(fullfile(pdirs{i}, "packinfo", ".autoload"), "file"))
+         dirs{end+1} = pdirs{i};
+         endif
+       endfor
      ## load package_name1 ...
      else
          dirs = {};

reply via email to

[Prev in Thread] Current Thread [Next in Thread]