Skip to content

Commit 367711d

Browse files
author
Release Manager
committed
Trac #34490: sage --package clean command to remove outdated source tarballs
The `$SAGE_ROOT/upstream/` accumulates tarballs over the time. The proposed `sage --package clean` command cleans that directory and keeps only tarballs that are currently needed (i.e. only the versions indicated in `$SAGE_ROOT/build/pkgs/*/package-version.txt` are kept). URL: https://trac.sagemath.org/34490 Reported by: tmonteil Ticket author(s): Thierry Monteil Reviewer(s): David Coudert
2 parents b4311cd + 3809a6f commit 367711d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

build/sage_bootstrap/app.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# -*- coding: utf-8 -*-
22
"""
33
Controller for the commandline actions
4+
5+
AUTHORS:
6+
7+
- Volker Braun (2016): initial version
8+
- Thierry Monteil (2022): clean option to remove outdated source tarballs
49
"""
510

611

@@ -26,6 +31,7 @@
2631
from sage_bootstrap.pypi import PyPiVersion, PyPiNotFound, PyPiError
2732
from sage_bootstrap.fileserver import FileServer
2833
from sage_bootstrap.expand_class import PackageClass
34+
from sage_bootstrap.env import SAGE_DISTFILES
2935

3036

3137
class Application(object):
@@ -303,3 +309,23 @@ def create(self, package_name, version=None, tarball=None, pkg_type=None, upstre
303309
else:
304310
update = ChecksumUpdater(package_name)
305311
update.fix_checksum()
312+
313+
def clean(self):
314+
"""
315+
Remove outdated source tarballs from the upstream/ directory
316+
317+
$ sage --package clean
318+
42 files were removed from the .../upstream directory
319+
"""
320+
log.debug('Cleaning upstream/ directory')
321+
package_names = PackageClass(':all:').names
322+
keep = [Package(package_name).tarball.filename for package_name in package_names]
323+
count = 0
324+
for filename in os.listdir(SAGE_DISTFILES):
325+
if filename not in keep:
326+
filepath = os.path.join(SAGE_DISTFILES, filename)
327+
if os.path.isfile(filepath):
328+
log.debug('Removing file {}'.format(filepath))
329+
os.remove(filepath)
330+
count += 1
331+
print('{} files were removed from the {} directory'.format(count, SAGE_DISTFILES))

build/sage_bootstrap/cmdline.py

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
55
This module handles the main "sage-package" commandline utility, which
66
is also exposed as "sage --package".
7+
8+
AUTHORS:
9+
10+
- Volker Braun (2016): initial version
11+
- Thierry Monteil (2022): clean option to remove outdated source tarballs
712
"""
813

914
# ****************************************************************************
@@ -174,6 +179,16 @@
174179
Creating new package "foo"
175180
"""
176181

182+
epilog_clean = \
183+
"""
184+
Remove outdated source tarballs from the upstream/ directory
185+
186+
EXAMPLE:
187+
188+
$ sage --package clean
189+
42 files were removed from the .../upstream directory
190+
"""
191+
177192

178193
def make_parser():
179194
"""
@@ -316,6 +331,11 @@ def make_parser():
316331
'--pypi', action="store_true",
317332
help='Create a package for a Python package available on PyPI')
318333

334+
parser_clean = subparsers.add_parser(
335+
'clean', epilog=epilog_clean,
336+
formatter_class=argparse.RawDescriptionHelpFormatter,
337+
help='Remove outdated source tarballs from the upstream/ directory')
338+
319339
return parser
320340

321341

@@ -356,6 +376,8 @@ def run():
356376
app.upload_cls(args.package_name)
357377
elif args.subcommand == 'fix-checksum':
358378
app.fix_checksum_cls(*args.package_class)
379+
elif args.subcommand == 'clean':
380+
app.clean()
359381
else:
360382
raise RuntimeError('unknown subcommand: {0}'.format(args))
361383

0 commit comments

Comments
 (0)