Skip to content

Commit

Permalink
Trac #31013: Remove unused class from sage_setup.optional extension
Browse files Browse the repository at this point in the history
The code in `optional_extension` was mostly unused and is removed in
this ticket (and similarly `extension.skip_build` was nowhere else set).
The only still used method was `is_package_installed_and_updated` which
is moved to `sage.misc.package`.

Related: #28815

URL: https://trac.sagemath.org/31013
Reported by: gh-tobiasdiez
Ticket author(s): Tobias Diez
Reviewer(s): François Bissey
  • Loading branch information
Release Manager committed Jan 30, 2022
2 parents 464f81e + a7b1e81 commit 3abe1a7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 101 deletions.
3 changes: 1 addition & 2 deletions build/pkgs/sagelib/spkg-install
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ fi
## Building takes places in the build/ subdirectory.
##
## As a special exception, we feed SAGE_PKGS and SAGE_SPKG_INST.
## They are needed by src/sage_setup/optional_extension.py
## via src/sage/misc/package.py. See meta-ticket #28815 for planned changes to this.
## They are needed by src/sage/misc/package.py. See meta-ticket #28815 for planned changes to this.

export SAGE_PKGS="$SAGE_ROOT"/build/pkgs
export SAGE_ROOT=/doesnotexist
Expand Down
2 changes: 1 addition & 1 deletion pkgs/sagemath-standard/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
# TODO: This should be quiet by default
print("Discovering Python/Cython source code....")
t = time.time()
from sage_setup.optional_extension import is_package_installed_and_updated
from sage.misc.package import is_package_installed_and_updated
distributions = ['']
optional_packages_with_extensions = ['mcqd', 'bliss', 'tdlib',
'coxeter3', 'fes', 'sirocco', 'meataxe']
Expand Down
26 changes: 26 additions & 0 deletions src/sage/misc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

DEFAULT_PYPI = 'https://pypi.org/pypi'


def pkgname_split(name):
r"""
Split a pkgname into a list of strings, 'name, version'.
Expand All @@ -69,6 +70,7 @@ def pkgname_split(name):
"""
return (name.split('-',1) + [''])[:2]


def pip_remote_version(pkg, pypi_url=DEFAULT_PYPI, ignore_URLError=False):
r"""
Return the version of this pip package available on PyPI.
Expand Down Expand Up @@ -123,6 +125,7 @@ def pip_remote_version(pkg, pypi_url=DEFAULT_PYPI, ignore_URLError=False):
stable_releases = [v for v in info['releases'] if 'a' not in v and 'b' not in v]
return max(stable_releases)


def pip_installed_packages(normalization=None):
r"""
Return a dictionary `name->version` of installed pip packages.
Expand Down Expand Up @@ -446,6 +449,29 @@ def is_package_installed(package, exclude_pip=True):
return any(p == package for p in installed_packages(exclude_pip))


def is_package_installed_and_updated(package: str) -> bool:
r"""
Return whether the given package is installed and up-to-date.
INPUT:
- ``package`` -- the name of the package.
EXAMPLES::
sage: from sage.misc.package import is_package_installed_and_updated
sage: is_package_installed_and_updated("alabaster") # optional - build, random
False
"""
try:
all_packages = list_packages(local=True)
pkginfo = all_packages[package]
return pkginfo.installed_version == pkginfo.remote_version
except KeyError:
# Might be an installed old-style package
return is_package_installed(package)


def package_versions(package_type, local=False):
r"""
Return version information for each Sage package.
Expand Down
3 changes: 0 additions & 3 deletions src/sage_setup/command/sage_build_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ def run(self):
cache=False,
)

# Filter out extensions with skip_build=True
extensions = [ext for ext in extensions if not getattr(ext, "skip_build", False)]

# We use [:] to change the list in-place because the same list
# object is pointed to from different places.
self.extensions[:] = extensions
Expand Down
94 changes: 0 additions & 94 deletions src/sage_setup/optional_extension.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import sage.misc.lazy_import_cache

from sage_setup.optional_extension import is_package_installed_and_updated
from sage.misc.package import is_package_installed_and_updated
from sage_setup.command.sage_build_ext_minimal import sage_build_ext_minimal
from sage_setup.command.sage_install import sage_install
from sage_setup.find import filter_cython_sources
Expand Down

0 comments on commit 3abe1a7

Please sign in to comment.