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

add support for building python package from pypi directly #29

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
799f048
added hg-multipkg that can checkout and build from a mercurial repo
jianingy Mar 19, 2013
054e0d3
use /usr/bin/perl in the case that /usr/local/bin/perl does not exist
jianingy Mar 19, 2013
5d0056b
added debian's control template
jianingy Mar 19, 2013
a9b5208
remove trailing spaces in control.template
jianingy Mar 19, 2013
831be12
Merge branch 'deb-issues'
jianingy Mar 19, 2013
04239a3
added support for debian package
jianingy Mar 19, 2013
cdec502
Merge branch 'deb-issues'
jianingy Mar 19, 2013
6a4e5d5
use /usr/bin/perl for deb packaging
jianingy Mar 19, 2013
4269a84
Merge branch 'deb-issues'
jianingy Mar 19, 2013
815e14a
merged from debian-issues
jianingy Mar 20, 2013
0d6175a
add support for fetching source using http protocol
jianingy Mar 21, 2013
e770d3e
reset confdir to original value
jianingy Mar 21, 2013
15185b4
Merge branch 'http-module'
jianingy Mar 21, 2013
d87f860
add git-module which can get source from a git repo
jianingy Mar 22, 2013
863a817
Merge branch 'git-module'
jianingy Mar 22, 2013
82f1017
add support of installing build requires before building
jianingy Mar 23, 2013
e2746e4
Merge branch 'buildrequires'
jianingy Mar 23, 2013
4f6f80c
raise an error when we encounter malformed yamls
jianingy Mar 23, 2013
d5b0697
Merge branch 'malformed-yaml'
jianingy Mar 23, 2013
d97ea8c
fix debian installed package detection
jianingy Mar 23, 2013
43b7417
Merge branch 'buildrequires'
jianingy Mar 23, 2013
00d02f8
add need_build_require and install_build_require to base class
jianingy Mar 24, 2013
880dabc
Merge branch 'buildrequires'
jianingy Mar 24, 2013
8d5397d
eh.. change warning message
jianingy Mar 24, 2013
5dbbfa4
Merge branch 'buildrequires'
jianingy Mar 24, 2013
79ceb63
add a one-step install script install.sh
jianingy Mar 24, 2013
6db1ca4
fix install.sh on debian
jianingy Mar 24, 2013
d185e48
Merge branch 'tools'
jianingy Mar 25, 2013
8c8aa5c
update version to 1.3 beta1
jianingy Mar 25, 2013
714b964
fix wrong Seco::Git package name
jianingy Mar 26, 2013
607aaf8
add support for building python package from pypi
jianingy Mar 26, 2013
5aa4018
Merge branch 'pypi-module'
jianingy Mar 26, 2013
abf3043
add json dependence
jianingy Mar 26, 2013
26a8296
be quiet when downloading pypi index
jianingy Mar 26, 2013
416b081
add environment variable PYTHON
jianingy Mar 29, 2013
4b51965
when build pypi module use scripts/build if it presents
jianingy Mar 29, 2013
e11fa2b
modify pypi.build so it could use other python by PYTHON env
jianingy Mar 29, 2013
19eccb4
add an example of building pypi package
jianingy Mar 29, 2013
07493ed
resolve pypi-module conflicts
jianingy Mar 29, 2013
db3686f
setup PYTHONHOME in pypi.build
jianingy Mar 29, 2013
f2ad819
Merge branch 'pypi-module'
jianingy Mar 29, 2013
2c2821e
use old build script for pypi-module
jianingy Mar 29, 2013
3a79916
Merge branch 'pypi-module'
jianingy Mar 29, 2013
30be328
add support for building package from pecl
jianingy Mar 30, 2013
3365929
Merge branch 'pecl-module'
jianingy Mar 31, 2013
394bb45
message changes, coding format changes
jianingy Apr 1, 2013
a70d5d7
choose the latest version if no version specified
jianingy Apr 1, 2013
f25532c
fix rpm build failure when filename contains spaces
jianingy Apr 7, 2013
846e02b
Merge branch 'filename-with-space-bug'
jianingy Apr 7, 2013
3220715
add multipkg-remote. a tool that can get index.yaml from multipkg adm…
jianingy Apr 8, 2013
ad0c18d
rename multipkg-remote to web-multipkg
jianingy Apr 9, 2013
049f6ef
update version to 1.3.3
jianingy Apr 9, 2013
af6663d
Merged with branch tarball
jianingy Apr 11, 2013
3014f6f
version updated to 1.3.4
jianingy Apr 11, 2013
00227b0
add support for other tarball format for pypi
jianingy Apr 11, 2013
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
7 changes: 7 additions & 0 deletions examples/django/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
default:
name: python2-django
version: 1.5
pypi: Django
summary: Django
python: /home/tops/bin/python
7 changes: 7 additions & 0 deletions examples/http_load/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default:
name: httpload
git: git://github.com/timbunce/http_load.git
git-branch: master
summary: a http load tester
version: 1.0

4 changes: 4 additions & 0 deletions examples/http_load/scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

mkdir -p $DESTDIR/usr/{bin,share/man/man1}
make install BINDIR=$DESTDIR/usr/bin MANDIR=$DESTDIR/usr/share/man/man1
6 changes: 6 additions & 0 deletions examples/nginx/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default:
name: nginx
http: http://nginx.org/download/nginx-1.2.6.tar.gz
version: 1.2.6

# cpan-module will fetch directly from CPAN
3 changes: 3 additions & 0 deletions examples/nginx/scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
./configure --prefix=/opt/nginx --without-pcre --without-http_gzip_module --without-http_rewrite_module
make install DESTDIR=$DESTDIR
4 changes: 3 additions & 1 deletion index.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default:
name: multipkg
version: '1.2'
version: '1.3.4'
summary: Automation for package builds (supports RPM, deb)
buildprefix: /usr
rpm:
Expand All @@ -14,6 +14,7 @@ rpm:
- subversion-perl
- perl-Git
- perl-Error
- perl-JSON
deb:
arch: all
provides:
Expand All @@ -24,3 +25,4 @@ deb:
- libyaml-syck-perl
- libsvn-perl
- liberror-perl
- libjson-perl
48 changes: 48 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

multipkg=$(which multipkg)

if [ -z "$multipkg" ]; then
cp -v source/lib/Seco/Multipkg.pm Multipkg.pm.orig

echo "Installing buildrequires. It may require sudo privileges."

if which yum; then
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y perl-YAML-Syck perl-ExtUtils-MakeMaker
rm -v -f multipkg-*.rpm
elif which dpkg; then
sudo apt-get -y install build-essential
rm -v -f multipkg_*.deb
fi

PREFIX=./root PKGVERID=0 INSTALLDIR=source scripts/transform
perl -I ./source/lib root/usr/bin/multipkg -t .

if which yum; then
sudo yum install -y multipkg-*rpm
rm -v multipkg-*rpm
elif which dpkg; then
sudo dpkg -i multipkg_*deb
rm -v multipkg_*deb
fi

unset PREFIX PKGVERID INSTALLDIR
mv -v Multipkg.pm.orig source/lib/Seco/Multipkg.pm

fi

multipkg -t .

# remove temporarily installed multipkg
if [ -z "$multipkg" ]; then
if which yum; then
sudo yum remove -y multipkg
elif which dpkg; then
sudo dpkg -P multipkg
fi
fi
echo ======================
echo == package build ok ==
echo ======================
ls -alh multipkg*
189 changes: 189 additions & 0 deletions root/usr/bin/hg-multipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/bin/perl -w

# Modified from Noah Meyerhans' git-multipkg, written by Jianing YANG
# <jianingy.yang at gmail dot com>.

# Copyright (c) 2011 Noah Meyerhans <[email protected]> All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the terms of either:

# a) the GNU General Public License as published by the Free
# Software Foundation, version 2, found in the included file GPLv2.
# b) the Perl "Artistic License," found in the included file PERLARTISTIC.

use strict;
use Data::Dumper;
use File::Temp;
use File::Basename;
use File::Spec;
use Getopt::Long;

Getopt::Long::Configure("bundling");

my $opt = {
'b' => '',
'r' => 'tip',
'B' => 'default',
};

my %options = (
'h|help' => 'show usage information',
'b|baseurl=s' => 'base URI for the mercurial repo',
'B|branch=s' => 'branch to build from',
'r|rev=s' => 'revision to build (default=HEAD)',
'k|keep' => 'do not delete the working directory',
'v|verbose' => 'verbose output',
'f|force' => 'Force through multipkg errors',
);

usage() unless GetOptions( $opt, keys %options );
my $package = shift;

usage() if( $opt->{h} );
usage() unless( $opt->{b} );
usage() unless( $package );

my $verbose = $opt->{v};

sub usage {
print <<EOF;

Usage: $0 [options] <package>
Options:
-c, changelog include changelog (NOT IMPLEMENTED)
-m, mtime set mtime on files from last revision (NOT IMPLEMENTED)
-b, baseuri=s base URI for Mercurial repo
-r, rev=s revision to checkout
-B, branch=s branch to build from (default=default)
-k, keep keep the temporary directory
-v, verbose verbose
-p, platform=s platform
-s, set=s List of variables to set
-f, force Force through multipkg errors

EOF
exit(0);
}

sub info { print "info: @_ \n" if ($verbose); }
sub fatal { print "fatal: @_ \n"; exit 111; }

# Clone the source repository to a local directory
sub clone {
my ($repo, $target, $opts) = @_;
info("Cloning from $repo to $target");
my $out = qx(hg clone -u $opts->{B} $repo $target);
info($out);
}

# Call multipkg
sub pkg {
my ($opts, $pkg, $srcdir, $build, $ts) = @_;
info("Invoking multipkg on $srcdir");
# options to pass through to multipkg
my @multipkg_opts = map { ("-$_") } grep { $opts->{$_} } (qw/k v f/);
my $vars = "release=$ts,srcurl=$opts->{b},srcdir=$srcdir";
print "BUILD:$build\n";
system("multipkg", '-s', $vars, @multipkg_opts, $build);
}

# Copy the contents of the hg repository to the build directory
sub archive {
my ($src, $dest, $opts) = @_;
my $cwd = $ENV{PWD};
info("archiving $src to $dest");
my $cmd = "hg archive -p . -t tar -r $opts->{r} - | (cd $dest && tar xf -)";
info("Running $cmd");
chdir($src);
mkdir($dest);
system($cmd);
chdir($cwd);
}

sub get_timestamp {
my ($dir, $rev) = @_;
my $ts = 0;
my $oldPWD = $ENV{PWD};
info("Gathering revision timestamp information for $dir\@$rev");
chdir($dir) or die;
$ts = qx(hg log -r $rev --template '{date|hgdate}');
($ts) = split /\s+/, $ts;
chdir($oldPWD);
die "Did not get a meaningful timestamp for $dir at $rev\n" unless($ts > 0);
return $ts;
}

sub getrepo {
my $path = shift;
return [ split '/', $path ]->[0];
}

sub getpkg {
my $path = shift;
return File::Basename::basename($path);
}

sub getpkgpath {
my $path = shift;
my $repo = getrepo($path);

my $pkgpath = $path;
$pkgpath =~ s{^$repo/?}{};
return $pkgpath;
}

sub main {
my ($opts, $path) = @_;

# Prepare the package, base and repo from the provided base URI

# Package name is always the same
my $pkg = getpkg($path);

# $pkgbase is contrived from the base uri and package path provided
# $repo is fed to hg clone
my ($pkgbase, $repo);

if ($opts->{b} =~ /^http/) {
# can't use File::Spec->catdir for these because it'll destory the two
# slashes in http://whatever.com/repo
my $repoid = getrepo($path);
$repoid =~ s{^/+}{};
my $base = $opts->{b};
$base =~ s{/+$}{};

$repo = "${base}/${repoid}";
$pkgbase = getpkgpath($path);
}
elsif ($opts->{b} =~ /\.hg$/){
$repo = $opts->{b};

# if $path is just a repo name, not a full path...
if ( File::Basename::basename( $path ) eq $path ) {
$pkgbase = '';
}
else {
#otherwise, shave off the first part of the path
$pkgbase = $path;
$pkgbase =~ s{^[^/]+/}{};
}
}
else {
# -b was not provided
# SHOULD NEVER BE REACHED
die "unsupported base";
}

my $dir = File::Temp::tempdir(CLEANUP => ( !defined($opts->{k}) ));
my $build = "$dir/build";
my $clonedir = "$dir/clone";
clone($repo, $clonedir, $opts);

my $srcdir = File::Spec->catdir($dir, 'src');
symlink File::Spec->catdir($clonedir, $pkgbase), $srcdir;
archive($srcdir, $build, $opts);
my $ts = get_timestamp($clonedir, $opts->{r});
pkg($opts, $pkg, $srcdir, $build, $ts);
}

main($opt, $package);
2 changes: 1 addition & 1 deletion root/usr/bin/multipkg
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ sub usage {
}

print sort @array;

print "\nVERSION: ", MULTIPKG_VERSION, "\n";
die "$msg\n";
}

Expand Down
81 changes: 81 additions & 0 deletions root/usr/bin/web-multipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/perl

use strict;
use JSON;
use Getopt::Long;

use constant {
VCS_SUBVERSION => 0,
VCS_GIT => 1,
VCS_MERCURIAL => 2,
};

Getopt::Long::Configure("bundling");
my $opt = {
's' => 'http://multipkg.in',
};

my %options = (
'h|help' => 'show usage information',
's|source' => 'multipkg admin site url',
'v|verbose' => 'show verbose information',
);

usage() unless GetOptions( $opt, keys %options );
my $package = shift;
my $verbose = '-v' if $opt->{v};

usage() if( $opt->{h} );
usage() unless( $package );

sub usage
{
print <<EOF;

Usage: $0 [options] <package>
Options:
-s, source=s URL of multipkg admin site

Examples:
multipkg-install multipkg
multipkg-install -s http://multipkg.in/ multipkg

EOF
exit(0);
}

sub error
{
my $msg = shift;
print STDERR "ERROR: $msg\n";
exit(111);
}

sub main
{
my $json = qx#curl -s '$opt->{s}/multipkg/api/1/search/?format=json\&name=$package'#;
error "admin server error" unless $json;

my $result = JSON->new->utf8->decode($json);
error "package not found" unless $result->{meta}->{total_count} > 0;

my $package = $result->{'objects'}[0];
my @split = split m#/#, $package->{vcs_address};
my $name = pop @split;
my $base = join "/", @split;
$name = join "/", ($name, $package->{vcs_subdir});
$name =~ s/\/$//g;

if ($package->{vcs_type} eq VCS_SUBVERSION) {
print("svn-multipkg $verbose -b $base $name\n");
system("svn-multipkg $verbose -b $base $name");
} elsif ($package->{vcs_type} eq VCS_GIT) {
system("git-multipkg $verbose -b $base $name");
} elsif ($package->{vcs_type} eq VCS_MERCURIAL) {
system("hg-multipkg $verbose -b $base $name");
} else {
die "UNKNOWN VCS TYPE!";
}
}

main();
3 changes: 3 additions & 0 deletions root/usr/share/multipkg/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ default:
buildprefix: '/usr/local'
prefix: '/'
perl: '/usr/bin/perl'
python: '/usr/bin/python'
version: '0.0001'
shebangmunge: 1
os_specific: no
xfercmd: '/usr/bin/curl -s -o %s %u'
git-branch: master

rpm:
autoreqprov: no
Expand Down
Loading