/torch-prepend-path

Prepend TORCH_PREPEND_PATH to torch's search path

Primary LanguageLua

Torch Path Prepending

This very simple script prepends the content of the TORCH_PREPEND_PATH and TORCH_PREPEND_CPATH environment variable to the torch search path, giving them the highest possible priority. In particular, this allows to run concurrently different versions of a given package.

Purpose

By default, the torch-env package sets the priority by decreasing order as

  1. ~/.torch
  2. the content of the LUA_PATH environment variable
  3. the content of the global torch installation, e.g. /usr/local/share/torch

This package changes the order to:

  1. the content of the TORCH_PREPEND_PATH environment variable
  2. ~/.torch
  3. the content of the LUA_PATH environment variable
  4. the content of the global torch installation, e.g. /usr/local/share/torch

The same holds for the C path, using TORCH_PREPEND_CPATH -- see Lua's documentation for the difference between LUA_PATH and LUA_CPATH.

In particular, it is now possible to run concurrently two scripts with two different versions of a package without modifying your code, by setting TORCH_PREPEND_PATH to different values in your shell before calling torch. For example:

TORCH_PREPEND_PATH=path_to_first_version TORCH_PREPEND_CPATH=path_to_libfiles_of_first_version torch -l prepend-path myscript.lua &
TORCH_PREPEND_PATH=path_to_second_version TORCH_PREPEND_CPATH=path_to_libfiles_of_first_version torch -l prepend-path myscript.lua &

Previously, with the default path ordering, this could only be achieved by having two versions of the script had to medling with package.path.

Use

Recommended

Simply run torch from the shell with

torch -l prepend-path

And voila, the content of the environment variable TORCH_PREPEND_PATH is prepended at the beginning of your search path for lua files, and the content of tTORCH_PREPEND_CPATH to the search path for C files.

#### Alternative If you have no control over how torch is called (e.g. within an IDE), you can load prepend-path directly from your code by adding

require 'prepend-path'

at the beginning. However, the whole purpose was to avoid having to fiddle with your script in the first place.

Installation

Either add the file init.lua to your torch path, or, simpler, use

torch-pkg deploy

at the root of the repository.