ofek / userpath

Cross-platform tool for adding locations to the user PATH, no elevated privileges required!
MIT License
151 stars 20 forks source link

homebrew (wip) #4

Closed AlJohri closed 4 years ago

AlJohri commented 5 years ago

Here is a work in progress homebrew formula. Just the testing section needs to be filled out:

class Userpath < Formula
  include Language::Python::Virtualenv

  desc "Cross-platform tool for adding locations to the user PATH"
  url "https://files.pythonhosted.org/packages/24/7b/3b991e87d08211a95bafcadc370cb17e75a7dfb51e6f9ce9247f8cfff4c0/userpath-1.1.0.tar.gz"
  sha256 "c4aa4b20298d14272e2a39047a38a7e2195c1d697dd37dec247e2331067e7f31"

  depends_on "python3"

  resource "click" do
    url "https://files.pythonhosted.org/packages/f8/5c/f60e9d8a1e77005f664b76ff8aeaee5bc05d0a91798afd7f53fc998dbc47/Click-7.0.tar.gz"
    sha256 "5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
  end

  def install
    xy = Language::Python.major_minor_version "python3"

    ENV.prepend_create_path "PYTHONPATH", libexec/"vendor/lib/python#{xy}/site-packages"
    resources.each do |r|
      r.stage do
        system "python3", *Language::Python.setup_install_args(libexec/"vendor")
      end
    end

    ENV.prepend_create_path "PYTHONPATH", libexec/"lib/python#{xy}/site-packages"
    system "python3", *Language::Python.setup_install_args(libexec)
    bin.install Dir["#{libexec}/bin/*"]
    bin.env_script_all_files(libexec/"bin", :PYTHONPATH => ENV["PYTHONPATH"])
  end

  test do
    false
  end
end

pipx formula for reference: https://github.com/Homebrew/homebrew-core/blob/master/Formula/pipx.rb

AlJohri commented 4 years ago

Latest formula

class Userpath < Formula
  include Language::Python::Virtualenv

  desc "Cross-platform tool for adding locations to the user PATH"
  url "https://files.pythonhosted.org/packages/32/92/4abff0a80d028a306e00bf82f8b21ff18d9ad8199b6d179da3521edf83af/userpath-1.2.0.tar.gz"
  sha256 "10fa2a90c61546f188989680a9b7510888b976f5d18503ad4482c8f919e783cb"

  depends_on "python3"

  resource "click" do
    url "https://files.pythonhosted.org/packages/f8/5c/f60e9d8a1e77005f664b76ff8aeaee5bc05d0a91798afd7f53fc998dbc47/Click-7.0.tar.gz"
    sha256 "5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
  end

  resource "distro" do
    url "https://files.pythonhosted.org/packages/ca/e3/78443d739d7efeea86cbbe0216511d29b2f5ca8dbf51a6f2898432738987/distro-1.4.0.tar.gz"
    sha256 "362dde65d846d23baee4b5c058c8586f219b5a54be1cf5fc6ff55c4578392f57"
  end

  def install
    xy = Language::Python.major_minor_version "python3"

    ENV.prepend_create_path "PYTHONPATH", libexec/"vendor/lib/python#{xy}/site-packages"
    resources.each do |r|
      r.stage do
        system "python3", *Language::Python.setup_install_args(libexec/"vendor")
      end
    end

    ENV.prepend_create_path "PYTHONPATH", libexec/"lib/python#{xy}/site-packages"
    system "python3", *Language::Python.setup_install_args(libexec)
    bin.install Dir["#{libexec}/bin/*"]
    bin.env_script_all_files(libexec/"bin", :PYTHONPATH => ENV["PYTHONPATH"])
  end

  test do
    system 'mkdir -p temphome'
    system 'userpath append --force --shell bash --home "temphome" /randompath >/dev/null 2>&1 || true'
    system 'grep -q "/randompath" temphome/.bash_profile'
  end
end

@ofek can you help me write a test? I'm having trouble getting --home to work.

mkdir -p temphome
touch temphome/.bash_profile
userpath append --shell bash --home "temphome" ~/.local/bin
# assert path in temphome/.bash_profile
rm -rf temphome

EDIT: updated with final formula including test

ofek commented 4 years ago

@AlJohri Sorry, what's not working?

AlJohri commented 4 years ago

Please try running the short snippet above or let me know if that invocation looks incorrect.

ofek commented 4 years ago

Oh do you mean the error checking? We could do 2 things:

  1. Temporarily swap out the real files during the test so you don't have to use --home
  2. Make a flag to not verify if invocations were successful

Up to you, let me know 🙂

AlJohri commented 4 years ago

got it, I didn't realize it was just failing the validation. I can work around that then for now.

mkdir -p temphome
userpath append --force --shell bash --home "temphome" /randompath >/dev/null 2>&1 || true
grep -q "/randompath" temphome/.bash_profile

updating the comment above with the final formula

proinsias commented 4 years ago

Any updates on this? (Thanks for leading the charge on it!)

AlJohri commented 4 years ago

@proinsias I was waiting for https://github.com/ofek/userpath/issues/3 but I suppose its not technically a blocker. The current behavior is differing from my expectations so I wasn't planning on using it until #3 is fixed

happy to submit it earlier if you need it

proinsias commented 4 years ago

"Need" is a strong word :) I am certainly looking forward to Homebrew/homebrew-core#40300 getting merged, which I believe is dependent on this PR.

AlJohri commented 4 years ago

@proinsias is there a particular feature you need from 0.14.0.0? you should already be able to brew install pipx, right?

proinsias commented 4 years ago

pipx completions. This is from 0.13.2.0 though, so an upgrade to 0.14.0.0 isn't necessary, but I didn't want to propose an upgrade to 0.13.2.0 if you were close to finishing this.

AlJohri commented 4 years ago

Closing this issue for now as pipx no longer needs userpath as a top level tool.