Pieter van de Bruggen
Another way of looking at the problem is this:
I have a linter that I'd like to use (e.g. git repo, tarball, local directory, whatever), but I can't run it without its runtime (e.g. Ruby), and it may require dependencies installed in that runtime environment (e.g. gems).
Installing the dependencies as described by the linter itself is strongly preferable, but explicitly listing dependencies in the
trunk.yaml
file might be a fair short-term workaround.Eli Schleifer
Conversation from Community Slack
In my case, I’ve got a fork of an existing linter that I’ve fixed a few bugs in. The linter itself is packaged and distributed as a Ruby gem, but I obviously don’t have permissions to publish that gem. While I’d like to see at least some of these changes make their way upstream, I want to be able to demonstrate their correctness first, and I expect that process to take some time.
Additional complications come from the fact that the linter package also has dependencies on other Ruby gems, which would need to be installed in the isolated environment. Ruby’s Bundler tool (for managing a group of dependencies) has built-in tooling to support installing gems from a git repo, though using Rubygems on its own seems to be a little more complicated.
---
TL;DR:
I have a git repository, that describes a Ruby package (gem).
I’d like to be able to use that described package as a linter in Trunk.
That described package depends on other packages, so just copying it into ~/.cache/trunk/linters isn’t quite enough to get me there.
#!/bin/bash
gemifgTMPDIR=$TMPDIR"_gemifg"
git clone $1 $gemifgTMPDIR
gemifgOWD=$PWD
cd $gemifgTMPDIR
gem build *.gemspec
gem install *.gem
if [ ! -z "$gemifgTMPDIR" ]
then
rm -rf $gemifgTMPDIR
fi
cd $gemifgOWD
Idiomatic Ruby would be to add the linter to your Gemfile (read: your application’s or library’s dependencies) as a development dependency, then run bundle install. Bundler takes care to install all of your direct and transient dependencies (whether from a Rubygems server or from a Git repo), and ensure that your application/library has the correct paths available to load dependencies from at runtime.
The Trunk equivalent, to my eye, would be to specify the linter as either a native package for $runtime or a Git repository, and let trunk handle the installation of that package and its dependencies.
For Ruby, cloning the repo then running bundle install is probably good enough for 90% of projects out there, though the behavior outlined in gemgit.sh is technically more correct, since it reuses more of the installation behaviors from the native package system (and covers gems that, for whatever reason, choose to not use Bundler).