Check-in [78fca7c39d]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | - purge pre-refactor stuff - move python package to new api |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
78fca7c39d8a47022bf7f8620e88edfb |
| User & Date: | jls@semicomplete.com 2012-03-01 06:26:03 |
Context
|
2012-03-02
| ||
| 07:17 | - Get things together enough that this works again: fpm -s dir -t rpm -d "zsh" -n testing ~/.zshrc - Move to using clamp instead of optparse check-in: aac642a70e user: jls@semicomplete.com tags: trunk | |
|
2012-03-01
| ||
| 06:26 | - purge pre-refactor stuff - move python package to new api check-in: 78fca7c39d user: jls@semicomplete.com tags: trunk | |
| 01:15 | - disable all the dumb stuff (like brp-repack-jars, library stripping, etc) rpmbuild does by default. FINALLY. - improve the spec to behave correctly with the new package api. check-in: ec3280e511 user: jls@semicomplete.com tags: trunk | |
Changes
Changes to lib/fpm.rb.
1 | require "fpm/namespace" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | require "fpm/namespace" require "fpm/package/dir" require "fpm/package/gem" require "fpm/package/rpm" require "fpm/package/python" #require "fpm/target/deb" #require "fpm/target/rpm" #require "fpm/target/solaris" #require "fpm/target/puppet" #require "fpm/source" #require "fpm/source/dir" #require "fpm/source/gem" #require "fpm/source/pear" #require "fpm/source/python" #require "fpm/source/rpm" #require "fpm/source/tar" |
Deleted lib/fpm/builder.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to lib/fpm/package.rb.
1 2 3 4 5 6 7 8 | require "fpm/namespace" require "socket" # for Socket.gethostname require "cabin" require "tmpdir" # This class is the parent of all packages. # If you want to implement an FPM package type, you'll inherit from this. # | > | 1 2 3 4 5 6 7 8 9 | require "fpm/namespace" require "fpm/util" require "socket" # for Socket.gethostname require "cabin" require "tmpdir" # This class is the parent of all packages. # If you want to implement an FPM package type, you'll inherit from this. # |
| ︙ | ︙ |
Added lib/fpm/package/pyfpm/__init__.py.
> | 1 | __all__ = [ "list_dependencies" ] |
Added lib/fpm/package/pyfpm/get_metadata.py.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
from distutils.core import Command
import json
import re
import time
# Note, the last time I coded python daily was at Google, so it's entirely
# possible some of my techniques below are outdated or bad.
# If you have fixes, let me know.
class get_metadata(Command):
description = "get package metadata"
user_options = []
def initialize_options(self):
pass
# def initialize_options
def finalize_options(self):
pass
# def finalize_options
def run(self):
#print type(self.distribution)
#for i in sorted(dir(self.distribution)):
#if i.startswith("_"):
#continue
###print "%s: %r" % (i, self.__getattr__(i))
#print "%s" % i
data = {
"name": self.distribution.get_name(),
"version": self.distribution.get_version(),
"author": "%s <%s>" % (self.distribution.get_author(),
self.distribution.get_author_email()),
"description": self.distribution.get_description(),
"license": self.distribution.get_license(),
"url": self.distribution.get_url(),
}
# If there are python C/extension modules, we'll want to build a native
# arch package.
if self.distribution.has_ext_modules():
data["architecture"] = "native"
else:
data["architecture"] = "all"
# end if
dependencies = None
try:
dependencies = self.distribution.install_requires
except:
pass
# In some cases (Mysql-Python) 'dependencies' is none, not empty.
if dependencies is None:
dependencies = []
# Some cases (like paramiko) dependencies is actually just a string, not a
# list
if isinstance(dependencies, str):
dependencies = [dependencies]
final_deps = []
dep_re = re.compile("([^<>= ]+)(?:\s*([<>=]{1,2})\s*([^,]*))?(?:,\s*([<>=]{1,2})\s*(.*))?$")
for dep in dependencies:
# python deps are strings that look like:
# "packagename"
# "packagename >= version"
# Replace 'packagename' with 'python#{suffix}-packagename'
m = dep_re.match(dep)
if m is None:
print "Bad dep: %s" % dep
time.sleep(3)
elif m.groups()[1] is None:
name, cond, version = m.groups()[0], ">=", 0
else:
groups = m.groups()
name, cond, version = groups[0:3]
if groups[3] is not None:
final_deps.append("%s %s %s" % (groups[0],
self._replace_deprecated(groups[3]),
groups[4]))
# end if
final_deps.append("%s %s %s" % (name,
self._replace_deprecated(cond),
version))
# end for i in dependencies
data["dependencies"] = final_deps
#print json.dumps(data, indent=2)
try:
print json.dumps(data, indent=2)
except AttributeError, e:
# For Python 2.5 and Debian's python-json
print json.write(data)
# def run
def _replace_deprecated(self, sign):
"""Replace deprecated operators"""
return {'<': '<<', '>': '>>'}.get(sign, sign)
# class list_dependencies
|
Added lib/fpm/package/python.rb.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
require "fpm/namespace"
require "fpm/source"
require "fpm/util"
require "rubygems/package"
require "rubygems"
require "fileutils"
require "tmpdir"
require "json"
class FPM::Source::Python < FPM::Source
def self.flags(opts, settings)
settings.source[:python] = "python"
settings.source[:easy_install] = "easy_install"
settings.source[:pypi] = "http://pypi.python.org/simple"
opts.on("--bin PYTHON_BINARY_LOCATION",
"The path to the python you want to run. Default is 'python'") do |path|
settings.source[:python] = path
end
opts.on("--easyinstall EASY_INSTALL_PATH",
"The path to your easy_install tool. Default is 'easy_install'") do |path|
settings.source[:easy_install] = path
end
opts.on("--pypi PYPI_SERVER",
"PyPi Server uri for retrieving packages. Default is 'http://pypi.python.org/simple'") do |pypi|
settings.source[:pypi] = pypi
end
opts.on("--package-prefix PREFIX",
"Prefix for python packages") do |package_prefix|
settings.source[:package_prefix] = package_prefix
end
end # def flags
def input(package)
path_to_package = download_if_necessary(package, version)
load_package_info(path_to_package)
install_to_staging(path_to_package)
end # def input
def download_if_necessary(package, version=nil)
path = package
# If it's a path, assume local build.
if File.directory?(path) or (File.exists?(path) and File.basename(path) == "setup.py")
return path
end
@logger.info("Trying to download", :package => package)
@tmpdir = ::Dir.mktmpdir("python-build", ::Dir.pwd)
if version.nil?
want_pkg = "#{package}"
else
want_pkg = "#{package}==#{version}"
end
# TODO(sissel): support a settable path to 'easy_install'
# TODO(sissel): support a tunable for uthe url to pypi
safesystem("easy_install", "-i", "http://pypi.python.org/simple",
"--editable", "-U", "--build-directory", @tmpdir, want_pkg)
# easy_install will put stuff in @tmpdir/packagename/, so find that:
# @tmpdir/somepackage/setup.py
dirs = ::Dir.glob(File.join(@tmpdir, "*"))
if dirs.length != 1
raise "Unexpected directory layout after easy_install. Maybe file a bug? The directory is #{@tmpdir}"
end
return dirs.first
end # def download
def load_package_info(package_path)
if File.directory?(setup_py)
package_path = File.join(setup_py, "setup.py")
end
if !File.exists?(setup_py)
@logger.error("Could not find 'setup.py'", :path => package_path)
raise "Unable to find python package; tried #{setup_py}"
end
if !attributes.include?(:package_name_prefix)
attributes[:package_name_prefix] = "python"
end
pylib = File.expand_path(File.dirname(__FILE__))
setup_cmd = "env PYTHONPATH=#{pylib} #{self[:settings][:python]} #{setup_py} --command-packages=pyfpm get_metadata"
output = ::Dir.chdir(File.dirname(setup_py)) { `#{setup_cmd}` }
puts output
metadata = JSON.parse(output[/\{.*\}/msx])
self.architecture = metadata["architecture"]
self.description = metadata["description"]
self.license = metadata["license"]
self.version = metadata["version"]
self.url = metadata["url"]
# Sanitize package name.
# Some PyPI packages can be named 'python-foo', so we don't want to end up
# with a package named 'python-python-foo'.
# But we want packages named like 'pythonweb' to be suffixed
# 'python-pythonweb'.
self.name = fix_name(metadata["name"])
self[:dependencies] += metadata["dependencies"].collect do |dep|
name, cmp, version = dep.split
name = fix_name(name)
"#{name} #{cmp} #{version}"
end
end # def load_package_info
def fix_name(name)
if name.start_with?("python")
# If the python package is called "python-foo" strip the "python-" part while
# prepending the package name prefix.
return [attributes[:package_name_prefix], name.gsub(/^python-/, "")].join("-")
else
return [attributes[:package_name_prefix], name].join("-")
end
end # def fix_name
def install_to_staging(package_path)
dir = File.dirname(package_path)
# Some setup.py's assume $PWD == current directory of setup.py, so let's
# chdir first.
::Dir.chdir(dir) do
# TODO(sissel): Make the path to 'python' tunable
# TODO(sissel): Respect '--prefix' somewhow from the caller?
safesystem("python", "setup.py", "install", "--prefix", staging_path)
end
clean
end # def make_tarball!
def clean
FileUtils.rm_r(@tmpdir)
end # def clean
end # class FPM::Source::Python
|
Deleted lib/fpm/source.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/dir.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/gem.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/npm.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/pear.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/python.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/rpm.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted lib/fpm/source/tar.rb.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |