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

Commit

Permalink
a few details in src/bin
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Feb 5, 2022
1 parent 439907f commit 3aed7d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
17 changes: 10 additions & 7 deletions src/bin/sage-coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
from __future__ import print_function

import os
import sys
from tokenize import (NEWLINE, COMMENT, INDENT, DEDENT, STRING, NL,
Expand All @@ -15,6 +13,7 @@ parser.add_argument('--summary', action='store_true', help='only print a short s

args = parser.parse_args()


def coverage_all(directory):
os.chdir(directory)
r = os.popen('sage-coverage * | grep SCORE').readlines()
Expand Down Expand Up @@ -131,7 +130,7 @@ class CoverageResults:
if not docstring:
self.no_doc.append(fullname)
return
if not "sage: " in docstring:
if "sage: " not in docstring:
self.no_test.append(fullname)
return

Expand Down Expand Up @@ -257,6 +256,8 @@ possibly_wrong = 0
bad_files = []

first = True


def go(filename):
r"""
If ``filename`` is a file, launch the inspector on this file. If
Expand Down Expand Up @@ -286,18 +287,20 @@ def go(filename):
no_test += len(cr.no_test)
possibly_wrong += len(cr.possibly_wrong)
good += len(cr.good)
if bad: bad_files.append(filename)
if bad:
bad_files.append(filename)
return
if not bad and args.only_bad:
return

global first
if first:
print('-'*72)
print('-' * 72)
first = False

cr.report() # Print the report
print('-'*72)
cr.report() # Print the report
print('-' * 72)


for arg in args.filename:
go(arg)
Expand Down
9 changes: 3 additions & 6 deletions src/bin/sage-list-packages
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ This is script can be called with one argument which might be either
"all", "standard", "optional", or "experimental". It is mostly a
script interface to sage_setup.packages.list_packages.
"""

from __future__ import absolute_import, print_function

import os
import argparse

Expand Down Expand Up @@ -48,7 +45,7 @@ args = vars(parser.parse_args())
################

if args['category'] == 'installed':
WARN = "*" * 60 + "\n"
WARN = "*" * 60 + "\n"
WARN += 'The "installed" category is deprecated. Use\n'
WARN += '"list-packages all --installed-only" instead\n'
WARN += "*" * 60
Expand Down Expand Up @@ -99,8 +96,8 @@ L.sort(key=lambda pkg: pkg.name)

# print (while getting rid of None in versions)
for pkg in L:
pkg = pkg._replace(installed_version = pkg.installed_version or 'not_installed',
remote_version = pkg.remote_version or '?')
pkg = pkg._replace(installed_version=pkg.installed_version or 'not_installed',
remote_version=pkg.remote_version or '?')
print(format_string.format(**pkg._asdict()))
if WARN:
print(WARN)
9 changes: 3 additions & 6 deletions src/bin/sage-location
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

# This script is executed by $SAGE_LOCAL/bin/sage
# before starting sage.

from __future__ import print_function

import os
import sys

SAGE_ROOT = os.environ.get('SAGE_ROOT', None)
SAGE_ROOT = os.environ.get('SAGE_ROOT', None)
if SAGE_ROOT:
SAGE_ROOT = os.path.realpath(SAGE_ROOT)
SAGE_LOCAL = os.environ['SAGE_LOCAL']
SAGE_ROOT = os.path.realpath(SAGE_ROOT)
SAGE_LOCAL = os.environ['SAGE_LOCAL']

location_file = os.path.join(SAGE_LOCAL, 'lib', 'sage-current-location.txt')

Expand Down
2 changes: 0 additions & 2 deletions src/bin/sage-num-threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#
# AUTHOR: Jeroen Demeyer (2011-12-08): Trac ticket #12016
#
from __future__ import print_function

import os
import multiprocessing

Expand Down
16 changes: 5 additions & 11 deletions src/bin/sage-startuptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#
# https://www.gnu.org/licenses/
########################################################################

from __future__ import print_function

import sys
import os
import time
Expand All @@ -38,10 +35,7 @@
index_to_parent = dict()
all_modules = dict()

if sys.version_info[0] == 2:
DEFAULT_LEVEL = -1
else:
DEFAULT_LEVEL = 0
DEFAULT_LEVEL = 0


def new_import(name, globals={}, locals={}, fromlist=[], level=DEFAULT_LEVEL):
Expand Down Expand Up @@ -116,26 +110,26 @@ def print_table(module_list, limit):
print(fmt_number.format(1000 * t, 1000 * data['cumulative_time'],
len(data['parents']), module.__name__))


def guess_module_name(src):
module = []
src, ext = os.path.splitext(src)
while src and src != '/':
head, tail = os.path.split(os.path.abspath(src))
if (tail == 'src'
or any(os.path.exists(os.path.join(head, tail, f))
for f in ('setup.py', 'pyproject.toml'))):
if (tail == 'src' or any(os.path.exists(os.path.join(head, tail, f))
for f in ('setup.py', 'pyproject.toml'))):
return '.'.join(module)
module.insert(0, tail)
src = head
return None


if not have_cmdline_args:
print('== Slowest module imports (excluding / including children) ==')
print_table(module_by_speed, 50)
print('Total time (sum over exclusive time): {:.3f}ms'.format(1000 * sum(data[0] for data in module_by_speed)))
print('Use sage -startuptime <module_name|file_name>... to get more details about specific modules.')
else:
from sage.env import SAGE_SRC
for module_arg in cmdline_args:
matching_modules = [m for m in all_modules if m.__name__ == module_arg]
if not matching_modules:
Expand Down

0 comments on commit 3aed7d9

Please sign in to comment.