From 58f40bc8369b81bee1e81092f1c85516f4ef8410 Mon Sep 17 00:00:00 2001 From: Corey Hickey Date: Mon, 13 Mar 2023 10:49:38 -0700 Subject: [PATCH 1/2] factor out git cloning This allows other source package classes to add use of this functionality. --- lib/fpm/package.rb | 8 ++++++++ lib/fpm/package/gem.rb | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/fpm/package.rb b/lib/fpm/package.rb index 1bbbd5d7af..92b6513e0d 100644 --- a/lib/fpm/package.rb +++ b/lib/fpm/package.rb @@ -293,6 +293,14 @@ def cleanup_build end end # def cleanup_build + def download_from_git(download_dir, url, branch) + logger.debug("Git cloning in directory #{download_dir}") + safesystem("git", "-C", download_dir, "clone", url, ".") + if branch + safesystem("git", "-C", download_dir, "checkout", branch) + end + end + # List all files in the staging_path # # The paths will all be relative to staging_path and will not include that diff --git a/lib/fpm/package/gem.rb b/lib/fpm/package/gem.rb index 26a45ad419..fac60c4f5b 100644 --- a/lib/fpm/package/gem.rb +++ b/lib/fpm/package/gem.rb @@ -104,11 +104,7 @@ def download(gem_name, gem_version=nil) FileUtils.mkdir(download_dir) unless File.directory?(download_dir) if attributes[:gem_git_repo] - logger.debug("Git cloning in directory #{download_dir}") - safesystem("git", "-C", download_dir, "clone", attributes[:gem_git_repo], ".") - if attributes[:gem_git_branch] - safesystem("git", "-C", download_dir, "checkout", attributes[:gem_git_branch]) - end + download_from_git(download_dir, attributes[:gem_git_repo], attributes[:gem_git_branch]) gem_build = [ "#{attributes[:gem_gem]}", "build", "#{download_dir}/#{gem_name}.gemspec"] ::Dir.chdir(download_dir) do |dir| From 84d5a2295c24c323baaf79c4aaecb67138a13dc9 Mon Sep 17 00:00:00 2001 From: Corey Hickey Date: Mon, 13 Mar 2023 11:01:04 -0700 Subject: [PATCH 2/2] support downloading python modules from git This works the same way as support in gems. New options are: --python-git-repo --python-git-branch --- lib/fpm/package/python.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/fpm/package/python.rb b/lib/fpm/package/python.rb index 5754a053d4..311331a8f2 100644 --- a/lib/fpm/package/python.rb +++ b/lib/fpm/package/python.rb @@ -85,6 +85,15 @@ class FPM::Package::Python < FPM::Package :attribute_name => :python_internal_pip, :default => true + option "--git-repo", "GIT_REPO", + "Use this git repo address as the source of the module instead of " \ + "pypi.", :default => nil + + option "--git-branch", "GIT_BRANCH", + "When using a git repo as the source of the module instead of " \ + "pypi, use this git branch.", + :default => nil + private # Input a package. @@ -125,15 +134,23 @@ def download_if_necessary(package, version=nil) logger.info("Trying to download", :package => package) + target = build_path(package) + FileUtils.mkdir(target) unless File.directory?(target) + if attributes[:python_git_repo] + download_from_git(target, attributes[:python_git_repo], attributes[:python_git_branch]) + return target + else + return download_from_pypi(package, version, target) + end + end # def download_if_necessary + + def download_from_pypi(package, version, target) if version.nil? want_pkg = "#{package}" else want_pkg = "#{package}==#{version}" end - target = build_path(package) - FileUtils.mkdir(target) unless File.directory?(target) - if attributes[:python_internal_pip?] # XXX: Should we detect if internal pip is available? attributes[:python_pip] = [ attributes[:python_bin], "-m", "pip"] @@ -193,7 +210,7 @@ def download_if_necessary(package, version=nil) raise "Unexpected directory layout after easy_install. Maybe file a bug? The directory is #{build_path}" end return dirs.first - end # def download + end # def download_from_pypi # Load the package information like name, version, dependencies. def load_package_info(setup_py)