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

Commit

Permalink
Add Features to check the environment at runtime
Browse files Browse the repository at this point in the history
Eventually this should replace is_package_installed()
checks which are annoying for packagers.
  • Loading branch information
saraedum authored and jdemeyer committed Feb 12, 2018
1 parent e6cae6d commit 628f35e
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/sage/databases/cremona.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

import sage.schemes.elliptic_curves.constructor as elliptic
from .sql_db import SQLDatabase, verify_column
from sage.misc.package import is_package_installed
from sage.env import SAGE_SHARE
from sage.misc.all import walltime

Expand Down Expand Up @@ -606,24 +605,25 @@ def __init__(self, name, read_only=True, build=False):
sage: c.name
'cremona mini'
"""
if name is None:
raise ValueError("name must not be None.")
if build and read_only:
raise ValueError("only one of build and read_only can be set at once.")

self.name = name
name = name.replace(' ','_')
db_path = os.path.join(SAGE_SHARE, 'cremona', name+'.db')

if build:
if name is None:
raise RuntimeError('The database must have a name.')
if read_only:
raise RuntimeError('The database must not be read_only.')
db_path = os.path.join(SAGE_SHARE, 'cremona', name.replace(' ','_')+'.db')
SQLDatabase.__init__(self, db_path, read_only=read_only, \
skeleton=_miniCremonaSkeleton)
return
if not os.path.isfile(db_path):
raise ValueError("Desired database (='%s') does not "%self.name \
+ "exist")
SQLDatabase.__init__(self, db_path, read_only=read_only)
if self.get_skeleton() != _miniCremonaSkeleton:
raise RuntimeError('Database at %s does '%(self.__dblocation__) \
+ 'not appear to be a valid SQL Cremona database.')
else:
from sage.misc.feature_test import DatabaseCremona
database = DatabaseCremona(name)
database.require()
SQLDatabase.__init__(self, database.absolute_path(), read_only=read_only)
if self.get_skeleton() != _miniCremonaSkeleton:
raise RuntimeError('Database at %s does '%(self.__dblocation__) \
+ 'not appear to be a valid SQL Cremona database.')

def __iter__(self):
"""
Expand Down Expand Up @@ -824,14 +824,15 @@ def coefficients_and_data(self, label):
if N < self.largest_conductor():
message = "There is no elliptic curve with label " + label \
+ " in the database"
elif is_package_installed('database_cremona_ellcurve'):
from sage.misc.feature_test import DatabaseCremona
cremona_database_presence = DatabaseCremona().is_present()
if cremona_database_presence:
message = "There is no elliptic curve with label " + label \
+ " in the currently available databases"
else:
message = "There is no elliptic curve with label " \
+ label + " in the default database; try installing " \
+ "the optional package database_cremona_ellcurve which " \
+ "contains the complete Cremona database"
+ label + " in the default database. " \
+ cremona_database_presence.resolution
raise ValueError(message)
ainvs = eval(c[0])
data = {'cremona_label': label,
Expand Down Expand Up @@ -1418,24 +1419,25 @@ def __init__(self, name, read_only=True, build=False):
sage: c.name # optional - database_cremona_ellcurve
'cremona'
"""
if name is None:
raise ValueError("name must not be None.")
if build and read_only:
raise ValueError("only one of build and read_only can be set at once.")

self.name = name
name = name.replace(' ','_')
db_path = os.path.join(SAGE_SHARE, 'cremona', name+'.db')

if build:
if name is None:
raise RuntimeError('The database must have a name.')
if read_only:
raise RuntimeError('The database must not be read_only.')
db_path = os.path.join(SAGE_SHARE, 'cremona', name.replace(' ','_')+'.db')
SQLDatabase.__init__(self, db_path, read_only=read_only, \
skeleton=_cremonaSkeleton)
return
if not os.path.isfile(db_path):
raise ValueError("Desired database (='%s') does not "%self.name \
+ "exist")
SQLDatabase.__init__(self, db_path, read_only=read_only)
if self.get_skeleton() != _cremonaSkeleton:
raise RuntimeError('Database at %s does '%(self.__dblocation__) \
+ 'not appear to be a valid SQL Cremona database.')
skeleton=_miniCremonaSkeleton)
else:
from sage.misc.feature_test import DatabaseCremona
database = DatabaseCremona(name)
database.require()
SQLDatabase.__init__(self, database.absolute_path(), read_only=read_only)
if self.get_skeleton() != _cremonaSkeleton:
raise RuntimeError('Database at %s does '%(self.__dblocation__) \
+ 'not appear to be a valid SQL Cremona database.')

def allbsd(self, N):
r"""
Expand Down Expand Up @@ -1673,7 +1675,8 @@ def CremonaDatabase(name=None,mini=None,set_global=None):
if name is None and not set_global:
return _db
if set_global and name is None:
if is_package_installed('database_cremona_ellcurve'):
from sage.misc.feature_test import DatabaseCremona
if DatabaseCremona().is_present():
name = 'cremona'
else:
name = 'cremona mini'
Expand Down

0 comments on commit 628f35e

Please sign in to comment.