Skip to content

Commit 992772b

Browse files
authored
Auto formatting (#60)
* COVERAGE: Fix some coverage regressions from pylint PR * ISORT: Run isort on source and tests * BLACK: Run black on source and tests * BLACK: Run black on source and tests * FORMATTING: Add tests and verification for autoformatting * FORMATTING: Add black/isort to root to simplify * Add preliminary contributor guide instructions Closes #59
1 parent e5cedce commit 992772b

37 files changed

+4154
-2279
lines changed

.github/workflows/regression-tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ jobs:
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
30-
python -m pip install numpy scipy numpy_groupies pytest-cov coverage coveralls sphinx_rtd_theme flake8
30+
python -m pip install numpy scipy numpy_groupies pytest-cov coverage coveralls \
31+
sphinx_rtd_theme isort black pylint mypy
3132
pip install .
33+
- name: Check auto-formatters
34+
run: |
35+
isort --check .
36+
black --check .
3237
# - name: Lint with flake8
3338
# run: |
3439
# # stop the build if there are Python syntax errors or undefined names

CONTRIBUTOR_GUIDE.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Python Tensor Toolbox Contributor Guide
2+
3+
## Issues
4+
If you are looking to get started or want to propose a change please start by checking
5+
current or filing a new [issue](https://github.com/sandialabs/pyttb/issues).
6+
7+
## Working on PYTTB locally
8+
1. clone your fork and enter the directory
9+
```
10+
git clone [email protected]:<your username>/pyttb.git
11+
cd pyttb
12+
```
13+
1. setup your desired python environment as appropriate
14+
15+
1. install dependencies
16+
```
17+
We use a mix of pyproject.toml, and setup.py currently. We are
18+
still iterating on simplifying the setup procedure.
19+
```
20+
21+
1. Checkout a branch and make your changes
22+
```
23+
git checkout -b my-new-feature-branch
24+
```
25+
1. Formatters and linting
26+
1. Run autoformatters from root of project (they will change your code)
27+
```commandline
28+
isort .
29+
black .
30+
```
31+
1. Pylint and mypy coverage is work in progress (these only raise errors)
32+
```commandline
33+
mypy pyttb/
34+
pylint pyttb/file_name.py //Today only tensor is compliant
35+
```
36+
37+
1. Run tests (at desired fidelity)
38+
1. Just doctests (enabled by default)
39+
```commandline
40+
pytest
41+
```
42+
1. Functional tests
43+
```commandline
44+
pytest .
45+
```
46+
1. All tests (linting and formatting checks)
47+
```commandline
48+
pytest . --packaging
49+
```
50+
1. With coverage
51+
```commandline
52+
pytest . --cov=pyttb --cov-report=term-missing
53+
```

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ for computing low-rank tensor models.
1515
* `sptensor`: sparse tensors
1616
* `ktensor`: Kruskal tensors
1717
* `tenmat`: matricized tensors
18+
* `ttensor`: Tucker tensors
1819

1920
**Tensor Algorithms:**
2021
* `cp_als`, `cp_apr`: Canonical Polyadic (CP) decompositions
22+
* `tucker_als`: Tucker decompostions
2123

24+
# Getting Started
2225
Check out the [Documentation](https://pyttb.readthedocs.io) to get started.
2326

27+
# Contributing
28+
Check out our [contributing guide](CONTRIBUTOR_GUIDE.md).
29+
2430
---
2531
[![Regression tests](https://github.com/sandialabs/pyttb/actions/workflows/regression-tests.yml/badge.svg)](https://github.com/sandialabs/pyttb/actions/workflows/regression-tests.yml) [![Coverage Status](https://coveralls.io/repos/github/sandialabs/pyttb/badge.svg?branch=main)](https://coveralls.io/github/sandialabs/pyttb?branch=main)

conftest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@
22
# LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
33
# U.S. Government retains certain rights in this software.
44

5+
import numpy
6+
57
# content of conftest.py
68
import pytest
7-
import numpy
9+
810
import pyttb
11+
12+
913
@pytest.fixture(autouse=True)
1014
def add_packages(doctest_namespace):
11-
doctest_namespace['np'] = numpy
12-
doctest_namespace['ttb'] = pyttb
15+
doctest_namespace["np"] = numpy
16+
doctest_namespace["ttb"] = pyttb
1317

1418

1519
def pytest_addoption(parser):
16-
parser.addoption('--packaging', action='store_true', dest="packaging",
17-
default=False, help="enable slow packaging tests")
20+
parser.addoption(
21+
"--packaging",
22+
action="store_true",
23+
dest="packaging",
24+
default=False,
25+
help="enable slow packaging tests",
26+
)
1827

1928

2029
def pytest_configure(config):
2130
if not config.option.packaging:
22-
setattr(config.option, 'markexpr', 'not packaging')
31+
setattr(config.option, "markexpr", "not packaging")

docs/source/conf.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@
1818
#
1919
import os
2020
import sys
21-
sys.path.insert(0, os.path.abspath('../../'))
22-
sys.path.insert(0, os.path.abspath('../'))
23-
sys.path.insert(0, os.path.abspath('.'))
21+
22+
sys.path.insert(0, os.path.abspath("../../"))
23+
sys.path.insert(0, os.path.abspath("../"))
24+
sys.path.insert(0, os.path.abspath("."))
2425

2526
from pyttb import __version__
2627

2728
# -- Project information -----------------------------------------------------
2829

29-
project = 'pyttb'
30-
copyright = ''
31-
author = 'Danny Dunlavy, Nick Johnson'
30+
project = "pyttb"
31+
copyright = ""
32+
author = "Danny Dunlavy, Nick Johnson"
3233

3334
# The short X.Y version
3435
version = __version__
3536
# The full version, including alpha/beta/rc tags
36-
release = ''
37+
release = ""
3738

3839

3940
# -- General configuration ---------------------------------------------------
@@ -46,11 +47,11 @@
4647
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4748
# ones.
4849
extensions = [
49-
'sphinx.ext.autodoc',
50+
"sphinx.ext.autodoc",
5051
"sphinx.ext.intersphinx",
51-
'sphinx.ext.mathjax',
52-
'sphinx.ext.viewcode',
53-
'sphinx.ext.napoleon'
52+
"sphinx.ext.mathjax",
53+
"sphinx.ext.viewcode",
54+
"sphinx.ext.napoleon",
5455
]
5556

5657
napoleon_use_param = False
@@ -59,19 +60,19 @@
5960
intersphinx_mapping = {
6061
"numpy": ("http://docs.scipy.org/doc/numpy/", "numpy.inv"),
6162
"python": ("http://docs.python.org/3.6/", "python.inv"),
62-
}
63+
}
6364

6465
# Add any paths that contain templates here, relative to this directory.
65-
templates_path = ['_templates']
66+
templates_path = ["_templates"]
6667

6768
# The suffix(es) of source filenames.
6869
# You can specify multiple suffix as a list of string:
6970
#
7071
# source_suffix = ['.rst', '.md']
71-
source_suffix = '.rst'
72+
source_suffix = ".rst"
7273

7374
# The master toctree document.
74-
master_doc = 'index'
75+
master_doc = "index"
7576

7677
# The language for content autogenerated by Sphinx. Refer to documentation
7778
# for a list of supported languages.
@@ -86,15 +87,15 @@
8687
exclude_patterns = []
8788

8889
# The name of the Pygments (syntax highlighting) style to use.
89-
pygments_style = 'sphinx'
90+
pygments_style = "sphinx"
9091

9192

9293
# -- Options for HTML output -------------------------------------------------
9394

9495
# The theme to use for HTML and HTML Help pages. See the documentation for
9596
# a list of builtin themes.
9697
#
97-
html_theme = 'sphinx_rtd_theme'
98+
html_theme = "sphinx_rtd_theme"
9899

99100
# Theme options are theme-specific and customize the look and feel of a theme
100101
# further. For a list of options available for each theme, see the
@@ -121,7 +122,7 @@
121122
# -- Options for HTMLHelp output ---------------------------------------------
122123

123124
# Output file base name for HTML help builder.
124-
htmlhelp_basename = 'pyttbdoc'
125+
htmlhelp_basename = "pyttbdoc"
125126

126127

127128
# -- Options for LaTeX output ------------------------------------------------
@@ -130,37 +131,36 @@
130131
# The paper size ('letterpaper' or 'a4paper').
131132
#
132133
# 'papersize': 'letterpaper',
133-
134134
# The font size ('10pt', '11pt' or '12pt').
135135
#
136-
'pointsize': '10pt',
137-
136+
"pointsize": "10pt",
138137
# Additional stuff for the LaTeX preamble.
139138
#
140139
# 'preamble': '',
141-
142140
# Latex figure (float) alignment
143141
#
144-
'figure_align': 'htbp',
142+
"figure_align": "htbp",
145143
}
146144

147145
# Grouping the document tree into LaTeX files. List of tuples
148146
# (source start file, target name, title,
149147
# author, documentclass [howto, manual, or own class]).
150148
latex_documents = [
151-
(master_doc, 'pyttb.tex', 'pyttb Documentation',
152-
'Danny Dunlavy, Nick Johnson', 'manual'),
149+
(
150+
master_doc,
151+
"pyttb.tex",
152+
"pyttb Documentation",
153+
"Danny Dunlavy, Nick Johnson",
154+
"manual",
155+
),
153156
]
154157

155158

156159
# -- Options for manual page output ------------------------------------------
157160

158161
# One entry per manual page. List of tuples
159162
# (source start file, name, description, authors, manual section).
160-
man_pages = [
161-
(master_doc, 'pyttb', 'pyttb Documentation',
162-
[author], 1)
163-
]
163+
man_pages = [(master_doc, "pyttb", "pyttb Documentation", [author], 1)]
164164

165165

166166
# -- Options for Texinfo output ----------------------------------------------
@@ -169,13 +169,19 @@
169169
# (source start file, target name, title, author,
170170
# dir menu entry, description, category)
171171
texinfo_documents = [
172-
(master_doc, 'pyttb', 'pyttb Documentation',
173-
author, 'Danny Dunlavy, Nick Johnson', 'Python Tensor Toolbox',
174-
'Miscellaneous'),
172+
(
173+
master_doc,
174+
"pyttb",
175+
"pyttb Documentation",
176+
author,
177+
"Danny Dunlavy, Nick Johnson",
178+
"Python Tensor Toolbox",
179+
"Miscellaneous",
180+
),
175181
]
176182

177183

178184
# -- Extension configuration -------------------------------------------------
179185
# Autodoc settings
180186
autoclass_content = "class"
181-
autodoc_member_order = 'bysource'
187+
autodoc_member_order = "bysource"

pyttb/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22
# LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
33
# U.S. Government retains certain rights in this software.
44

5-
__version__ = '1.3.8'
5+
__version__ = "1.3.8"
66

7+
import warnings
8+
9+
from pyttb.cp_als import cp_als
10+
from pyttb.cp_apr import *
11+
from pyttb.export_data import export_data
12+
from pyttb.import_data import import_data
13+
from pyttb.khatrirao import khatrirao
714
from pyttb.ktensor import ktensor
8-
from pyttb.sptensor import sptensor
9-
from pyttb.tensor import tensor
15+
from pyttb.pyttb_utils import *
1016
from pyttb.sptenmat import sptenmat
17+
from pyttb.sptensor import sptensor
1118
from pyttb.sptensor3 import sptensor3
1219
from pyttb.sumtensor import sumtensor
1320
from pyttb.symktensor import symktensor
1421
from pyttb.symtensor import symtensor
1522
from pyttb.tenmat import tenmat
23+
from pyttb.tensor import tensor
1624
from pyttb.ttensor import ttensor
17-
18-
from pyttb.pyttb_utils import *
19-
from pyttb.khatrirao import khatrirao
20-
from pyttb.cp_apr import *
21-
from pyttb.cp_als import cp_als
2225
from pyttb.tucker_als import tucker_als
2326

24-
from pyttb.import_data import import_data
25-
from pyttb.export_data import export_data
2627

27-
import warnings
2828
def ignore_warnings(ignore=True):
2929
if ignore:
30-
warnings.simplefilter('ignore')
30+
warnings.simplefilter("ignore")
3131
else:
32-
warnings.simplefilter('default')
32+
warnings.simplefilter("default")
33+
3334

3435
ignore_warnings(True)

0 commit comments

Comments
 (0)