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

Commit 1721a44

Browse files
committed
Merge branch 'u/soehms/knotinfo' of trac.sagemath.org:sage into knotinfo_30352
2 parents 8453ffb + 5844cae commit 1721a44

17 files changed

+4366
-18
lines changed

build/pkgs/database_knotinfo/SPKG.rst

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
database_knotinfo: Tables of Knots and Links from the KnotInfo Databases
2+
========================================================================
3+
4+
Description
5+
-----------
6+
7+
Database for named knots and links provided at
8+
9+
https://knotinfo.math.indiana.edu/
10+
11+
and
12+
13+
https://linkinfo.sitehost.iu.edu'
14+
15+
Dependencies
16+
------------
17+
18+
- Sage library
19+
20+
21+
Upstream Contact
22+
----------------
23+
24+
- Charles Livingston <[email protected]>
25+
- Allison H. Moore <[email protected]>
26+
27+
Update Instructions
28+
-------------------
29+
30+
- See the Python script ``create_knotinfo_tarball.py`` in the current directory.
31+
32+
Changelog
33+
---------
34+
35+
- 20200713 (Sebastian Oehms, 13 Juli 2020, :trac:`30352`, initial version)
36+
37+
The tarball has been created from the both download files at the
38+
given date:
39+
40+
``knotinfo_data_complete.xls``
41+
``linkinfo_data_complete.xlsx``
42+
43+
exporting them to CSV via LibreOffice.
44+
45+
The second file has been changed manually deleting one character:
46+
a trailing "}" occuring in the homfly_polynomial column of the last
47+
link ``L11n459{1,1,1}``.
48+
49+
- 20210201 (Sebastian Oehms, 1 February 2021, :trac:`30352`, upgrade)
50+
51+
Three new columns have been added to ``knotinfo_data_complete.xls``
52+
(``montesinos_notation``, ``boundary_slopes`` and ``pretzel_notation``).
53+
``linkinfo_data_complete.xlsx`` remains unchanged.
54+
55+
The tarball has been created using ``create_knotinfo_tarball.py``.
56+
The fix concerning the misplaced character for ``L11n459{1,1,1}``
57+
is performed in :meth:`KnotInfoBase.homfly_polynomial`, now.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tarball=knotinfo-20210201.tar.bz2
2+
sha1=a8a69dacd1f61f19a921d8e5b90d6cfdea85d859
3+
md5=5f53bd7e3a672648d41460c4d22d52b3
4+
cksum=1608275975
5+
upstream_url=https://github.com/soehms/sagemath_knotinfo/blob/main/knotinfo-20210201.tar.bz2?raw=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/python
2+
3+
r"""
4+
Python script to create a tarball for the sage-package ``database_knotinfo``
5+
in the given path. This utility should be used in case of a switch to a
6+
new version of the data files (that is if the original files on the
7+
KnotInfo LinkInfo web-page have changed). In that case an invocation of
8+
``sage -package update database_knotinfo <new version>`` and
9+
``sage -package fix-checksum database_knotinfo`` will be necessary.
10+
11+
..NOTE::
12+
13+
This function demands the Python package ``pandas``, ``xlrd`` and
14+
``xlsx2csv`` to be installed. If not you have to run::
15+
16+
pip install pandas
17+
pip install xlrd
18+
pip install xlsx2csv
19+
20+
before using this function.
21+
22+
INPUT:
23+
24+
- ``version`` -- string, name of the new version to be created
25+
(by default date of the day of creation)
26+
- ``path`` -- string of the path where the tarball should be stored
27+
(by default ``pwd``)
28+
29+
EXAMPLES::
30+
31+
~/sage $ build/pkgs/database_knotinfo/create_knotinfo_tarball.py 20210201 upstream
32+
src/
33+
src/knotinfo_data_complete.csv
34+
src/linkinfo_data_complete.csv
35+
"""
36+
37+
import sys, os
38+
from xlsx2csv import Xlsx2csv
39+
from pandas import read_excel
40+
41+
##############################################################################
42+
# Copyright (C) 2021 Sebastian Oehms <[email protected]>
43+
#
44+
# This program is free software: you can redistribute it and/or modify
45+
# it under the terms of the GNU General Public License as published by
46+
# the Free Software Foundation, either version 2 of the License, or
47+
# (at your option) any later version.
48+
# http://www.gnu.org/licenses/
49+
##############################################################################
50+
51+
52+
cmdline_args = sys.argv[1:]
53+
54+
version = None
55+
path = None
56+
57+
if len(cmdline_args) > 1:
58+
path = cmdline_args[1]
59+
60+
if len(cmdline_args) > 0:
61+
version = cmdline_args[0]
62+
63+
64+
if not version:
65+
from datetime import datetime
66+
version = str(datetime.today().date()).replace('-','')
67+
68+
if not path:
69+
path = os.environ['PWD']
70+
71+
path_temp = os.path.join(path, 'special_knotinfo_spkg_temp_dir')
72+
path_src = os.path.join(path_temp, 'src')
73+
os.makedirs(path_temp)
74+
os.makedirs(path_src)
75+
76+
def convert(path_src, url, filen, reader):
77+
if reader == Xlsx2csv:
78+
excel = filen + '.xlsx'
79+
else:
80+
excel = filen + '.xls'
81+
csv = filen + '.csv'
82+
inp = os.path.join(url, excel)
83+
out = os.path.join(path_src, csv)
84+
if reader == Xlsx2csv:
85+
from six.moves.urllib.request import urlopen
86+
f = urlopen(inp)
87+
url_data = f.read()
88+
temp_file = os.path.join(path_temp, 'temp.xlsx')
89+
f = open(temp_file, 'wt')
90+
f.write(url_data)
91+
f.close()
92+
data = reader(temp_file, delimiter='|', skip_empty_lines=True)
93+
data.convert(out)
94+
else:
95+
data = reader(inp)
96+
data.to_csv(out, sep='|', index=False)
97+
98+
# first KnotInfo (using pandas and xlrd)
99+
convert(path_src, 'https://knotinfo.math.indiana.edu/', 'knotinfo_data_complete', read_excel)
100+
101+
# now LinkInfo (using xlsx2csv)
102+
convert(path_src, 'https://linkinfo.sitehost.iu.edu/', 'linkinfo_data_complete', Xlsx2csv)
103+
104+
tar_file = 'knotinfo-%s.tar.bz2' %version
105+
path_tar = os.path.join(path_temp, tar_file)
106+
107+
os.system('cd %s; tar -cvjSf %s src' %(path_temp, tar_file))
108+
os.system('mv %s %s; rm -rf %s' %(path_tar, path, path_temp))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| $(SAGERUNTIME)
2+
3+
----------
4+
All lines of this file are ignored except the first.
5+
It is copied by SAGE_ROOT/build/make/install into SAGE_ROOT/build/make/Makefile.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20210201
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cd $SAGE_ROOT/src/sage/
2+
3+
echo "Testing databases/knotinfo_db.py"
4+
sage -t --long --optional="sage,database_knotinfo" databases/knotinfo_db.py || sdh_die "Error testing KnotInfo databases"
5+
6+
echo "Testing knots/knotinfo.py"
7+
sage -t --optional="sage,database_knotinfo" knots/knotinfo.py || sdh_die "Error testing KnotInfo funcionality"
8+
9+
echo "Testing knots/link.py"
10+
sage -t --optional="sage,database_knotinfo" knots/link.py || sdh_die "Error testing KnotInfo funcionality"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
INSTALL="yes"
2+
TARGET="${SAGE_SHARE}/knotinfo"
3+
VERSION=`cat package-version.txt`
4+
if [ -d $TARGET ]
5+
then
6+
diff package-version.txt $TARGET > /dev/null 2>&1
7+
if [ $? -eq 0 ]
8+
then
9+
INSTALL="no"
10+
echo "Version $VERSION of knotinfo already installed"
11+
else
12+
OLD_VERSION=`cat $TARGET/package-version.txt`
13+
echo "Removing former version $OLD_VERSION of knotinfo"
14+
rm -rf $TARGET
15+
fi
16+
fi
17+
18+
if [ "$INSTALL" = "yes" ]
19+
then
20+
exec sage-python23 spkg-install.py
21+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
from sage.env import SAGE_SHARE
3+
from sage.misc.misc import sage_makedirs
4+
5+
install_root = os.path.join(SAGE_SHARE, 'knotinfo')
6+
7+
if __name__ == '__main__':
8+
sage_makedirs(install_root)
9+
print("Creating the KnotInfo database.")
10+
from sage.databases.knotinfo_db import KnotInfoDataBase
11+
KnotInfoDataBase(install=True)
12+
os.system('cp package-version.txt %s' %install_root)

build/pkgs/database_knotinfo/type

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
optional

src/doc/en/reference/databases/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ database engine.
6262
sage/databases/cunningham_tables
6363
sage/databases/db_class_polynomials
6464
sage/databases/db_modular_polynomials
65+
sage/databases/knotinfo_db
6566

6667
.. include:: ../footer.txt

src/doc/en/reference/knots/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ Knot Theory
66

77
sage/knots/knot
88
sage/knots/link
9+
sage/knots/knotinfo
910

1011
.. include:: ../footer.txt

0 commit comments

Comments
 (0)