apkbuild-pypi.in: Updates to fix some issues

This commit is contained in:
Timothy Legge 2021-01-22 21:17:41 -04:00
parent 7e754436f1
commit 82b4d9bf43
1 changed files with 87 additions and 12 deletions

View File

@ -4,6 +4,7 @@ use strict;
use warnings;
use autodie qw(:all);
use feature qw(:5.14);
use experimental 'switch';
use LWP::UserAgent;
use LWP::ConnCache;
use JSON;
@ -13,20 +14,22 @@ my %pkgmap = ();
my %licenses = ();
my $template = <<'EOF';
# Automatically generated by apkbuild-pypi, template 3
[% authors %]
pkgname=[% pkgname %]
#_pkgreal is used by apkbuild-pypi to find modules at PyPI
_pkgreal=[% pkgreal %]
pkgver=[% pkgver %]
pkgrel=0
pkgrel=[% pkgrel %]
pkgdesc="[% pkgdesc %]"
provides="[% provides %]"
replaces="[% replaces %]"
url="http://packages.python.org/pypi/[% pkgreal %]"
arch="noarch"
license="[% license %]"
pydepends=""
pymakedepends=""
depends="python3 $pydepends"
depends="python3"
checkdepends="python3-dev"
makedepends="py3-setuptools $pymakedepends"
makedepends="py3-setuptools"
subpackages=""
source="[% source %]"
builddir="$srcdir/$_pkgreal-$pkgver"
@ -35,6 +38,10 @@ build() {
python3 setup.py build
}
check() {
python3 setup.py test
}
package() {
PYTHONPATH=$pkgdir`python3 -c "import site; print(site.getsitepackages()[0])"` \
python3 setup.py install \
@ -43,10 +50,6 @@ package() {
--single-version-externally-managed
}
check() {
python3 setup.py test
}
EOF
my $ua = LWP::UserAgent->new();
@ -67,12 +70,18 @@ sub read_assignments_from_file {
return () if ( ! -e $filename );
my $text = read_file($filename);
my %sline = $text =~ /^(\w+)\s*=\s*([^\"\n]*)$/mg;
my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\"$/mg;
my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\".*$/mg;
my %hash = ( %sline, %mline );
my $authors = join("\n", $text =~ /^# Contributor: .*$/mg, $text =~ /^# Maintainer: .*$/mg);
$hash{'authors'} = $authors if length($authors) > 1;
my $provides = $text =~ m/provides=\"(.*)\"".*/mg;
$hash{'provides'} = $1 if length($provides) >= 1;
my $requires = $text =~ m/^requires=\"(.*)\"".*$/mg;
$hash{'requires'} = $1 if length($requires) >= 1;
return \%hash;
}
@ -104,16 +113,35 @@ sub read_apkbuild {
}
sub write_apkbuild {
my ($distdata, $authors) = @_;
my ($distdata, $apkbuild) = @_;
my $replaces = undef;
my $provides = undef;
my $authors = undef;
my $pkgrel = 0;
if (defined $apkbuild) {
$authors = $apkbuild->{authors};
$provides = $apkbuild->{provides};
$replaces = $apkbuild->{replaces};
$pkgrel = $apkbuild->{pkgrel};
if ($apkbuild->{pkgver} eq $distdata->{info}{version}) {
$pkgrel++;
}
}
my %repl = (
authors => ($authors or "# Contributor: $packager\n# Maintainer: $packager"),
pkgname => map_pypi_to_apk($distdata->{info}{name}),
pkgreal => $distdata->{info}{name},
pkgver => $distdata->{info}{version},
pkgrel => $pkgrel,
source => get_source($distdata),
license => map_license($distdata->{info}{license}),
pkgdesc => $distdata->{info}{summary},
provides => ($provides or ''),
replaces => ($replaces or ''),
);
$template =~ s/\[% (.*?) %\]/$repl{$1}/g;
@ -130,6 +158,34 @@ sub prepare_tree {
system('abuild checksum unpack prepare');
}
sub find_package_name {
my ($apkbuild) = @_;
my $pkgreal = '';
if (exists $apkbuild->{_realname}) {
$pkgreal = $apkbuild->{_realname};
} elsif (exists $apkbuild->{_pkgreal}) {
$pkgreal = $apkbuild->{_pkgreal};
} elsif (exists $apkbuild->{_pkgname}) {
$pkgreal = $apkbuild->{_pkgname};
} elsif (exists $apkbuild->{_name}) {
$pkgreal = $apkbuild->{_name};
} elsif (exists $apkbuild->{_realpkgname}) {
$pkgreal = $apkbuild->{_realpkgname};
} elsif (exists $apkbuild->{_pkg_real}) {
$pkgreal = $apkbuild->{_pkg_real};
} elsif (exists $apkbuild->{source}) {
$pkgreal = $apkbuild->{source};
$pkgreal =~ m/(\w+)-/;
$pkgreal = $1;
} else {
print "No pkg real found\n";
die;
}
return $pkgreal;
}
sub get_data {
my ($package) = @_;
my $response = $ua->get("https://pypi.python.org/pypi/$package/json");
@ -205,13 +261,27 @@ given ($ARGV[0]) {
get_deps($data);
} when ('recreate') {
my $apkbuild = read_apkbuild;
if (! defined $apkbuild->{_pkgreal}) {
$apkbuild->{_pkgreal} = find_package_name($apkbuild);
}
my $distdata = get_data($apkbuild->{_pkgreal});
my $data = write_apkbuild($distdata, $apkbuild->{authors});
my $pkgver = $distdata->{info}{version} =~ s/^[^0-9]+//r;
if ($pkgver ne $apkbuild->{pkgver}) {
#Reset pkgrel on upgrade on recreate
say "Upgrading PyPI module from $apkbuild->{pkgver} to $pkgver";
$apkbuild->{pkgrel}=0;
}
my $data = write_apkbuild($distdata, $apkbuild);
prepare_tree;
get_deps($data);
} when ('upgrade') {
my $apkbuild = read_apkbuild;
if (! defined $apkbuild->{_pkgreal}) {
$apkbuild->{_pkgreal} = find_package_name($apkbuild);
}
my $distdata = get_data($apkbuild->{_pkgreal});
my $pkgver = $distdata->{info}{version};
@ -234,10 +304,15 @@ given ($ARGV[0]) {
}
} when ('check') {
my $apkbuild = read_apkbuild;
if (! defined $apkbuild->{_pkgreal}) {
$apkbuild->{_pkgreal} = find_package_name($apkbuild);
}
my $distdata = get_data($apkbuild->{_pkgreal});
my $pkgver = $distdata->{info}{version};
say "$apkbuild->{pkgname}: Latest version: $pkgver Packaged version: $apkbuild->{pkgver}";
if ($pkgver ne $apkbuild->{pkgver}) {
exit(1);