Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support building python modules from a git source #1999

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/fpm/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions lib/fpm/package/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
25 changes: 21 additions & 4 deletions lib/fpm/package/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
Expand Down