Esempio n. 1
0
    def uninstall(self, pkgname, *args, **kwargs):
        """A context manager which allows uninstallation of packages from the environment

        :param str pkgname: The name of a package to uninstall

        >>> env = Environment("/path/to/env/root")
        >>> with env.uninstall("pytz", auto_confirm=True, verbose=False) as uninstaller:
                cleaned = uninstaller.paths
        >>> if cleaned:
                print("uninstalled packages: %s" % cleaned)
        """

        auto_confirm = kwargs.pop("auto_confirm", True)
        verbose = kwargs.pop("verbose", False)
        with self.activated():
            monkey_patch = next(
                iter(dist for dist in self.base_working_set
                     if dist.project_name == "recursive-monkey-patch"), None)
            if monkey_patch:
                monkey_patch.activate()
            pip_shims = self.safe_import("pip_shims")
            pathset_base = pip_shims.UninstallPathSet
            import recursive_monkey_patch
            recursive_monkey_patch.monkey_patch(PatchedUninstaller,
                                                pathset_base)
            dist = next(
                iter(
                    filter(lambda d: d.project_name == pkgname,
                           self.get_working_set())), None)
            pathset = pathset_base.from_dist(dist)
            if pathset is not None:
                pathset.remove(auto_confirm=auto_confirm, verbose=verbose)
            try:
                yield pathset
            except Exception as e:
                if pathset is not None:
                    pathset.rollback()
            else:
                if pathset is not None:
                    pathset.commit()
            if pathset is None:
                return
Esempio n. 2
0
        def _an_element_(self):
            pass

        @semantic(gap="Random", codomain="self")
        @abstract_method
        def random_element(self):
            pass

    @semantic(mmt="TODO")
    class Finite:
        class ParentMethods:
            @semantic(gap="List", codomain="list_of_self")
            @abstract_method
            def list(self):
                pass
monkey_patch(Sets, sage.categories.sets_cat.Sets)

@semantic(mmt="TODO")
class EnumeratedSets:
    class ParentMethods:
        @semantic(gap="Iterator", codomain="iter_of_self")
        @abstract_method
        def __iter__(self):
            pass
monkey_patch(EnumeratedSets, sage.categories.enumerated_sets.EnumeratedSets)

# class Lists:
#     def super_categories(self):
#         return EnumeratedSets().Finite()
#     class ParentMethods:
#         @semantic(gap="")
Esempio n. 3
0
      '_an_element_': ...},
      'cardinality': {'__imfunc__': <abstract method cardinality at ...>,
       'codomain': *.sage(),
       'gap_name': 'Size',...},
      'is_d_trivial': ...,
      'is_finite': ...,
      'is_l_trivial': ...,
      'is_r_trivial': ...,
      'one': ...,
      'random_element': ...,
      'semigroup_generators': ...}}
"""

##############################################################################
# Monkey patch the Sage library upon importing this module
##############################################################################

import logging
from recursive_monkey_patch import monkey_patch

log_level = logging.ERROR
#log_level=logging.INFO

import sage_annotations.misc
import sage.misc
monkey_patch(sage_annotations.misc, sage.misc, log_level=log_level)

import sage_annotations.categories
import sage.categories
monkey_patch(sage_annotations.categories, sage.categories, log_level=log_level)
Esempio n. 4
0
"""
Typical idiom to automatize the monkey patching

Importing this module triggers the monkey patching of its features into a_test_module.
"""

import sys
from recursive_monkey_patch import monkey_patch
import a_test_module
monkey_patch(sys.modules[__name__], a_test_module)
from sage.categories.sets_cat import Sets
from sage.categories.magmas import Magmas
from sage.categories.additive_semigroups import AdditiveSemigroups
from sage.categories.additive_groups import AdditiveGroups
from sage.categories.enumerated_sets import EnumeratedSets
from sage.categories.rings import Rings
from sage.structure.element import Element
from sage.structure.parent import Parent
from sage.libs.gap.libgap import libgap
from sage.libs.gap.element import GapElement

import categories
import sage.categories
import categories.objects
import sage.categories.objects
monkey_patch(categories.objects, sage.categories.objects)

if False: # Whether to use the explicit GAP categories (in categories/*), or anotations (in mmt.py)
    monkey_patch(categories, sage.categories)
    from sage.categories.lie_algebras import LieAlgebras
else:
    import mmt
    from mmt import LieAlgebras

# libgap does not know about several functions
# This is a temporary workaround to let some of the tests run
import sage.libs.gap.gap_functions
sage.libs.gap.gap_functions.common_gap_functions.extend(
    (["FreeMonoid", "IsRTrivial", "JClasses", "IsField", "FiniteField",
      "LieAlgebra", "FullMatrixAlgebra", "ZmodnZ", "ApplicableMethod",
      "GeneratorsOfMonoid", "GeneratorsOfSemigroup",
Esempio n. 6
0
    Henselization of Integer Ring with respect to 2-adic valuation

"""
#*****************************************************************************
#       Copyright (C) 2018-2022 Julian Rüth <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#                  http://www.gnu.org/licenses/
#*****************************************************************************

from __future__ import absolute_import
from . import sage as monkey_sage
import sage.all

from .monkey import *

from recursive_monkey_patch import monkey_patch
monkey_patch(monkey_sage, sage)

# Make "import sage.rings.padics.henselization" work with SageMath 9.4.
# We are not sure why recursive_monkey_patch does not take care of this (anymore.)
import sys
sys.modules[
    'sage.rings.padics.henselization'] = sage.rings.padics.henselization

from sage.rings.padics.henselization import Henselization
sage.all.Henselization = Henselization
Esempio n. 7
0
    sage: Semigroups().Finite().parent_class.is_r_trivial.__module__
    'sage_semigroups.categories.finite_semigroups'
"""
import sys
import logging
from recursive_monkey_patch import monkey_patch

import sage
# TODO: do we want this? Should this list the features that are being patched?
log_level = logging.WARNING
# log_level = logging.INFO
if log_level <= logging.INFO:
    print("Loading sage-semigroups and patching its features into Sage's library:")
sage_semigroups = sys.modules[__name__]
from . import misc, categories, monoids, graphs
monkey_patch(sage_semigroups.misc, sage.misc, log_level=log_level)
monkey_patch(sage_semigroups.categories, sage.categories, log_level=log_level)
monkey_patch(sage_semigroups.graphs, sage.graphs, log_level=log_level)
monkey_patch(sage_semigroups.monoids, sage.monoids, log_level=log_level)

# Insert the content of sage_semigroups.all in the global name space
from . import all
from sage.repl.user_globals import initialize_globals
initialize_globals(sage_semigroups.all)

# Some traces of an attempt
# from sage.repl.ipython_extension import SageCustomizations
# all = SageCustomizations.all_globals()
# all.foo = 3

"""
Esempio n. 8
0
from sage.categories.rings import Rings
from sage.structure.element import Element
from sage.structure.parent import Parent
from sage.libs.gap.libgap import libgap
from sage.libs.gap.element import GapElement
from sage.categories.category_with_axiom import CategoryWithAxiom

##############################################################################
# Initialization
##############################################################################

import categories
import sage.categories
import categories.objects
import sage.categories.objects
monkey_patch(categories.objects, sage.categories.objects)

# Workaround until #27911 is merged
# libgap does not know about several functions
# This is a temporary workaround to let some of the tests run
import sage.libs.gap.gap_functions
sage.libs.gap.gap_functions.common_gap_functions.union(([
    "FreeMonoid", "IsRTrivial", "GreensJClasses", "GreensRClasses",
    "GreensLClasses", "GreensDClasses", "IsField", "FiniteField", "LieAlgebra",
    "FullMatrixAlgebra", "ZmodnZ", "ApplicableMethod", "GeneratorsOfMonoid",
    "GeneratorsOfSemigroup", "GeneratorsOfAlgebra", "AdditiveInverse",
    "IsomorphismTransformationMonoid", "LieCentralizer", "LieNormalizer",
    "IsLieNilpotent", "IsRestrictedLieAlgebra", r"\+", r"\-", r"\*", r"\/"
]))

##############################################################################