Hi Nathann, On Thu, Jun 17, 2010 at 3:45 AM, Nathann Cohen <nathann.co...@gmail.com> wrote:
<SNIP> > Just a question about this "OptionalPackageNotInstalledError" > exception mentionned about the bug you found in is_hamiltonian... It > sounds like it should be used in a lot of places if it is to become > the standard way of saying "install this package first". I like the name "OptionalPackageNotInstalledError" as suggested by David Loeffler. But I would like to suggest another name: OptionalPackageNotFoundError. See below for an implementation and documentation. > So two > questions : > > * Where do you think it should be defined ? The proposed new exception OptionalPackageNotFoundError should be defined somewhere "at the top", giving the impression that this exception can be used by modules outside of the graph theory and combinatorial optimization modules. For example, let's consider any of Magma, Maple, Matlab, and Mathematica as an optional package that one could use through an interface within the Sage library. If the interface discovers that the required optional package is not installed on the system, or that the interface can't find the package, then the interface raises an OptionalPackageNotFoundError. I think the new exception OptionalPackageNotFoundError can be defined in a new module called misc/exceptions.py Here's an implementation: diff --git a/doc/en/reference/misc.rst b/doc/en/reference/misc.rst --- a/doc/en/reference/misc.rst +++ b/doc/en/reference/misc.rst @@ -7,6 +7,7 @@ :maxdepth: 2 sage/misc/abstract_method + sage/misc/exceptions sage/misc/misc sage/misc/bitset sage/misc/constant_function diff --git a/sage/misc/exceptions.py b/sage/misc/exceptions.py new file mode 100644 --- /dev/null +++ b/sage/misc/exceptions.py @@ -0,0 +1,27 @@ +class OptionalPackageNotFoundError(RuntimeError): + """ + This class defines the exception that should be raised when a function, + method, or class cannot detect an optional package that it depends on. + When an ``OptionalPackageNotFoundError`` is raised, this means one of the + following: + + - The required optional package is not installed. + + - The required optional package is installed, but the relevant interface + to that package is unable to detect the package. + + EXAMPLES:: + + sage: from sage.misc.exceptions import OptionalPackageNotFoundError + sage: def find_package(fav_package): + ... try: + ... raise OptionalPackageNotFoundError("Unable to detect optional package: %s" % fav_package) + ... except OptionalPackageNotFoundError: + ... raise + ... + sage: find_package("ham and spam") + Traceback (most recent call last): + ... + OptionalPackageNotFoundError: Unable to detect optional package: ham and spam + """ + pass > * Can I really write a patch updating the whole Sage library for this > change ? It is the kind of patch that would quickly become > uncompatible with plenty of other patches, as it will touch plenty of > different files... You can do a gradual migration to using the new exception OptionalPackageNotFoundError. Let's first concentrate on modules in the graph theory component. At the same time, the Developer's Guide needs to be updated to explain the various types of exceptions that have been defined for Sage, and also about Python built-in exceptions. Of course, I don't expect you to do all the work. I have defined the new exception class. As you are more familiar with where GLPK and CBC (and CPLEX) are used, I trust your judgement in updating the various graph theory modules to use this new exception. Just tell me what I can do to help out. -- Regards Minh Van Nguyen -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org