Skip to content

Commit

Permalink
renaming mpm to mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
mobeets committed Feb 17, 2024
1 parent e19d85d commit 11d7a8a
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 108 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
_old/

# exclude everything
mpm-packages/*
mpi-packages/*
mpm-packages/

# exception to the rule
!mpm-packages/.gitkeep
!mpi-packages/.gitkeep
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Jay H
Copyright (c) 2024 Jay Hennig

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Matlab Package Manager (mpm)
# Matlab Package Installer (mpi)

[![View mpm on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/54548-mpm)
[![View mpi on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/54548-mpm)

A simple package manager for Matlab (inspired by [pip](https://github.com/pypa/pip)). Downloads packages from Matlab Central's File Exchange, GitHub repositories, or any other url pointing to a .zip file.

## Quickstart

Download/clone this repo and add it to your Matlab path (using `addpath`). Now try the following:

- `mpm install [package-name]`: install package by name
- `mpm uninstall [package-name]`: remove package, if installed
- `mpm search [package-name]`: search for package given name (checks Github and Matlab File Exchange)
- `mpm freeze`: lists all packages currently installed
- `mpm init`: adds all installed packages to path (run when Matlab starts up)
- `mpi install [package-name]`: install package by name
- `mpi uninstall [package-name]`: remove package, if installed
- `mpi search [package-name]`: search for package given name (checks Github and Matlab File Exchange)
- `mpi freeze`: lists all packages currently installed
- `mpi init`: adds all installed packages to path (run when Matlab starts up)

## More details

Expand All @@ -21,100 +21,100 @@ Download/clone this repo and add it to your Matlab path (using `addpath`). Now t
__Install (searches FileExchange and Github):__

```
>> mpm install export_fig
>> mpi install export_fig
```

When installing, mpm checks for a file in the package called `install.m`, which it will run after confirming (or add `--force` to auto-confirm). It also checks for a file called `pathlist.m` which tells it which paths (if any) to add.
When installing, mpi checks for a file in the package called `install.m`, which it will run after confirming (or add `--force` to auto-confirm). It also checks for a file called `pathlist.m` which tells it which paths (if any) to add.

__Install a Github release (by tag, branch, or commit)__

By tag:

```
>> mpm install matlab2tikz -t 1.0.0
>> mpi install matlab2tikz -t 1.0.0
```

By branch:

```
>> mpm install matlab2tikz -t develop
>> mpi install matlab2tikz -t develop
```

By commit:

```
>> mpm install matlab2tikz -t ca56d9f
>> mpi install matlab2tikz -t ca56d9f
```

__Uninstall__

```
>> mpm uninstall matlab2tikz
>> mpi uninstall matlab2tikz
```

When uninstalling, mpm checks for a file in the package called `uninstall.m`, which it will run after confirming (or add `--force` to auto-confirm).
When uninstalling, mpi checks for a file in the package called `uninstall.m`, which it will run after confirming (or add `--force` to auto-confirm).

__Search without installing:__

```
>> mpm search export_fig
>> mpi search export_fig
```

__Install from a url:__

```
>> mpm install covidx -u https://www.mathworks.com/matlabcentral/fileexchange/76213-covidx
>> mpi install covidx -u https://www.mathworks.com/matlabcentral/fileexchange/76213-covidx
```
OR:

```
>> mpm install export_fig -u https://github.com/altmany/export_fig.git
>> mpi install export_fig -u https://github.com/altmany/export_fig.git
```

(Note that when specifying Github repo urls you must add the '.git' to the url.)

__Install local package:__

```
>> mpm install my_package -u path/to/package --local
>> mpi install my_package -u path/to/package --local
```

The above will copy `path/to/package` into the default install directory. To skip the copy, add `-e` to the above command.

__Overwrite existing packages:__

```
>> mpm install matlab2tikz --force
>> mpi install matlab2tikz --force
```

__Install/uninstall packages in a specific directory:__

```
>> mpm install matlab2tikz -d /Users/mobeets/mypath
>> mpi install matlab2tikz -d /Users/mobeets/mypath
```

Note that the default installation directory is `mpm-packages/`.
Note that the default installation directory is `mpi-packages/`.

## Environments ("Collections")

mpm has rudimentary support for managing collections of packages. To specify which collection to act on, use `-c [collection_name]`. Default collection is "default".
mpi has rudimentary support for managing collections of packages. To specify which collection to act on, use `-c [collection_name]`. Default collection is "default".

```
>> mpm install cbrewer -c test
>> mpi install cbrewer -c test
Using collection "test"
Collecting 'cbrewer'...
Found url: https://www.mathworks.com/matlabcentral/fileexchange/58350-cbrewer2?download=true
Downloading https://www.mathworks.com/matlabcentral/fileexchange/58350-cbrewer2?download=true...
>> mpm init -c test
>> mpi init -c test
Using collection "test"
Adding to path: /Users/mobeets/code/mpm/mpm-packages/mpm-collections/test/cbrewer
Adding to path: /Users/mobeets/code/mpi/mpi-packages/mpi-collections/test/cbrewer
Added paths for 1 package(s).
```

## Installing multiple packages from file

```
>> mpm install -i /Users/mobeets/example/requirements.txt
>> mpi install -i /Users/mobeets/example/requirements.txt
```

Specifying a requirements file lets you install or search for multiple packages at once. See 'requirements-example.txt' for an example. Make sure to provide an absolute path to the file!
Expand All @@ -123,16 +123,16 @@ To automatically confirm installation without being prompted, set `--approve`. N

## What it does

By default, mpm installs all Matlab packages to the directory `mpm-packages/`. (You can edit `mpm_config.m` to specify a custom default installation directory.)
By default, mpi installs all Matlab packages to the directory `mpi-packages/`. (You can edit `mpi_config.m` to specify a custom default installation directory.)

If you restart Matlab, you'll want to run `mpm init` to re-add all the folders in the installation directory to your Matlab path. Better yet, just run `mpm init` from your Matlab [startup script](http://www.mathworks.com/help/matlab/ref/startup.html).
If you restart Matlab, you'll want to run `mpi init` to re-add all the folders in the installation directory to your Matlab path. Better yet, just run `mpi init` from your Matlab [startup script](http://www.mathworks.com/help/matlab/ref/startup.html).

## Troubleshooting

Because there's no standard directory structure for a Matlab package, automatically adding paths can get a bit messy. When mpm downloads a package, it adds a single folder within that package to your Matlab path. If there are no `*.m` files in the package's base directory, it looks in folders called 'bin', 'src', 'lib', or 'code' instead. You can specify the name of an internal directory by passing in an `-n` or `internaldir` argument. To install a package without modifying any paths, set `--nopaths`. Or to add _all_ subfolders in a package to the path, set `--allpaths`.
Because there's no standard directory structure for a Matlab package, automatically adding paths can get a bit messy. When mpi downloads a package, it adds a single folder within that package to your Matlab path. If there are no `*.m` files in the package's base directory, it looks in folders called 'bin', 'src', 'lib', or 'code' instead. You can specify the name of an internal directory by passing in an `-n` or `internaldir` argument. To install a package without modifying any paths, set `--nopaths`. Or to add _all_ subfolders in a package to the path, set `--allpaths`.

Mpm keeps track of the packages it's downloaded in a file called `mpm.mat`, within each installation directory.
mpi keeps track of the packages it's downloaded in a file called `mpi.mat`, within each installation directory.

## Requirements

mpm should work cross-platform on versions Matlab 2014b and later. Also note that, starting with Matlab 2022, you may see a warning when using mpm, as Matlab includes a built-in command of the same name (used for installing Matlab products). You may need to rename the file `mpm.m` to something else, and then rename the function name on line 1 of this file to match, as well as the line containing "help mpm".
mpi should work cross-platform on versions Matlab 2014b and later. Also note that, starting with Matlab 2022, you may see a warning when using mpi, as Matlab includes a built-in command of the same name (used for installing Matlab products). You may need to rename the file `mpi.m` to something else, and then rename the function name on line 1 of this file to match, as well as the line containing "help mpi".
Empty file added mpi-packages/.gitkeep
Empty file.
56 changes: 28 additions & 28 deletions mpm.m → mpi.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function mpm(action, varargin)
%MPM Matlab Package Manager
% function mpm(ACTION, varargin)
function mpi(action, varargin)
%MPI Matlab Package Installer
% function mpi(ACTION, varargin)
%
% ACTION can be any of the following:
% 'init' add all installed packages in default install directory to path
Expand All @@ -17,34 +17,34 @@ function mpm(action, varargin)
% Examples:
%
% % Add all installed packages to the path (e.g. to be run at startup)
% mpm init
% mpi init
%
% % Search for a package called 'test' on Matlab File Exchange
% mpm search test
% mpi search test
%
% % Install a package called 'test'
% mpm install test
% mpi install test
%
% % Uninstall a package called 'test'
% mpm uninstall test
% mpi uninstall test
%
% % List all installed packages
% mpm freeze
% mpi freeze
%
% % Change the folder added to the path in an already installed package
% mpm set test -n folder_name_to_add
% mpi set test -n folder_name_to_add
%
% To modify the default behavior of the above commands,
% the following optional arguments are available:
%
% name-value arguments:
% url (-u): optional; if does not exist, must search
% infile (-i): if set, will run mpm on all packages listed in file
% infile (-i): if set, will run mpi on all packages listed in file
% install-dir (-d): where to install package
% query (-q): if name is different than query
% release-tag (-t): if url is found on github, this lets user set release tag
% internal-dir (-n): lets user set which directories inside package to add to path
% collection (-c): override mpm's default package collection ("default")
% collection (-c): override mpi's default package collection ("default")
% by specifying a custom collection name
%
% arguments that are true if passed (otherwise they are false):
Expand All @@ -58,12 +58,12 @@ function mpm(action, varargin)
% --use-local (-e): skip copy operation during local install
%
% For more help, or to report an issue, see <a href="matlab:
% web('https://github.com/mobeets/mpm')">the mpm Github page</a>.
% web('https://github.com/mobeets/mpi')">the mpi Github page</a>.
%

% print help info if no arguments were provided
if nargin < 1
help mpm;
help mpi;
return;
end

Expand All @@ -78,40 +78,40 @@ function mpm(action, varargin)

% installing from requirements
if ~isempty(opts.inFile)
% read filename, and call mpm for all lines in this file
% read filename, and call mpi for all lines in this file
readRequirementsFile(opts.inFile, opts);
return;
end

% load metadata
[opts.metadata, opts.metafile] = getMetadata(opts);

% mpm init
% mpi init
if strcmpi(opts.action, 'init')
opts.updateMpmPaths = true;
opts.updateMpiPaths = true;
updatePaths(opts);
return;
end

% mpm freeze
% mpi freeze
if strcmpi(opts.action, 'freeze')
listPackages(opts);
return;
end

% mpm set
% mpi set
if strcmpi(opts.action, 'set')
changePackageOptions(package, opts);
return;
end

% mpm uninstall
% mpi uninstall
if strcmpi(opts.action, 'uninstall')
removePackage(package, opts);
return;
end

% mpm search OR mpm install
% mpi search OR mpi install
findAndSetupPackage(package, opts);
end

Expand Down Expand Up @@ -301,11 +301,11 @@ function listPackages(opts)
package.addAllDirsToPath = false;
package.collection = 'default';

opts = mpm_config(); % load default opts from config file
opts = mpi_config(); % load default opts from config file
opts.installDir = opts.DEFAULT_INSTALL_DIR;
opts.metadir = opts.DEFAULT_INSTALL_DIR;
opts.searchGithubFirst = opts.DEFAULT_CHECK_GITHUB_FIRST;
opts.updateMpmPaths = false;
opts.updateMpiPaths = false;
opts.updateAllPaths = false;
opts.localInstall = false;
opts.localInstallUseLocal = false;
Expand Down Expand Up @@ -638,7 +638,7 @@ function listPackages(opts)

function [m, metafile] = getMetadata(opts)

metafile = fullfile(opts.metadir, 'mpm.mat');
metafile = fullfile(opts.metadir, 'mpi.mat');
if exist(metafile, 'file')
m = load(metafile);
packages = [];
Expand Down Expand Up @@ -734,7 +734,7 @@ function updatePaths(opts)

% add mdir to path for each package in metadata (optional)
namesAdded = {};
if opts.updateMpmPaths
if opts.updateMpiPaths
packages = opts.metadata.packages;
for ii = 1:numel(packages)
success = updatePath(packages(ii), opts);
Expand Down Expand Up @@ -801,7 +801,7 @@ function updatePaths(opts)
if ~ismember(f, namesAlreadyAdded)
if ~opts.debug
dirPath = fullfile(opts.installDir, f);
disp(mpm_config('updatepath_op', dirPath));
disp(mpi_config('updatepath_op', dirPath));
addpath(dirPath);
end
c = c + 1;
Expand Down Expand Up @@ -937,7 +937,7 @@ function updatePaths(opts)

% update metadir, if collection was set
if ~strcmpi(opts.collection, 'default')
opts.metadir = fullfile(opts.metadir, 'mpm-collections', ...
opts.metadir = fullfile(opts.metadir, 'mpi-collections', ...
opts.collection);
opts.installDir = opts.metadir;
if strcmpi(opts.action, 'install')
Expand Down Expand Up @@ -1124,7 +1124,7 @@ function readRequirementsFile(fileName, opts)
% run all
for ii = 1:numel(cmds)
cmd = strsplit(cmds{ii});
mpm(opts.action, cmd{:});
mpi(opts.action, cmd{:});
end
end

Expand Down Expand Up @@ -1205,7 +1205,7 @@ function checkForFileAndRun(installDir, fileName, opts)
persistent locale nls
if ~isstruct(nls)
locale = char(regexp(get(0, 'Language'), '^[a-zA-Z]+', 'match'));
nls = load('mpm_nls.mat');
nls = load('mpi_nls.mat');
end

%% Check if message key exists.
Expand Down
4 changes: 2 additions & 2 deletions mpm_config.m → mpi_config.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function opts = mpm_config()
function opts = mpi_config()

opts = struct();

% set default directory to install packages
curdir = fileparts(mfilename('fullpath'));
opts.DEFAULT_INSTALL_DIR = fullfile(curdir, 'mpm-packages');
opts.DEFAULT_INSTALL_DIR = fullfile(curdir, 'mpi-packages');

% search github before searching Matlab File Exchange?
opts.DEFAULT_CHECK_GITHUB_FIRST = false;
Expand Down
Binary file added mpi_nls.mat
Binary file not shown.
Binary file removed mpm_nls.mat
Binary file not shown.
Loading

0 comments on commit 11d7a8a

Please sign in to comment.