[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problem with local packages taking precedence over global and (an appare
From: |
Sergei Steshenko |
Subject: |
problem with local packages taking precedence over global and (an apparent) solution |
Date: |
Mon, 21 May 2012 02:28:11 -0700 (PDT) |
Hello,
this is regarding functionality of 'octave-3.6.1/scripts/pkg/pkg.m' file.
After installing packages both locally and globally I've noticed that both
global and local packages were listed by 'pkg list', and they were both listed
as autoloaded.
I did request autoloading in both cases, so it is not a problem, the problem is
that both local and global - if I understand correctly, local packages should
take precedence.
Looking into 'octave-3.6.1/scripts/pkg/pkg.m' file contents I came to the
conclusion (thanks to the comment) I came to the conclusion that the desired
functionality is supposed to be implemented by line #1988..2004:
1972 function [out1, out2] = installed_packages (local_list, global_list)
1973 ## Get the list of installed packages.
1974 try
1975 local_packages = load (local_list).local_packages;
1976 catch
1977 local_packages = {};
1978 end_try_catch
1979 try
1980 global_packages = load (global_list).global_packages;
1981 catch
1982 global_packages = {};
1983 end_try_catch
1984 installed_pkgs_lst = {local_packages{:}, global_packages{:}};
1985
1986 ## Eliminate duplicates in the installed package list.
1987 ## Locally installed packages take precedence.
1988 dup = [];
1989 for i = 1:length (installed_pkgs_lst)
1990 if (find (dup, i))
1991 continue;
1992 endif
1993 for j = (i+1):length (installed_pkgs_lst)
1994 if (find (dup, j))
1995 continue;
1996 endif
1997 if (strcmp (installed_pkgs_lst{i}.name,
installed_pkgs_lst{j}.name))
1998 dup = [dup, j];
1999 endif
2000 endfor
2001 endfor
2002 if (! isempty(dup))
2003 installed_pkgs_lst(dup) = [];
2004 endif
.
Alas, inserting diagnostic prints I verified that after the code is executed,
the duplicates (i.e. local and global packages with the same name) are still
there.
I tried to understand the logic of the code, but failed. So I simply rewrote
the piece of code, and it seems to work OK now. Here's how the code looks now:
function [out1, out2] = installed_packages (local_list, global_list)
## Get the list of installed packages.
try
local_packages = load (local_list).local_packages;
catch
local_packages = {};
end_try_catch
try
global_packages = load (global_list).global_packages;
catch
global_packages = {};
end_try_catch
# ## Eliminate duplicates in the installed package list.
# ## Locally installed packages take precedence.
installed_pkgs_lst = local_packages;
for global_pkg_num = 1:length(global_packages)
global_pkg_is_not_a_local_duplicate = 1;
for local_pkg_num = 1:length(local_packages)
if(strcmp(local_packages{local_pkg_num}.name,
global_packages{global_pkg_num}.name))
global_pkg_is_not_a_local_duplicate = 0;
break;
endif
endfor
if(global_pkg_is_not_a_local_duplicate)
installed_pkgs_lst = {installed_pkgs_lst{:},
global_packages{global_pkg_num}};
endif
endfor
.
The code is simpler, and is as bad O(N ^ 2)) as the original one, but for less
than 100 packages currently available the computational complexity doesn't
matter.
My currently used version of 'pkg.m' file ('pkg.m.20120521.gz') with this and
other fixes is attached.
Among other fixes:
1) locally installed packaged are under ~/octave-X.Y.Z directory and _not_
under ~/octave directory => no more clashes/unpredictable behavior because of
old version packages;
2) likewise, list of locally installed packages is in ~/.octave_packages-X.Y.Z
file and _not_ in ~/.octave_packages file.
Regards,
Sergei.
pkg.m.20120521.gz
Description: GNU Zip compressed data
- problem with local packages taking precedence over global and (an apparent) solution,
Sergei Steshenko <=