Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 1e2f79d

Browse files
author
Matthias Koeppe
committed
Merge branch 't/30865/sage_bootstrap__update_extend_system_package_tools' into t/30947/src_doc_bootstrap__simplify_by_using_new_options_of__sage__package_list_
2 parents 2220595 + b762c3d commit 1e2f79d

File tree

10 files changed

+110
-83
lines changed

10 files changed

+110
-83
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ build/make/Makefile: configure $(SPKG_COLLECT_FILES) $(CONFIG_FILES:%=%.in)
6464
buildbot-python3:
6565
$(MAKE)
6666

67-
# Preemptively download all standard upstream source tarballs.
67+
# Preemptively download all source tarballs of normal packages.
6868
download:
6969
export SAGE_ROOT=$$(pwd) && \
70-
export PATH=$$SAGE_ROOT/src/bin:$$PATH && \
71-
./src/bin/sage-download-upstream
70+
export PATH=$$SAGE_ROOT/build/bin:$$PATH && \
71+
sage-package download :all:
7272

7373
dist: build/make/Makefile
7474
./sage --sdist

build/pkgs/sagelib/src/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
'bin/sage-cleaner',
143143
## Only makes sense in sage-the-distribution. TODO: Move to another installation script.
144144
'bin/sage-list-packages',
145-
'bin/sage-download-upstream',
146145
'bin/sage-location',
147146
## Uncategorized scripts in alphabetical order
148147
'bin/math-readline',

build/sage_bootstrap/app.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def config(self):
4343
from sage_bootstrap.config import Configuration
4444
print(Configuration())
4545

46-
def list_cls(self, package_class):
46+
def list_cls(self, *package_classes, **filters):
4747
"""
4848
Print a list of all available packages
4949
@@ -54,9 +54,19 @@ def list_cls(self, package_class):
5454
autotools
5555
[...]
5656
zn_poly
57+
58+
$ sage -package list --has-file=spkg-configure.m4 :experimental:
59+
perl_term_readline_gnu
60+
61+
$ sage -package list --has-file=spkg-configure.m4 --has-file=distros/debian.txt | sort
62+
arb
63+
boost_cropped
64+
brial
65+
[...]
66+
zn_poly
5767
"""
5868
log.debug('Listing packages')
59-
pc = PackageClass(package_class)
69+
pc = PackageClass(*package_classes, **filters)
6070
for pkg_name in pc.names:
6171
print(pkg_name)
6272

@@ -157,8 +167,13 @@ def download(self, package_name, allow_upstream=False):
157167
package.tarball.download(allow_upstream=allow_upstream)
158168
print(package.tarball.upstream_fqn)
159169

160-
def download_cls(self, package_name_or_class):
161-
pc = PackageClass(package_name_or_class)
170+
def download_cls(self, package_name_or_class, allow_upstream=False):
171+
"""
172+
Download a package or a class of packages
173+
"""
174+
pc = PackageClass(package_name_or_class, has_files=['checksums.ini'])
175+
def download_with_args(package):
176+
return self.download(package, allow_upstream=allow_upstream)
162177
pc.apply(self.download)
163178

164179
def upload(self, package_name):

build/sage_bootstrap/cmdline.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ def make_parser():
200200
help='Print a list of all available packages')
201201
parser_list.add_argument(
202202
'package_class',
203-
type=str, default=':all:', nargs='?',
203+
type=str, default=[':all:'], nargs='*',
204204
help='Package class like :all: (default) or :standard:')
205+
parser_list.add_argument(
206+
'--has-file', action='append', default=[], metavar='FILENAME', dest='has_files',
207+
help='Only include packages that have this file')
205208

206209
parser_name = subparsers.add_parser(
207210
'name', epilog=epilog_name,
@@ -300,7 +303,7 @@ def run():
300303
if args.subcommand == 'config':
301304
app.config()
302305
elif args.subcommand == 'list':
303-
app.list_cls(args.package_class)
306+
app.list_cls(*args.package_class, has_files=args.has_files)
304307
elif args.subcommand == 'name':
305308
app.name(args.tarball_filename)
306309
elif args.subcommand == 'tarball':

build/sage_bootstrap/expand_class.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,46 @@
2525

2626
class PackageClass(object):
2727

28-
def __init__(self, package_name_or_class):
29-
if package_name_or_class == ':all:':
30-
self._init_all()
31-
elif package_name_or_class == ':standard:':
32-
self._init_standard()
33-
elif package_name_or_class == ':optional:':
34-
self._init_optional()
35-
elif package_name_or_class == ':experimental:':
36-
self._init_experimental()
37-
elif package_name_or_class == ':huge:':
38-
self._init_huge()
39-
else:
40-
if package_name_or_class.startswith(':'):
41-
raise ValueError('Package name cannot start with ":", got %s', package_name_or_class)
42-
if package_name_or_class.endswith(':'):
43-
raise ValueError('Package name cannot end with ":", got %s', package_name_or_class)
44-
self.names = [package_name_or_class]
45-
46-
def _init_all(self):
47-
self.names = [pkg.name for pkg in Package.all()]
48-
49-
def _init_standard(self):
50-
self.names = [pkg.name for pkg in Package.all() if pkg.type == 'standard']
51-
52-
def _init_optional(self):
53-
self.names = [pkg.name for pkg in Package.all() if pkg.type == 'optional']
54-
55-
def _init_experimental(self):
56-
self.names = [pkg.name for pkg in Package.all() if pkg.type == 'experimental']
57-
58-
def _init_huge(self):
59-
self.names = [pkg.name for pkg in Package.all() if pkg.type == 'huge']
60-
28+
def __init__(self, *package_names_or_classes, **filters):
29+
self.names = []
30+
filenames = filters.pop('has_files', [])
31+
if filters:
32+
raise ValueError('filter not supported')
33+
def included_in_filter(pkg):
34+
return all(pkg.has_file(filename) for filename in filenames)
35+
for package_name_or_class in package_names_or_classes:
36+
if package_name_or_class == ':all:':
37+
self._init_all(predicate=included_in_filter)
38+
elif package_name_or_class == ':standard:':
39+
self._init_standard(predicate=included_in_filter)
40+
elif package_name_or_class == ':optional:':
41+
self._init_optional(predicate=included_in_filter)
42+
elif package_name_or_class == ':experimental:':
43+
self._init_experimental(predicate=included_in_filter)
44+
elif package_name_or_class == ':huge:':
45+
self._init_huge(predicate=included_in_filter)
46+
else:
47+
if package_name_or_class.startswith(':'):
48+
raise ValueError('Package name cannot start with ":", got %s', package_name_or_class)
49+
if package_name_or_class.endswith(':'):
50+
raise ValueError('Package name cannot end with ":", got %s', package_name_or_class)
51+
self.names.append(package_name_or_class)
52+
53+
def _init_all(self, predicate):
54+
self.names.extend(pkg.name for pkg in Package.all() if predicate(pkg))
55+
56+
def _init_standard(self, predicate):
57+
self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'standard' and predicate(pkg))
58+
59+
def _init_optional(self, predicate):
60+
self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'optional' and predicate(pkg))
61+
62+
def _init_experimental(self, predicate):
63+
self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'experimental' and predicate(pkg))
64+
65+
def _init_huge(self, predicate):
66+
self.names.extend(pkg.name for pkg in Package.all() if pkg.type == 'huge' and predicate(pkg))
67+
6168
def apply(self, function, *args, **kwds):
6269
for package_name in self.names:
6370
function(package_name, *args, **kwds)

build/sage_bootstrap/package.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def tarball_filename(self):
146146
147147
String. The full-qualified tarball filename.
148148
"""
149-
return self.tarball_pattern.replace('VERSION', self.version)
149+
pattern = self.tarball_pattern
150+
if pattern:
151+
return self.tarball_pattern.replace('VERSION', self.version)
152+
else:
153+
return None
150154

151155
@property
152156
def tarball_upstream_url_pattern(self):
@@ -236,8 +240,8 @@ def all(cls):
236240
base = os.path.join(SAGE_ROOT, 'build', 'pkgs')
237241
for subdir in os.listdir(base):
238242
path = os.path.join(base, subdir)
239-
if not os.path.isfile(os.path.join(path, "checksums.ini")):
240-
log.debug('%s has no checksums.ini', subdir)
243+
if not os.path.isfile(os.path.join(path, "type")):
244+
log.debug('%s has no type', subdir)
241245
continue
242246
try:
243247
yield cls(subdir)
@@ -251,46 +255,60 @@ def path(self):
251255
Return the package directory
252256
"""
253257
return os.path.join(SAGE_ROOT, 'build', 'pkgs', self.name)
254-
258+
259+
def has_file(self, filename):
260+
"""
261+
Return whether the file exists in the package directory
262+
"""
263+
return os.path.exists(os.path.join(self.path, filename))
264+
255265
def _init_checksum(self):
256266
"""
257267
Load the checksums from the appropriate ``checksums.ini`` file
258268
"""
259269
checksums_ini = os.path.join(self.path, 'checksums.ini')
260270
assignment = re.compile('(?P<var>[a-zA-Z0-9_]*)=(?P<value>.*)')
261271
result = dict()
262-
with open(checksums_ini, 'rt') as f:
263-
for line in f.readlines():
264-
match = assignment.match(line)
265-
if match is None:
266-
continue
267-
var, value = match.groups()
268-
result[var] = value
272+
try:
273+
with open(checksums_ini, 'rt') as f:
274+
for line in f.readlines():
275+
match = assignment.match(line)
276+
if match is None:
277+
continue
278+
var, value = match.groups()
279+
result[var] = value
280+
except IOError:
281+
pass
269282
self.__md5 = result.get('md5', None)
270283
self.__sha1 = result.get('sha1', None)
271284
self.__cksum = result.get('cksum', None)
272-
self.__tarball_pattern = result['tarball']
285+
self.__tarball_pattern = result.get('tarball', None)
273286
self.__tarball_upstream_url_pattern = result.get('upstream_url', None)
274287
# Name of the directory containing the checksums.ini file
275288
self.__tarball_package_name = os.path.realpath(checksums_ini).split(os.sep)[-2]
276289

277290
VERSION_PATCHLEVEL = re.compile('(?P<version>.*)\.p(?P<patchlevel>[0-9]+)')
278291

279292
def _init_version(self):
280-
with open(os.path.join(self.path, 'package-version.txt')) as f:
281-
package_version = f.read().strip()
282-
match = self.VERSION_PATCHLEVEL.match(package_version)
283-
if match is None:
284-
self.__version = package_version
285-
self.__patchlevel = -1
293+
try:
294+
with open(os.path.join(self.path, 'package-version.txt')) as f:
295+
package_version = f.read().strip()
296+
except IOError:
297+
self.__version = None
298+
self.__patchlevel = None
286299
else:
287-
self.__version = match.group('version')
288-
self.__patchlevel = int(match.group('patchlevel'))
289-
300+
match = self.VERSION_PATCHLEVEL.match(package_version)
301+
if match is None:
302+
self.__version = package_version
303+
self.__patchlevel = -1
304+
else:
305+
self.__version = match.group('version')
306+
self.__patchlevel = int(match.group('patchlevel'))
307+
290308
def _init_type(self):
291309
with open(os.path.join(self.path, 'type')) as f:
292310
package_type = f.read().strip()
293311
assert package_type in [
294-
'base', 'standard', 'optional', 'experimental', 'script', 'pip'
312+
'base', 'standard', 'optional', 'experimental'
295313
]
296314
self.__type = package_type

build/sage_bootstrap/tarball.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def download(self, allow_upstream=False):
140140
on the sage mirrors, fall back to downloading it from
141141
the upstream URL if the package has one.
142142
"""
143+
if not self.filename:
144+
raise ValueError('non-normal package does define a tarball, so cannot download')
143145
destination = self.upstream_fqn
144146
if os.path.isfile(destination):
145147
if self.checksum_verifies():

src/bin/sage-download-upstream

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/doc/en/installation/source.rst

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,15 +1096,7 @@ you. This is influenced by the following environment variable:
10961096

10971097
- ``SAGE_SERVER/spkg/upstream``
10981098

1099-
for clean upstream tarballs, and it searches the directories
1100-
1101-
- ``SAGE_SERVER/spkg/standard/``,
1102-
- ``SAGE_SERVER/spkg/optional/``,
1103-
- ``SAGE_SERVER/spkg/experimental/``,
1104-
- ``SAGE_SERVER/spkg/archive/``
1105-
1106-
for old-style Sage packages.
1107-
1099+
for upstream tarballs.
11081100

11091101
Here are some of the more commonly used variables affecting the build process:
11101102

src/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
'bin/sage-cleaner',
143143
## Only makes sense in sage-the-distribution. TODO: Move to another installation script.
144144
'bin/sage-list-packages',
145-
'bin/sage-download-upstream',
146145
'bin/sage-location',
147146
## Uncategorized scripts in alphabetical order
148147
'bin/math-readline',

0 commit comments

Comments
 (0)