Giter Club home page Giter Club logo

mpm's Introduction

Matlab Package Installer (mpi)

View mpi on File Exchange

A simple package manager for Matlab (inspired by 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:

  • 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)

What it does

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 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.

More details

Install a single package

Install (searches FileExchange and Github):

>> mpi install export_fig

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:

>> mpi install matlab2tikz -t 1.0.0

By branch:

>> mpi install matlab2tikz -t develop

By commit:

>> mpi install matlab2tikz -t ca56d9f

Uninstall

>> mpi uninstall matlab2tikz

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:

>> mpi search export_fig

Install from a url:

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

OR:

>> 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:

>> 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:

>> mpi install matlab2tikz --force

Install/uninstall packages in a specific directory:

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

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

Environments ("Collections")

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

>> 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...
>> mpi init -c test
Using collection "test"
   Adding to path: /Users/mobeets/code/mpi/mpi-packages/mpi-collections/test/cbrewer
   Added paths for 1 package(s).

Installing multiple packages from file

>> 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!

To automatically confirm installation without being prompted, set --approve. Note that this is only available when installing packages from file.

Moving from mpm to mpi

mpi was previously known as "mpm". (We had to change the name because Matlab started using "mpm" as a way of installing Matlab toolboxes.)

One way of transitioning from (our) mpm to mpi is to simply reinstall all packages/collections using mpi, which will use the new default installation path in mpi-packages/. Alternatively, point mpi to the folder containing any previously installed packages by changing mpi-packages to mpm-packages in mpi_config.m.

Troubleshooting

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.

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

Requirements

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".

mpm's People

Contributors

erkandem avatar mobeets avatar octomike avatar remi-gau avatar sin-mike avatar trevor-moon avatar wrgrant avatar zm-cttae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpm's Issues

mpm -e

One of my favorite features of pip is the -e mode. This mode can be used on a package that is installed from a local directory and instead of copying these files into an mpm-packages directory, creates a link in mpm-packages to the package. The advantage of this is you can edit the package in its current location. In the end, the effect is very similar to a simple addpath(genpath(dir)); but it gathers requirements for this package and allows mpm to keep track of this dependency and leverage the other enhancements (uninstall, environments, install.m, etc.)

mpm local install

As described in #46, mpm should handle being passed a path to a local directory. (Basically, just call installPackage() but don't download anything. Instead, copy this path to mpm-packages or wherever opts.installdir is.) Might also add a --local flag to tell mpm that the path is local.

"mpm install" and "mpm uninstall"

  • make users explicitly say "install"
  • also provide "uninstall" command (this will be possible once we manage installations in an mpm folder, as in #24 )

mpm help

What do you think of >> mpm with no args bringing up a help/man/doc/usage-guide?

read requirements.txt

in separate file, should read in requirements.txt

  • if '.git', add 'zipball/master'
  • if no '.zip' or '.git', try adding '?download=true'

mpm freeze

list all currently installed packages using mpm freeze

error with `mpm install export_fig`

>> mpm install export_fig
Collecting 'export_fig'...
   Found url: https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig?download=true
   Downloading https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig?download=true...
Error using websave (line 107)
The server returned the status 404 with message "Not Found" in response to the request
to URL
https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/23629/versions/101/download/zip/github_repo.zip?src=&license=.

Error in mpm>unzipFromUrl (line 428)
    zipfnm = websave(zipfnm, pkg.url);

Error in mpm>installPackage (line 357)
        isOk = unzipFromUrl(pkg);

Error in mpm>findAndSetupPackage (line 100)
        [pkg, isOk] = installPackage(pkg, opts);

Error in mpm (line 71)
    findAndSetupPackage(pkg, opts);

adding _all_ paths inside folder?

maybe this needs to be an option. like, if subfolders have + then this shouldn't need to happen. also it might be kinda offensive to add every single subfolder to a path...

allow searching matlab fileexchange and github

Maybe start with fileexchange, or you can provide a version number and it will search on github (e.g., v1.1.1 for matlab2tikz). In any case, for searches, should always confirm before downloading.

allow for internal bin directory

For matlab2​tikz, for example, you actually need to add the path src/ in order to call it. So allow for specifying this when installing. And notBoxPlot would need code/.

Build MEX files as part of installation

In other languages specific package managers (Python's pip and distutils system) it is possible to directly build extensions to the language as part of the package installation process. Octave has a package system that allows a similar functionality.

To achieve something similar with mpm, we might intoduce one or more optional .m files which live at a special location relative to the package root. These files implement hooks that are run at the build, install, and uninstall steps. The package maintainer would write hooks and distribute them as part of the package. If a hook is not implemented, mpm would just skip that step.

For example, a build hook might consist of a few calls to mex ...

mex myFile.c -myFlags 

In the Octave system, it's possible to run a ./configure script at build time to resolve any system specific include paths and flags.

The hooks get copied over to a package-specific metadata directory by mpm. Then at uninstall time, mpm runs the copy of the uninstall hook cached in the metadata directory before wiping it clean.

"mpm init -c [collection]"

This issue is for adding venv-like environments to mpm. I'm going to call them "collections" instead of environments since mpm -e is already being used ;)

The idea in this setting is that a collection is a nickname for a particular collection of packages, which you can then easily enable/disable in order to add/rm the paths to all of those installations.

A few notes:

  • mpm init -c colname enables a collection called colname (creating one if it doesn't exist), which means rmpaths for the previous collection (e.g., default), and adding paths for the new collection
  • every user has a default collection, so that mpm init is short-hand for mpm init -c default
  • each collection gets its own folder inside the user's default install directory (e.g., assuming the install directory is mpm-packages, then all packages for the colname collection should be installed to mpm-packages/mpm-collections/colname). for easier backwards compatibility, packages in the default collection are still installed directly to mpm-packages.
  • mpm install -c colname (similarly for mpm uninstall) indicates to install the package to the colname collection
  • mpm freeze -c colname lists the packages in colname
  • in all cases (install, uninstall, freeze, etc.), if -c is not provided then the implied collection is always -c default, NOT the currently init'd collection. To me, this is a safer bet, since there's no easy way to specify which collection is currently enabled (unlike in venv, for example, where it's prefixed to your bash prompt)

e.g., in the following, the package tmp would be installed to the default collection, NOT the test collection, while tmp2 would be installed to the test collection and not the default collection.

>> mpm init -c test
>> mpm install tmp
>> mpm install tmp2 -c test

mpm2: find url given name

Need a function in matlab to find the correct url to download given a name (e.g., "export_tikz") and any of the user's arguments regarding where to search first (i.e., github vs. matlab exchange), and a release_tag (github only). See find_package() in mpm.py for current functionality.

Two pieces to this:

  • search github (find_github_repo() in find_package.py)
    • user has option to set release_tag
    • python code uses the github pip package, which probably doesn't exist in matlab?
  • search Matlab Central (find_matlabcentral_repo() in find_package.py)

websave will probably be useful

This code should go in findUrl() in mpm2.m

paths added by default

What's the motivation for looking for folders called 'bin', 'src', 'lib', or 'code'? My preference would be to have the default behavior be adding all folders (i.e. addpath(genpath(path/to/toolbox))), which you can override with a set of paths. In the correct configuration, I'm having trouble properly installing some packages, like FMAToolbox

cannot search for package if already exists

>> mpm search cbrewer
Collecting 'cbrewer'...
Warning:    Package already exists. Re-run with --force to
overwrite. 
> In mpm>findAndSetupPackage (line 82)
  In mpm (line 71) 
>> mpm search cbrewer --force
Error using mpm>validateArgs (line 774)
Nothing to force when searching.

Error in mpm (line 34)
    validateArgs(pkg, opts);

rename mpmpath?

rename to mpm so you're calling the same thing in both places?

mpm2: update internal data

Need to keep track of all packages installed by writing to file after all user calls to mpm2.

In python, this is done by updating mpm.json. In matlab, probably better to do this with just a native .mat file. See write_to_mpmfile() in mpm.py for current functionality.

local install empty dir

$ git clone https://github.com/michael-zugaro/FMAToolbox.git
>> mpm install FMAToolbox -u /Users/bendichter/dev/FMAToolbox --local --force

puts an empty FMAToolbox folder in mpm-packages

install not adding paths?

I might be doing something wrong here... when I run >> mpm install buzcode -u https://github.com/bendichter/buzcode I only see buzcode in mpm-packages, and the directory is empty.

Give mpm its own default install dir

Instead of using userpath, give mpm its own directory to manage its installations (more like how pip has site-packages) (see #20 )

currently mpm keeps track of what it's installed in mpm.json, which keeps track of the {name, url, date_downloaded, and install_dir}.

for each downloaded folder within this install directory, we will want to be able to call:

  • mpm on (probably run by default after downloading, right?) #26
  • mpm off #26
  • mpm uninstall (rmdir) #25

Check for pathlist file

After downloading, check for a file pathlist.m (or something like mpmpaths.m) containing a list of folders to add to path (see #20 ). This would override the default action.

Check for install.m

After installation, check for and run any included installation file, e.g., one called install.m. (See #20 )

Should we check for a specifically named install file, such as mpminstall.m? Depends what sorts of things would be done inside an install script.

Github API search

I'm a little confused by what mpm install foo -g actually searches for. When I use it, I rarely get useful results.

The constructed query is:

/?q=foo&language=matlab&sort=stars&order=desc

I believe the "best" query, according to the API should be:

/?q=foo+language:matlab

The problem here unfortunately is, that webread() will encode the : and + sign, which foobars the search results completely.

Wishlist

I quickly tried out MPM and I find it is a really great tool, I wish Mathworks would implement something like this but deeply integrated into Matlab. I would like to recommend your code to users of my library as a mean of installing it (www.github.com/tsdev/spinw). However I have a few wishes which would be necessary to install my code:

  • MPM should install all code not into userpath but some unique subfolder as many users use the userpath folder to just dump any Matlab code, for example you could use the site-packages (as pip) or something similar
  • the user should able to do all the basic (install, uninstall from FEX and a given github repo) without falling back to python code, as this makes the installation of MPM itself already difficult
  • MPM should check if there is an install script in the added package (something like install.m similarly to pip) and if true, should run it
  • also it should be possible to define the list of subfolders in each package that has to be added to the Matlab path (for example MPM could check for the existence of a pathlist.m file in the package that contains all folder that should be added to the path)
  • it would be nice if mpm would have a more pip like input argument structure mpm install my_package and mpm uninstall my_package
  • since Matlab does not have an import command like python, any package added to the Matlab path last, would conflict with function of the same name, to avoid this I often add/remove certain packages from the search path, it would be really nice if I could do this with MPM by adding/removing a certain package from the search path without installing/uninstalling it every time, for example: mpm on my_package and mpm off my_package

I would be also happy to implement the above changes if you are interested in the above.

"mpm on" and "mpm off"

once we start managing installations (see #24 ), we can give mpm a more venv-like functionality by allowing users to enable/disable certain packages from being in the path (see #20 ).

e.g., mpm on matlab2tikz adds the paths (e.g., as listed in pathlist if it exists), while mpm off matlab2tikz removes them.

RETHINKING

okay, what are all the desired behaviors?

  1. should be able to install in one line: mpm mASD
  2. should be able to install from requirements.txt file mpm -r requirements.txt
  3. should add paths of thing installed so that it can be used effortlessly/by default
  4. should install everything by default to one folder
  5. should (optionally) install everything to a particular folder: mpm -r requirements.txt -p .
  6. should be able to check for updates if there is repo associated: wait, NO. git does this.

basically, (3) is the tricky part:

  • don't add subfolders? e.g. cbrewer has subfolders...they need to be added. but others might have subfolders that shouldn't be added (like, how deep do i go?) or have none to be added at all (if using + structure)
  • how to handle startup stuff. like, do i update automatically?

Question: Does mpm keep track of installs after they exist? or is it an install tool only?

also, for self-install: is adding stuff to .bash_profile necessary? the only real important thing is that mpm is in your Matlab path, and that mpm in Matlab knows how to call its own python file in order to download stuff. so i think if its all Matlab-contained then I don't need to mess with .bash_profile

mpm2: find folder(s) to add to path

Write function to find the folders that mpm should add to the user's path.

First, check if the folders are already specified:

  • package itself might specify--check for file called pathlist.m (#22)
  • users might specify which folders to add via command-line argument

see find_mfile_dir() in mpm.py for current functionality.

This code should go in installPackage() in mpm2.m

mpm2: main function

Write function that:

  • gets opts from command line using #29
  • searches for url using #27
  • if opts.action is 'install', installs url and unzips
  • adds folders to path using #28
  • keep track of anything installed using #32

See main() in mpm.py for current functionality.

option to update

or at least mention that if you need to update repos you can either call -f or go into each directory and go a git pull

mpm2: install from file

allows user to install a list of packages by specifying a requirements file

usage: mpm2 install -r [path-to-requirements].

see requirements-example.txt for example input.
basically will just call mpm2 on every item inside this file.

see load_from_file() in mpm.py for current functinality.

This code should go in mpm2.m

mpm gui from matlab

the downloading can still be done with the python script, but it makes more sense to be calling mpm from within matlab, no?

broken urls for some packages

currently "export_fig" and "matlab2tikz" are giving the following error:

>> mpm install matlab2tikz
Collecting 'matlab2tikz'...
   Found url: https://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz?download=true
   Downloading https://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz?download=true...
Error using websave (line 95)
The server returned the message: "Not Found" for URL,
'https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/22022/versions/54/download/zip/github_repo.zip?src=&license='
(with HTTP response code 404).

Error in mpm>unzipFromUrl (line 428)
    zipfnm = websave(zipfnm, pkg.url);

Error in mpm>installPackage (line 357)
        isOk = unzipFromUrl(pkg);

Error in mpm>findAndSetupPackage (line 100)
        [pkg, isOk] = installPackage(pkg, opts);

Error in mpm (line 71)
    findAndSetupPackage(pkg, opts);

mpm2: handle command-line arguments

Write function to accept command-line arguments in matlab-friendly way (e.g., 'Argument', ArgumentValue format), and also set default arguments if not provided. Return a struct called opts so we can access these in easy way, e.g., opts.verbose.

Arguments:

  • Action [assumed first argument]: accept 'install' or 'search' for now; see #30
  • Name [optional second argument]: name of package (e.g., 'matlab2tikz')
  • -r, or RequirementsFile: if set, will run mpm2 on all packages in requirements file as in #31
  • -u, or Url (optional; if does not exist, must search using #27 )
  • -t, or ReleaseTag: if url is found on github, this lets user set release tag
  • -g, or SearchGithubFirst: check github for url before matlab fileexchange
  • -i, or InstallDir: where to install package
  • -f, or Force: install package even if package with this name already exists in InstallDir
  • -n, or InternalDir: lets user set which directories inside package to add to path

Example usages:

  • mpm2 install export_fig -u http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig
  • mpm2 install colorbrewer
  • mpm2 install matlab2tikz -t 1.0.0
  • mpm2 install -r requirements-example.txt (or mpm2 install RequirementsFile requirements-example.txt)

add import-like functionality using addpath + mpm

Hi I am primarily a python/R/clojure programmer who is now using matlab because a lab I am working in primarily uses it. I have found the global path and a lack of a package manager (like pip) to be a particularly terrible pain point so far. I just came across this package and I really like the ideas here!

I was wondering if you would be interested in a PR for an import package like function for use with mpm . I envision a simple function that is initialized by mpm with the main repository download path and then can temporarily add packages/functions to the path by writing import exampleFunction at the top of the script. I dont think this would be difficult to do and I would be happy to contribute if you think this would be a good idea.

mpm2: update metadata

  • confirm metadata is updated (e.g., folder could have been deleted but still exist in metadata)
  • if forcing overwrite, need to remove the old entries

error installing second package

mpm install chronux -u http://chronux.org/chronuxFiles/filesReleases/chronux_2_12.zip
mpm install circular-statistics-toolbox-directional-statistics

Error using horzcat
Number of fields in structure arrays being concatenated do not match. Concatenation of
structure arrays requires that these arrays have the same set of fields.

Error in mpm>addToMetadata (line 544)
    pkgs = [pkgs pkg];

Error in mpm>findAndSetupPackage (line 102)
            opts = addToMetadata(pkg, opts);

Error in mpm (line 71)
    findAndSetupPackage(pkg, opts);

some keyboard debugging:

K>> pkg

pkg = 

  struct with fields:

                     name: 'circular-statistics-toolbox-directional-statistics'
                      url: 'https://www.mathworks.com/matlabcentral/fileexchange/10676-circular-statistics-toolbox-directional-statistics?download=true'
              internaldir: ''
              release_tag: ''
                  addpath: 1
            local_install: 0
    no_rmdir_on_uninstall: 0
                    query: ''
               installdir: '/Users/bendichter/dev/mpm/mpm-packages/circular-statistics-toolbox-directional-statistics'
          date_downloaded: '29-Jul-2018 19:18:59'
                     mdir: ''

K>> pkgs

pkgs = 

  struct with fields:

                     name: 'chronux'
                      url: 'http://chronux.org/chronuxFiles/filesReleases/chronux_2_12.zip?download=true'
              internaldir: ''
              release_tag: ''
                  addpath: 1
            local_install: 0
    no_rmdir_on_uninstall: 0
                    query: ''
               installdir: '/Users/bendichter/dev/mpm/mpm-packages/chronux'
          date_downloaded: '29-Jul-2018 19:16:37'
                     mdir: ''
                 pathlist: []

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.