class Pipenv < Formula include Language::Python::Virtualenv desc "Python dependency management tool" homepage "https://docs.pipenv.org/" url "https://files.pythonhosted.org/packages/aa/74/24afb34771d81294f660e1bc2beb06a7ac674f0798bbac505b7ac856a3ae/pipenv-10.1.0.tar.gz" sha256 "3732350e3cd8cc033d66748c418bab4b018dc0a4fcf1687f17a103ac44eac0c6" bottle do cellar :any_skip_relocation sha256 "8b0ce4c9ca0a94d223f0b1de9afa898a5d3f6fe9a9f59f9ebce67102b6e04d96" => :high_sierra sha256 "8d6bca54006eac0036ea3c21cb126e338c3d55a09f2bd0c17553eccac3873c54" => :sierra sha256 "3844ec0d823c570e81f8e2dcb2aeea26c87b90d218b52dad0d2b9e67224ad05e" => :el_capitan end depends_on "python3" resource "certifi" do url "https://files.pythonhosted.org/packages/15/d4/2f888fc463d516ff7bf2379a4e9a552fef7f22a94147655d9b1097108248/certifi-2018.1.18.tar.gz" sha256 "edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d" end resource "chardet" do url "https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz" sha256 "84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae" end resource "idna" do url "https://files.pythonhosted.org/packages/f4/bd/0467d62790828c23c47fc1dfa1b1f052b24efdf5290f071c7a91d0d82fd3/idna-2.6.tar.gz" sha256 "2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f" end resource "pew" do url "https://files.pythonhosted.org/packages/21/8c/585c136d5c63eb80ece3328eb290d16ccf6d2d55420848d9fc6a07de68ca/pew-1.1.2.tar.gz" sha256 "b8312728526c9010295c88215c95a1b1731fdbd1a568f728e069932bd0545611" end resource "requests" do url "https://files.pythonhosted.org/packages/b0/e1/eab4fc3752e3d240468a8c0b284607899d2fbfb236a56b7377a329aa8d09/requests-2.18.4.tar.gz" sha256 "9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e" end resource "urllib3" do url "https://files.pythonhosted.org/packages/ee/11/7c59620aceedcc1ef65e156cc5ce5a24ef87be4107c2b74458464e437a5d/urllib3-1.22.tar.gz" sha256 "cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f" end resource "virtualenv" do url "https://files.pythonhosted.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz" sha256 "02f8102c2436bb03b3ee6dede1919d1dac8a427541652e5ec95171ec8adbc93a" end resource "virtualenv-clone" do url "https://files.pythonhosted.org/packages/36/66/d95f83255138ded1aec242de5ee51536226fa7b2582a7ce0863fea5dc4f2/virtualenv-clone-0.2.6.tar.gz" sha256 "6b3be5cab59e455f08c9eda573d23006b7d6fb41fae974ddaa2b275c93cc4405" end def install # Using the virtualenv DSL here because the alternative of using # write_env_script to set a PYTHONPATH breaks things. # https://github.com/Homebrew/homebrew-core/pull/19060#issuecomment-338397417 venv = virtualenv_create(libexec, "python3") venv.pip_install resources venv.pip_install buildpath # `pipenv` needs to be able to find `virtualenv` and `pew` on PATH. So we # install symlinks for those scripts in `#{libexec}/tools` and create a # wrapper script for `pipenv` which adds `#{libexec}/tools` to PATH. (libexec/"tools").install_symlink libexec/"bin/pew", libexec/"bin/pip", libexec/"bin/virtualenv" env = { :PATH => "#{libexec}/tools:$PATH", } (bin/"pipenv").write_env_script(libexec/"bin/pipenv", env) end # Avoid relative paths def post_install lib_python_path = Pathname.glob(libexec/"lib/python*").first lib_python_path.each_child do |f| next unless f.symlink? realpath = f.realpath rm f ln_s realpath, f end inreplace lib_python_path/"orig-prefix.txt", Formula["python3"].opt_prefix, Formula["python3"].prefix.realpath end test do ENV["LC_ALL"] = "en_US.UTF-8" assert_match "Commands", shell_output("#{bin}/pipenv") system "#{bin}/pipenv", "install", "requests" assert_predicate testpath/"Pipfile", :exist? assert_predicate testpath/"Pipfile.lock", :exist? assert_match "requests", (testpath/"Pipfile").read end end