How to install luarocks packages without internet? - lua

I used torch distro repository on github and installed LuaJIT and luarocks.
I want to install luarocks packages , from source, that is downloading the packages(.zip files) and building them from source .
I tried doing it by downloading the packages from github and then running luarocks install modulename.rockspec . But here it again starts cloning from github.
Can anyone tell me the exact procedure to do this ?

You can use either source rocks or binary rocks.
Using source rocks
A source rock is a package with .src.rock extension containing the sources. You create it packing a rockspec:
luarocks pack bla-1.0-1.rockspec # uses the network
This produces bla-1.0-1.src.rock. Running luarocks build bla-1.0-1.src.rock does not use the network to build bla, but it will hit the network to fetch dependencies if needed. So you need to pack and install all dependencies beforehand.
Using binary rocks
A binary rock is a compiled package with .PLATFORM.rock extension containing the .lua or .so/.dll modules. You create it building a module and then packing the code you built:
luarocks build bla-1.0-1.rockspec # uses the network
luarocks pack bla # doesn't use the network
This produces a binary rock, say bla-1.0-1.linux-x86.rock. Note however that to install this in another machine, the target machine needs to be fully ABI-compatible, that is, all installed libraries in the source and destination machine need to be compatible (e.g. same OS/distro version). For this reason, this is useful for deploying rocks to multiple machines in a farm, but not for distributing binary packages for end-users in general.
Grouping packed rocks into a local server
Once you pack all rocks you need (and their dependencies) using one of the methods above, you can put them all in a directory, then turn it into a "local server":
mkdir my_rocks
mv *.rock my_rocks # suppose we have some packed .rock files here
cd my_rocks
luarocks-admin make-manifest my_rocks
This works with both source and binary rocks. You'll then be able to build rocks from there without fetching the network.
luarocks install bla --only-server=/home/YOURNAME/my_rocks

Related

Build docker images with asdf tool-versions

I am generalizing the use of the asdf tool (https://github.com/asdf-vm/asdf) to manage all our project dependencies, and I would like to integrate the .tool-versions file with my Dockerfiles, to ensure we are always using the same tool-versions when developing locally, or when generating docker-images.
In my Dockerfiles I often end up having projects that require multiple tools to successfully build (like Node-gyp that requires python, ruby that requires node, etc.) and I usually have something like
# Pick an initial container matching the project as best as possible
FROM node:x.x.x-alpine
[...]
# Some commands that will install nvm, pyenv, or other tools to handle versions
# and then `RUN [pyenv|nvm|...] install [version_number]`
How can I easily retrieve the version from my .tool-versions and read it as a version number for my Dockerfile ?
The .tool-versions file looks like this
python 2.7.18
nodejs 12.8.1

octave: add gdal support for mapping package

I am trying to run some old matlab code with octave. Unfortunately this code contains a geotiffread function and I think I should change this function with rasterread (package mapping).
However, when I try to install the mapping package I get this warning:
octave:7> pkg install mapping-1.4.0.tar.gz
configure: WARNING: GDAL library not found. Reading of raster files will be disabled.
For information about changes from previous versions of the mapping package, run 'news mapping'.
I tried to run octave (5.2.0 version) within:
a Debian Buster distribution (snap and flatpak package)
a docker container (MacOS 10.15 host, installed from the mtmiller/octave image).
online with the octave-online service, running this code:
pkg load mapping;
[bands, info] = rasterread ('mexutm250.tiff');
With this output:
octave:3> source("my_script.m")
error: gdalread: reading of raster file with GDAL was disabled during installation
error: called from
rasterread at line 56 column 26
my_script at line 2 column 15
No attempt was successful.
EDIT 2: I know that my octave installations are without GDAL support. I would like to use octave with full mapping package, and GDAL support, without recompile it. There is a way to do it (e.g. update a library path within the docker installation to add the libgdal library)?
If there is no way to add GDAL support without recompile octave, there is a guide to do it with minimal effort?
EDIT 3: I already installed the gdal dependencies:
$ sudo aptitude search gdal |grep ^i
[sudo] password for virtuser:
i gdal-bin - Geospatial Data Abstraction Library - programmi di utilità
i A gdal-data - libreria Geospatial Data Abstraction Library - file di dati
i libgdal-dev - libreria Geospatial Data Abstraction Library - file di sviluppo
i libgdal20 - libreria Geospatial Data Abstraction Library
Thank you.
I got octave with GDAL integration when I installed the octave package from the debian repository. I needed octave 5.2, so I switched to Ubuntu 20.04.
as suggested in one of the comments, checking
>> news mapping
(also at https://octave.sourceforge.io/mapping/NEWS.html)
looking at mapping 1.2.1 where rasterread was introduced, it states:
** New features
Reading GIS raster data: A first go is provided using
functions rasterread.m and rasterinfo.m. Both invoke binary
function gdalread() of which an initial version was provided
by Shashank Khare. rasterread.m and rasterinfo.m can read
and return info on any raster data type that the underlying
GDAL library can read. As such, separate functions for e.g.,
GeoTIFF and ArcGrid etc. are not required.
To make use of these functions the GDAL library must be
present on your system => GDAL is a suggested dependency.
You should be able to install the GDAL library in Debian using your preferred installation method.
Unsure whether or not you'll need to uninstall/reinstall the mapping package afterward, but if an unload/reload doesn't get rid of the message, try that and see if mapping is able to see the library.

How to install cudnn.torch?

Their page contains Installation section but it is not understandable by one, who does not know torch and lua (like me): section enumerates prerequisites installtion, but has no word about cudnn.torch itself.
Repository contains bunch of lua files. What to do with them to "install"?
You have to install cuda first (https://developer.nvidia.com/cuda-downloads), then download the cudnn bindings (https://developer.nvidia.com/cuda-downloads).
Then if you have already installed torch, luarocks install cudnn should be enough.
For a full installation, you can have a look at this tuto.
You need to install from the github repo:
git clone https://github.com/soumith/cudnn.torch
cd cudnn.torch
luarocks make
Depending on your installed version of CUDA you may need to specify a specific branch of the repo, e.g. git clone https://github.com/soumith/cudnn.torch.git -b R7

Does luarocks management have "./node_modules" equivalent for projects?

In NodeJS/NPM, you can create a package.json and run npm install to install all your dependencies in a folder within your project: ./node_modules. (A project can be an app or another module/package.)
Ruby also has a "bundler" system (using a .bundle file) that keeps track of gems specific to a dir (ie project).
Does LuaRocks have similar conventions? Or is it recommeneded to install everything to /usr or $HOME?
So far I've been able to get similiar functionality, but I have to create a custom LuaRocks config file and specify --tree=my_local_lua_rocks_dir every time I want to install a rock. Granted, I can always create a bash script. The point is that it seems I'm going against a convention.
It is possible to install rocks into a directory under the current directory, using the --tree flag:
luarocks install --tree ./lua_modules lpeg
And then you have to configure your package.path and package.cpath variables in Lua (settable via LUA_PATH and LUA_CPATH environment variables) so it finds the modules installed inside it. There are several ways to do this conveniently: this tutorial explains how to do it, with more examples.
Instead of using Vert, I've decided to just edit the LuaRocks config file:
In /etc/luarocks/config.lua :
rocks_servers = {
[[http://rocks.moonscript.org/]],
[[http://luarocks.org/repositories/rocks]]
}
rocks_trees = {
[[/usr/local]],
[[./my_dir]]
}
./my_dir is relative to the pwd you're in, not to the location of the config file. Of course, change my_dir to whatever you want.
"The order of the rock_trees matters: When installing rocks, LuaRocks tries to pick a location to store the rock starting from the bottom of the list; when loading rocks in runtime, LuaRocks scans from the top of the list." From: http://luarocks.org/en/Config_file_format
Then in your .bashrc:
eval `luarocks path`
export PATH=$PATH:my_dir/bin
However, for certain commands you now have to specify the tree or it will give you a confusing error:
luarocks make --tree=my_dir

Lua: Install a rock using luarocks from a locally installed rock (or from a .zip/.tar.gz)

I hunted around but I couldn't determine if this is possible.
Basically, http://luarocks.org is down, and I already have a copy of luafilesystem installed on another machine locally here. With Ruby, it's possible to cross install ruby gems using the 'gem' command locally. I'm wondering if the same is possible with rocks and luarocks.
Is there any way to 'cross-install' a rock (for instance, luafilesystem), by using another local installation of that rock?
Something like:
luarocks install //10.0.1.123/machine/path/to/luafilesystem/on/other/machine
is what I'd like to be able to do.
UPDATE: I'd even be happy with how to install a rock from the .tar.gz or .zip, for instance, if I downloaded one of the images from this location (in the case of LuaFileSystem).
In which case, the 'source' for the install would / could be local to the machine, rather than remote (and wouldn't necessarily already be installed as a rock).
If you have the source zip, you can unpack it and point luarocks to the the rockspec file. Here is how I installed 'busted' from source.
git clone https://github.com/Olivine-Labs/busted.git
luarocks install busted/busted-1.3-1.rockspec
Or install it directly from source
cd busted
luarocks make
LuaRocks has a pack subcommand that will create a binary rock (a zip file containing all files for an installed module). You can use that binary rock to install the same module on another computer, given that the architecture matches.
E.g.
luarocks pack luafilesystem
produces luafilesystem-1.6.2-2.linux-x86_64.rock on my machine, and
luarocks install luafilesystem-1.6.2-2.linux-x86_64.rock
will reinstall luafilesystem with no internet connection necessary.
If Someone want an installation from the local source rock.
Just do this:
cd /path/to/source-rock
luarocks make source-rock.rockspec
NOTE:
Use make instead of install. The reason is here (quoted below).
LuaRocks offers this:
make Compile package in current directory using a rockspec.
install Install a rock.
However, install does not utilize the present make. It tries
to download and recompile the same package from the server instead
of the one I customized locally.
Any way round this?
The make command will actually build and install your customized
rockspec. The poor naming choice causes confusion every now and then,
I know.

Resources