Skip to content

Commit 83f14a3

Browse files
author
Sudarshan Raghunathan
committed
Update to Python3; Remove references to UF Sparse; Add Jupyter notebook support
1 parent 82a56a3 commit 83f14a3

File tree

14 files changed

+278
-211
lines changed

14 files changed

+278
-211
lines changed

PyUFGet/__main__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

PyUFGet/config.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

PyUFGet/query.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

Tests/PyUFGet_test.py renamed to Tests/ssget_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
import PyUFGet as p
2+
import ssget as p
33

44
class TestPyUFGet(unittest.TestCase):
55
def test_search_by_id(self):

setup.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
#!/usr/bin/env python
2-
from distutils.core import setup
1+
from setuptools import setup
32

4-
setup(name="PyUFGet",
3+
setup(name="ssget",
54
version="0.92",
6-
description="A Python interface to the University of Florida Sparse Matrix Collection",
5+
description="A Python interface to the SparseSuite Matrix Collection",
76
author="Sudarshan Raghunathan",
87
author_email="rdarshan@gmail.com",
9-
url="http://www.github.com/drdarshan/PyUFGet",
10-
packages=["PyUFGet"])
8+
url="http://www.github.com/drdarshan/ssget",
9+
packages=["ssget"],
10+
entry_points={
11+
"console_scripts": [
12+
"ssget = ssget.query:cli",
13+
],
14+
},
15+
install_requires=['tqdm']
16+
)

PyUFGet/__init__.py renamed to ssget/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
'''
2-
The PyUFGet module provides interfaces to search and download matrices from the
2+
The `ssget` module provides interfaces to search and download matrices from the
33
University of Florida Sparse Matrix Collection.
44
5-
There are two ways to use PyUFGet:
6-
* By importing the PyUFGet module in Python, or
5+
There are two ways to use `ssget`:
6+
* By importing the `ssget` module in Python, or
77
* As a standalone command-line tool
88
9-
To search for sparse matrices that match a given criterion, use `PyUFGet.search` ::
9+
To search for sparse matrices that match a given criterion, use `ssget.search` ::
1010
11-
PyUFGet.search(name_or_id, **kwargs)
11+
`ssget.search(name_or_id, **kwargs)`
1212
13-
`PyUFGet.search` only returns a list of `Matrix` objects that match
13+
`ssget.search` only returns a list of `Matrix` objects that match
1414
the selection criterion. To download the matrices themselves, use the
15-
`download` method in the `Matrix object` or use `PyUFGet.fetch` ::
15+
`download` method in the `Matrix object` or use `ssget.fetch` ::
1616
17-
PyUFGet.fetch(name_or_id, format, location, **kwargs)
17+
`ssget.fetch(name_or_id, format, location, **kwargs)`
1818
19-
The rules for specifying the search criteria in `PyUFGet.search` and
20-
`PyUFGet.fetch` are as follows:
19+
The rules for specifying the search criteria in `ssget.search` and
20+
`ssget.fetch` are as follows:
2121
2222
1. `name_or_id` can be either the numerical ID of the matrix such as
2323
`42` or a pattern such as `"HB/ash*"` or `"c-"`. This field is
@@ -39,17 +39,17 @@
3939
4040
If `name_or_id` is specified, it overrides any conflicting key-value settings in `**kwargs`.
4141
42-
In `PyUFGet.fetch`, `format` can be one of 'MM', 'MAT' or 'RB'; 'MM'
42+
In `ssget.fetch`, `format` can be one of 'MM', 'MAT' or 'RB'; 'MM'
4343
is the default if `format` is omitted. Finally, `location` refers
4444
to the directory where the matrices will be downloaded on the local
45-
machine. It defaults to `%APPDATA%/PyUFGet` on Windows and
46-
`~/.PyUFGet` on Unix-like platforms.
45+
machine. It defaults to `%APPDATA%/`ssget`` on Windows and
46+
`~/.ssget` on Unix-like platforms.
4747
48-
In addition to its usage as a Python library, PyUFGet can be run from
48+
In addition to its usage as a Python library, `ssget` can be run from
4949
the command line as follows ::
5050
51-
python PyUFGet
52-
Usage: PyUFGet [NameOrID] [options]
51+
python `ssget`
52+
Usage: `ssget` [NameOrID] [options]
5353
5454
NameOrID A numerical matrix ID or a pattern matching the name of
5555
the matrix.
@@ -76,7 +76,7 @@
7676
-o LOCATION, --outdir=LOCATION
7777
The directory in the local machine where matrices will
7878
be downloaded to. Defaults to
79-
%AppData%\PyUFGet on Windows and ~/.PyUFGet on Unix.
79+
`%AppData%\ssget` on Windows and `~/.ssget` on Unix.
8080
8181
Size and Non-zero filters:
8282
These options may be used to restrict the shape or number of non-zero
@@ -97,5 +97,5 @@
9797
The maximum number of non-zero values in the
9898
matrix/matrices.
9999
'''
100-
from query import search, fetch, cli
100+
from .query import search, fetch, cli
101101
__all__ = ["query"]

ssget/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .query import cli
2+
cli()

PyUFGet/bundle.py renamed to ssget/bundle.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import gzip
2+
import os
3+
import tarfile
4+
import shutil
5+
16
def extract(bundle):
2-
import gzip
3-
import os
4-
import tarfile
57
basedir, filename = os.path.split(bundle)
68
tarfilename = os.path.join(basedir, '.'.join((filename.split('.')[0], 'tar')))
79
gzfile = gzip.open(bundle, 'rb')
810
with open(tarfilename, 'wb') as outtarfile:
9-
import shutil
1011
shutil.copyfileobj(gzfile, outtarfile)
1112
gzfile.close()
1213
tarfile.open(tarfilename).extractall(basedir)

ssget/config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import sys
3+
import logging
4+
5+
logger = logging.getLogger(__name__)
6+
7+
SS_DIR = None
8+
SS_DB = "index.db"
9+
SS_TABLE = "MATRICES"
10+
SS_ROOT_URL = "https://sparse.tamu.edu"
11+
SS_INDEX_URL = "/".join((SS_ROOT_URL, "files", "ssstats.csv"))
12+
13+
if sys.platform == "win32":
14+
SS_DIR = os.path.join(os.environ["APPDATA"], "ssget")
15+
else:
16+
SS_DIR = os.path.join(os.environ["HOME"], ".ssget")
17+
18+
SS_DB = os.path.join(SS_DIR, SS_DB)
19+
20+
os.makedirs(SS_DIR, exist_ok=True)
21+
22+
def dump():
23+
logger.debug(dict(SS_DIR=SS_DIR, SS_DB=SS_DB, SS_TABLE=SS_TABLE, SS_ROOT_URL=SS_ROOT_URL, SS_INDEX_URL=SS_INDEX_URL))
24+
25+
26+
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
'''
2-
The `csvindex` module parses the UFStats.csv file and generate entries for each row in a Matrix database
2+
The `csvindex` module parses the SSStats.csv file and generate entries for each row in a Matrix database
33
'''
44

5+
import csv
6+
import logging
7+
import requests
8+
from .config import SS_INDEX_URL
9+
10+
logger = logging.getLogger(__name__)
11+
512
def getdtype(real, logical):
613
'''
714
Converts a (real, logical) pair into one of the three types, 'real', 'complex' and 'binary'
815
'''
916
return 'binary' if logical else ('real' if real else 'complex')
1017

11-
def gen_rows(csvfile):
18+
def gen_rows(csvrows):
1219
'''
1320
Creates a generator that returns a single row in the matrix database.
1421
'''
15-
import csv
16-
reader = csv.reader(csvfile)
22+
reader = csv.reader(csvrows)
1723
matid = 0
1824
for line in reader:
1925
matid += 1
@@ -32,14 +38,12 @@ def gen_rows(csvfile):
3238
yield matid, group, name, rows, cols, nnz, getdtype(real, logical), is2d3d, isspd, psym, nsym, kind
3339

3440
def generate():
35-
from config import UF_INDEX_URL
36-
import urllib2
37-
csvfile = urllib2.urlopen(UF_INDEX_URL)
38-
39-
import logging
41+
response = requests.get(SS_INDEX_URL)
42+
lines = response.iter_lines()
43+
4044
# Read the number of entries
41-
logging.info("Number of entries in the CSV file: " + csvfile.readline())
45+
logger.info(f'Number of entries in the CSV file: {next(lines)}')
4246
# Read the last modified date
43-
logging.info("Last modified date: " + csvfile.readline())
47+
logger.info(f'Last modified date: {next(lines)}')
4448

45-
return gen_rows(csvfile)
49+
return gen_rows(line.decode('utf-8') for line in lines)

0 commit comments

Comments
 (0)