From 7b1288f65810612002bd895ee1c3a111765e5c88 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Tue, 24 Sep 2019 19:34:34 +0200 Subject: [PATCH 1/3] create: add --python option --- Library/Homebrew/dev-cmd/create.rb | 6 +++++- Library/Homebrew/formula_creator.rb | 10 +++++++++- docs/Manpage.md | 2 ++ manpages/brew.1 | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index 05f7fce691c36..8ee6974c93b66 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -27,6 +27,8 @@ def create_args description: "Create a basic template for a Go build." switch "--meson", description: "Create a basic template for a Meson-style build." + switch "--python", + description: "Create a basic template for a Python build." switch "--no-fetch", description: "Homebrew will not download to the cache and will thus not add its SHA-256 "\ "to the formula for you, nor will it check the GitHub API for GitHub projects "\ @@ -42,7 +44,7 @@ def create_args switch :force switch :verbose switch :debug - conflicts "--autotools", "--cmake", "--go", "--meson" + conflicts "--autotools", "--cmake", "--go", "--meson", "--python" end end @@ -77,6 +79,8 @@ def create :meson elsif args.go? :go + elsif args.python? + :python end if fc.name.nil? || fc.name.strip.empty? diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index dbea710c5e2ea..d8153bde900fd 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -85,6 +85,10 @@ def template # https://rubydoc.brew.sh/Formula # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! class #{Formulary.class_s(name)} < Formula + <% if mode == :python %> + include Language::Python::Virtualenv + + <% end %> desc "#{desc}" homepage "#{homepage}" <% if head? %> @@ -104,6 +108,8 @@ class #{Formulary.class_s(name)} < Formula <% elsif mode == :meson %> depends_on "meson" => :build depends_on "ninja" => :build + <% elsif mode == :python %> + depends_on "python" <% elsif mode.nil? %> # depends_on "cmake" => :build <% end %> @@ -126,6 +132,8 @@ def install system "ninja", "-v" system "ninja", "install", "-v" end + <% elsif mode == :python %> + virtualenv_install_with_resources <% else %> # Remove unrecognized options if warned by configure system "./configure", "--disable-debug", @@ -134,7 +142,7 @@ def install "--prefix=\#{prefix}" # system "cmake", ".", *std_cmake_args <% end %> - <% if mode != :meson and mode != :go %> + <% if mode != :meson and mode != :go and mode != :python %> system "make", "install" # if this fails, try separate make/make install steps <% end %> end diff --git a/docs/Manpage.md b/docs/Manpage.md index 165e32b18c81d..3e459b91c18eb 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -805,6 +805,8 @@ a simple example. For the complete API, see: Create a basic template for a Go build. * `--meson`: Create a basic template for a Meson-style build. +* `--python`: + Create a basic template for a Python build. * `--no-fetch`: Homebrew will not download *`URL`* to the cache and will thus not add its SHA-256 to the formula for you, nor will it check the GitHub API for GitHub projects (to fill out its description and homepage). * `--HEAD`: diff --git a/manpages/brew.1 b/manpages/brew.1 index d20766fdd9529..fd6436469f17e 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1028,6 +1028,10 @@ Create a basic template for a Go build\. Create a basic template for a Meson\-style build\. . .TP +\fB\-\-python\fR +Create a basic template for a Python build\. +. +.TP \fB\-\-no\-fetch\fR Homebrew will not download \fIURL\fR to the cache and will thus not add its SHA\-256 to the formula for you, nor will it check the GitHub API for GitHub projects (to fill out its description and homepage)\. . From 3eef564beb4b38fa5476f312095d6decef3e41f3 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Wed, 25 Sep 2019 13:41:56 +0200 Subject: [PATCH 2/3] create: add commented out resource block if --python --- Library/Homebrew/formula_creator.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index d8153bde900fd..9ff63333fcb93 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -114,6 +114,14 @@ class #{Formulary.class_s(name)} < Formula # depends_on "cmake" => :build <% end %> + <% if mode == :python %> + # Additional Python dependency + # resource "" do + # url "" + # sha256 "" + # end + + <% end %> def install # ENV.deparallelize # if your formula fails when building in parallel <% if mode == :cmake %> From da19c15c101eb3ebecf5b01f9185dc6a92ae6f23 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Wed, 25 Sep 2019 13:59:00 +0200 Subject: [PATCH 3/3] create: simplify conditional in template --- Library/Homebrew/formula_creator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index 9ff63333fcb93..eeb4fdd69310b 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -150,7 +150,7 @@ def install "--prefix=\#{prefix}" # system "cmake", ".", *std_cmake_args <% end %> - <% if mode != :meson and mode != :go and mode != :python %> + <% if mode == :autotools or mode == :cmake %> system "make", "install" # if this fails, try separate make/make install steps <% end %> end