Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First homebrew formula, don't understand the installation process after collecting dependencies and resources

Context (Skip Unless Desired)

I'm am a super nub, in context, here, so please be nice! The project I want to write a formula for is used in the context of cognitive psychology research; it won't, probably, see a very broad distribution simply because the user base is very narrow; to date I've just been running around installing this by hand on everyone's computers. But it's finally getting sufficient use that this is no longer viable.

The only 'Ruby' I know is from writing SCSS/Sass, so I'm mostly just copy-and-pasting my way to something like success.

Problem

In a nut shell, I am trying to distribute a project I've been working on for a while via Homebrew. It includes:

  • Mostly a largish Python module I've written
  • a Python-based CLI for interacting with said module
  • some template files used by the CLI to when using the module to create things
  • several Python dependencies
  • one Python dependency not distributed by PyPi but available on GitHub
  • one compiled Python dependency that is distributed 3rd party and usually with a hardware purchase
  • sdl2
  • some frameworks you've never heard of

I understand:

  • How to specify brewable dependencies
  • how to include my Python dependencies as resources. I've written a very simply setup.py for my module that I've been using for about a year, but, all the other bits I've been installing manually.
  • How to install certain basic, canonical aspects of the project (i.e. Getting the CLI linked into /usr/local/bin

I do not understand:

  • how to actually install anything in Cellar How to install certain odds and ends not covered by the fragments of homebrew-speak I've snagged from reading formulas
  • get all these bits to find each other once they're in the Cellar (I mean I abstractly understand that this is achieved with symlinks and $PATH variables, but concretely, this is out of my depth—I'm a self-taught web-developer-turned-programmer-for-the-lab-I-work-at)
  • where to place the CLI and it's template files, and how to configure setup.py (if indeed setup.py is where this should be done) to expect them at their brewed location

Worth noting is that my lab uses the system Python. I'm not opposed to this running in a brew-installed version of Python (indeed I'd prefer it), but, the install can't cause the system Python to stop being the default version used at the command line, mostly because the intended userbase (i.e. Coders with a very low proficiency) will panic and flee if their memorized routines for executing their programs fail and I can't guarantee they haven't installed things in the the system site-packages directory (sorry).

If any of this was unclear, by all means throw questions at me I'll be happy to clarify.

Here's a link to the Git repository for reference to the directory structure of the project.

My script to date isn't very big, here's as far as I've gotten:

class Klibs < Formula
  desc ""
  homepage ""
  url "https://github.com/jmwmulle/klibs/archive/0.9.1.4.tar.gz"
  version "0.9.1.4"
  # sha256 is wrong; just been editing the local cache while I learn how to do this properly :S
  # (in case anyone tries to brew create the repository and notices)
  sha256 "d854b85fc6fae58a9f6d046c206a73ac8c5948e89740cd55c02450e1ba9af0e0"

  depends_on :python if MacOS.version <= :snow_leopard
  depends_on "sdl2"         => :required
  # bunch of other brewable dependencies

  resource "PySDL2" do
    url "https://pypi.python.org/packages/source/P/PySDL2/PySDL2-0.9.3.zip"
   sha1 "030f2351d1da387f878e14c8a86e08571d7baf5b"
  end  

  # ...bunch of other python modules

  resource "AggDraw" do  # note that this one's not hosted by PyPi
    url "https://github.com/preo/aggdraw.git"
    sha1 "92e5e75aaaf5c535735d974764472e7e4d8e5cb0"
  end

  def install
      resource("PySDL2").stage { system "python", *Language::Python.setup_install_args(libexec/"vendor") }
      # and, again, more python modules
      cd "klibs" do
          ENV.prepend_create_path "PYTHONPATH", libexec/"lib/python2.7/site-packages"
          cd "lib/pylink" do
              cd "frameworks/eyelink" do
                  frameworks.install("eyelink_core_graphics.framework")
                  frameworks.install("eyelink_core.framework")
              end   
              # this next part I *know* must be wrong, I'm just not sure how to achieve 
              # this the homebrew way and thought I'd at least demonstrate what 
              # I need to do; this is a pre-compiled, third-party python module
              # that is not distributed by any other means  
              system "cp", "-r", "pylink", "#{libexec}/lib/python2.7/site-packages"
              system "ln", "-s", "#{libexec}/lib/python2.7/site-packages/pylink"
          end
          system "python", "setup.py", "install", "--prefix=#{prefix}"
      end
      bin.install("bin/klibs")
      lib.install("lib/klibs")
  end
  test do
    system "false"
  end
end
like image 407
Jonline Avatar asked Dec 08 '15 19:12

Jonline


People also ask

Does Homebrew install from source?

Homebrew's pre-built binary packages (known as bottles) of many formulae can only be used if you install in the default installation prefix, otherwise they have to be built from source. Building from source takes a long time, is prone to failure, and is not supported.

Where are brew formulas installed?

Packages are installed according to their formulae, which live in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula .

What is a formula in Homebrew?

A formula provides instructions and metadata for Homebrew to install a piece of software. Every Homebrew formula is a Formula. All subclasses of Formula (and all Ruby classes) have to be named UpperCase and not-use-dashes . A formula specified in this-formula.


1 Answers

Well, homebrew is not the best medium for packaging and distributing code (OSX only). You probably want to look at: http://python-packaging-user-guide.readthedocs.org/en/latest/distributing/. Depending on how you write your code; you may be able to put your requirements directly in your setup.py rather than put them in a homebrew recipe.

As for packages that you are using that are not on PyPI; ask yourself the following questions:

  • Does the code I want to use have the proper software license?
  • Can I open an issue on the github projects so the owners put them on PyPI?

getting machines to conform to a particular config

If you are managing a farm of machines:

  • chef, puppet, salt, ansible, ...

If you only care about the distribution:

  • setuptools + virtualenv + pip makes a good combo.
  • pip is able to install requirements from PyPI, github, file servers, ...
like image 163
dnozay Avatar answered Nov 10 '22 00:11

dnozay