Skip to content

Commit 6753fbd

Browse files
author
Release Manager
committed
sagemathgh-37855: `sage.misc.package`: Remove deprecated code <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Remove code deprecated in: - sagemath#31013 (2022) - sagemath#30747 (2020) - sagemath#30607 (2020) ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#37855 Reported by: Matthias Köppe Reviewer(s): François Bissey, Matthias Köppe
2 parents 9ce51d0 + 9221a32 commit 6753fbd

File tree

5 files changed

+10
-210
lines changed

5 files changed

+10
-210
lines changed

src/sage/game_theory/normal_form_game.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@
647647
from sage.matrix.constructor import vector
648648
from sage.misc.temporary_file import tmp_filename
649649
from sage.numerical.mip import MixedIntegerLinearProgram
650-
from sage.misc.package import PackageNotFoundError
651650
from sage.cpython.string import bytes_to_str
652651

653652
try:
@@ -1704,7 +1703,7 @@ def obtain_nash(self, algorithm=False, maximization=True, solver=None):
17041703

17051704
if algorithm == "LCP":
17061705
if Game is None:
1707-
raise PackageNotFoundError("gambit")
1706+
raise RuntimeError("gambit not found") # should later become a FeatureNotFoundError
17081707
return self._solve_LCP(maximization)
17091708

17101709
if algorithm.startswith('lp'):

src/sage/interfaces/kash.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,7 @@ def _quit_string(self):
527527
return 'quit;'
528528

529529
def _start(self):
530-
try:
531-
Expect._start(self)
532-
except RuntimeError:
533-
# TODO: replace this error with something more accurate.
534-
from sage.misc.package import PackageNotFoundError
535-
raise PackageNotFoundError("kash")
530+
Expect._start(self)
536531
# Turn off the annoying timer.
537532
self.eval('Time(false);')
538533

src/sage/misc/all.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@
134134
lazy_import('sage.misc.dist', 'install_scripts', deprecation=34259)
135135
lazy_import('sage.misc.trace', 'trace', deprecation=34259)
136136
lazy_import('sage.misc.package', ('installed_packages', 'is_package_installed',
137-
'standard_packages', 'optional_packages',
138-
'experimental_packages', 'package_versions'),
137+
'package_versions'),
139138
deprecation=34259)
140139
lazy_import('sage.misc.benchmark', 'benchmark', deprecation=34259)
141140
lazy_import('sage.repl.interpreter', 'logstr', deprecation=34259)

src/sage/misc/package.py

+6-195
Original file line numberDiff line numberDiff line change
@@ -228,34 +228,6 @@ def is_installed(self) -> bool:
228228
"""
229229
return self.installed_version is not None
230230

231-
def __getitem__(self, key: Union[int, str]):
232-
r"""
233-
Only for backwards compatibility to allow dict-like access.
234-
235-
TESTS::
236-
237-
sage: from sage.misc.package import PackageInfo
238-
sage: package = PackageInfo("test_package")
239-
sage: package["name"]
240-
doctest:warning...
241-
dict-like access is deprecated, use pkg.name instead of pkg['name'], for example
242-
See https://github.com/sagemath/sage/issues/31013 for details.
243-
'test_package'
244-
sage: package[0]
245-
'test_package'
246-
"""
247-
if isinstance(key, str):
248-
from sage.misc.superseded import deprecation
249-
250-
if key == "installed":
251-
deprecation(31013, "dict-like access via 'installed' is deprecated, use method is_installed instead")
252-
return self.is_installed()
253-
else:
254-
deprecation(31013, "dict-like access is deprecated, use pkg.name instead of pkg['name'], for example")
255-
return self.__getattribute__(key)
256-
else:
257-
return tuple.__getitem__(self, key)
258-
259231

260232
def list_packages(*pkg_types: str, pkg_sources: List[str] = ['normal', 'pip', 'script'],
261233
local: bool = False, ignore_URLError: bool = False, exclude_pip: bool = False) -> Dict[str, PackageInfo]:
@@ -547,109 +519,6 @@ def package_versions(package_type, local=False):
547519
return {pkg.name: (pkg.installed_version, pkg.remote_version) for pkg in list_packages(package_type, local=local).values()}
548520

549521

550-
def standard_packages():
551-
"""
552-
Return two lists. The first contains the installed and the second
553-
contains the not-installed standard packages that are available
554-
from the Sage repository.
555-
556-
OUTPUT:
557-
558-
- installed standard packages (as a list)
559-
560-
- NOT installed standard packages (as a list)
561-
562-
Run ``sage -i package_name`` from a shell to install a given
563-
package or ``sage -f package_name`` to re-install it.
564-
565-
.. SEEALSO:: :func:`sage.misc.package.list_packages`
566-
567-
EXAMPLES::
568-
569-
sage: from sage.misc.package import standard_packages
570-
sage: installed, not_installed = standard_packages() # optional - sage_spkg
571-
doctest:...: DeprecationWarning: ...
572-
sage: 'numpy' in installed # optional - sage_spkg
573-
True
574-
"""
575-
from sage.misc.superseded import deprecation
576-
deprecation(30747,
577-
'the functions standard_packages, optional_packages, experimental_packages '
578-
'are deprecated, use sage.features instead')
579-
pkgs = list_packages('standard', local=True).values()
580-
return (sorted(pkg.name for pkg in pkgs if pkg.is_installed()),
581-
sorted(pkg.name for pkg in pkgs if not pkg.is_installed()))
582-
583-
584-
def optional_packages():
585-
"""
586-
Return two lists. The first contains the installed and the second
587-
contains the not-installed optional packages that are available
588-
from the Sage repository.
589-
590-
OUTPUT:
591-
592-
- installed optional packages (as a list)
593-
594-
- NOT installed optional packages (as a list)
595-
596-
Run ``sage -i package_name`` from a shell to install a given
597-
package or ``sage -f package_name`` to re-install it.
598-
599-
.. SEEALSO:: :func:`sage.misc.package.list_packages`
600-
601-
EXAMPLES::
602-
603-
sage: # optional - sage_spkg
604-
sage: from sage.misc.package import optional_packages
605-
sage: installed, not_installed = optional_packages()
606-
doctest:...: DeprecationWarning: ...
607-
sage: 'biopython' in installed + not_installed
608-
True
609-
sage: 'biopython' in installed # optional - biopython
610-
True
611-
"""
612-
from sage.misc.superseded import deprecation
613-
deprecation(30747,
614-
'the functions standard_packages, optional_packages, experimental_packages '
615-
'are deprecated, use sage.features instead')
616-
pkgs = list_packages('optional', local=True)
617-
pkgs = pkgs.values()
618-
return (sorted(pkg.name for pkg in pkgs if pkg.is_installed()),
619-
sorted(pkg.name for pkg in pkgs if not pkg.is_installed()))
620-
621-
622-
def experimental_packages():
623-
"""
624-
Return two lists. The first contains the installed and the second
625-
contains the not-installed experimental packages that are available
626-
from the Sage repository.
627-
628-
OUTPUT:
629-
630-
- installed experimental packages (as a list)
631-
632-
- NOT installed experimental packages (as a list)
633-
634-
Run ``sage -i package_name`` from a shell to install a given
635-
package or ``sage -f package_name`` to re-install it.
636-
637-
.. SEEALSO:: :func:`sage.misc.package.list_packages`
638-
639-
EXAMPLES::
640-
641-
sage: from sage.misc.package import experimental_packages
642-
sage: installed, not_installed = experimental_packages() # optional - sage_spkg
643-
doctest:...: DeprecationWarning: ...
644-
"""
645-
from sage.misc.superseded import deprecation
646-
deprecation(30747,
647-
'the functions standard_packages, optional_packages, experimental_packages '
648-
'are deprecated, use sage.features instead')
649-
pkgs = list_packages('experimental', local=True).values()
650-
return (sorted(pkg.name for pkg in pkgs if pkg.is_installed()),
651-
sorted(pkg.name for pkg in pkgs if not pkg.is_installed()))
652-
653522
def package_manifest(package):
654523
"""
655524
Return the manifest for ``package``.
@@ -691,68 +560,10 @@ def package_manifest(package):
691560
pass
692561
raise RuntimeError('package manifest directory changed at runtime')
693562

694-
class PackageNotFoundError(RuntimeError):
695-
"""
696-
This class defines the exception that should be raised when a
697-
function, method, or class cannot detect a Sage package that it
698-
depends on.
699-
700-
This exception should be raised with a single argument, namely
701-
the name of the package.
702563

703-
When a ``PackageNotFoundError`` is raised, this means one of the
704-
following:
705-
706-
- The required optional package is not installed.
707-
708-
- The required optional package is installed, but the relevant
709-
interface to that package is unable to detect the package.
710-
711-
Raising a ``PackageNotFoundError`` is deprecated. Use
712-
:class:`sage.features.FeatureNotPresentError` instead.
713-
714-
User code can continue to catch ``PackageNotFoundError`` exceptions
715-
for compatibility with older versions of the Sage library.
716-
This does not cause deprecation warnings.
717-
718-
EXAMPLES::
719-
720-
sage: from sage.misc.package import PackageNotFoundError
721-
sage: try:
722-
....: pass
723-
....: except PackageNotFoundError:
724-
....: pass
725-
726-
"""
727-
728-
def __init__(self, *args):
729-
"""
730-
TESTS::
731-
732-
sage: from sage.misc.package import PackageNotFoundError
733-
sage: raise PackageNotFoundError("my_package")
734-
Traceback (most recent call last):
735-
...
736-
PackageNotFoundError: the package 'my_package' was not found. You can install it by running 'sage -i my_package' in a shell
737-
"""
738-
super().__init__(*args)
739-
# We do not deprecate the whole class because we want
740-
# to allow user code to handle this exception without causing
741-
# a deprecation warning.
742-
from sage.misc.superseded import deprecation
743-
deprecation(30607, "Instead of raising PackageNotFoundError, raise sage.features.FeatureNotPresentError")
744-
745-
def __str__(self):
746-
"""
747-
Return the actual error message.
748-
749-
EXAMPLES::
750-
751-
sage: from sage.misc.package import PackageNotFoundError
752-
sage: str(PackageNotFoundError("my_package"))
753-
doctest:warning...
754-
"the package 'my_package' was not found. You can install it by running 'sage -i my_package' in a shell"
755-
"""
756-
return ("the package {0!r} was not found. "
757-
"You can install it by running 'sage -i {0}' in a shell"
758-
.format(self.args[0]))
564+
# PackageNotFoundError used to be an exception class.
565+
# It was deprecated in #30607 and removed afterwards.
566+
# User code can continue to use PackageNotFoundError in
567+
# try...except statements using this definition, which
568+
# catches no exception.
569+
PackageNotFoundError = ()

src/sage/rings/polynomial/multi_polynomial_ideal.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1383,11 +1383,7 @@ def _groebner_basis_ginv(self, algorithm="TQ", criteria='CritPartially', divisio
13831383
T = P.term_order()
13841384
K = P.base_ring()
13851385

1386-
try:
1387-
import ginv
1388-
except ImportError:
1389-
from sage.misc.package import PackageNotFoundError
1390-
raise PackageNotFoundError("ginv")
1386+
import ginv
13911387

13921388
st = ginv.SystemType("Polynomial")
13931389

0 commit comments

Comments
 (0)