Skip to content

Commit

Permalink
Auto formatting (#60)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ntjohnson1 authored Mar 4, 2023
1 parent e5cedce commit 992772b
Show file tree
Hide file tree
Showing 37 changed files with 4,154 additions and 2,279 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install numpy scipy numpy_groupies pytest-cov coverage coveralls sphinx_rtd_theme flake8
python -m pip install numpy scipy numpy_groupies pytest-cov coverage coveralls \
sphinx_rtd_theme isort black pylint mypy
pip install .
- name: Check auto-formatters
run: |
isort --check .
black --check .
# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
Expand Down
53 changes: 53 additions & 0 deletions CONTRIBUTOR_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Python Tensor Toolbox Contributor Guide

## Issues
If you are looking to get started or want to propose a change please start by checking
current or filing a new [issue](https://github.com/sandialabs/pyttb/issues).

## Working on PYTTB locally
1. clone your fork and enter the directory
```
git clone git@github.com:<your username>/pyttb.git
cd pyttb
```
1. setup your desired python environment as appropriate

1. install dependencies
```
We use a mix of pyproject.toml, and setup.py currently. We are
still iterating on simplifying the setup procedure.
```

1. Checkout a branch and make your changes
```
git checkout -b my-new-feature-branch
```
1. Formatters and linting
1. Run autoformatters from root of project (they will change your code)
```commandline
isort .
black .
```
1. Pylint and mypy coverage is work in progress (these only raise errors)
```commandline
mypy pyttb/
pylint pyttb/file_name.py //Today only tensor is compliant
```

1. Run tests (at desired fidelity)
1. Just doctests (enabled by default)
```commandline
pytest
```
1. Functional tests
```commandline
pytest .
```
1. All tests (linting and formatting checks)
```commandline
pytest . --packaging
```
1. With coverage
```commandline
pytest . --cov=pyttb --cov-report=term-missing
```
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ for computing low-rank tensor models.
* `sptensor`: sparse tensors
* `ktensor`: Kruskal tensors
* `tenmat`: matricized tensors
* `ttensor`: Tucker tensors

**Tensor Algorithms:**
* `cp_als`, `cp_apr`: Canonical Polyadic (CP) decompositions
* `tucker_als`: Tucker decompostions

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

# Contributing
Check out our [contributing guide](CONTRIBUTOR_GUIDE.md).

---
[![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)
21 changes: 15 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@
# LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
# U.S. Government retains certain rights in this software.

import numpy

# content of conftest.py
import pytest
import numpy

import pyttb


@pytest.fixture(autouse=True)
def add_packages(doctest_namespace):
doctest_namespace['np'] = numpy
doctest_namespace['ttb'] = pyttb
doctest_namespace["np"] = numpy
doctest_namespace["ttb"] = pyttb


def pytest_addoption(parser):
parser.addoption('--packaging', action='store_true', dest="packaging",
default=False, help="enable slow packaging tests")
parser.addoption(
"--packaging",
action="store_true",
dest="packaging",
default=False,
help="enable slow packaging tests",
)


def pytest_configure(config):
if not config.option.packaging:
setattr(config.option, 'markexpr', 'not packaging')
setattr(config.option, "markexpr", "not packaging")
72 changes: 39 additions & 33 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('.'))

sys.path.insert(0, os.path.abspath("../../"))
sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, os.path.abspath("."))

from pyttb import __version__

# -- Project information -----------------------------------------------------

project = 'pyttb'
copyright = ''
author = 'Danny Dunlavy, Nick Johnson'
project = "pyttb"
copyright = ""
author = "Danny Dunlavy, Nick Johnson"

# The short X.Y version
version = __version__
# The full version, including alpha/beta/rc tags
release = ''
release = ""


# -- General configuration ---------------------------------------------------
Expand All @@ -46,11 +47,11 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon'
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
]

napoleon_use_param = False
Expand All @@ -59,19 +60,19 @@
intersphinx_mapping = {
"numpy": ("http://docs.scipy.org/doc/numpy/", "numpy.inv"),
"python": ("http://docs.python.org/3.6/", "python.inv"),
}
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

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

# Output file base name for HTML help builder.
htmlhelp_basename = 'pyttbdoc'
htmlhelp_basename = "pyttbdoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -130,37 +131,36 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
'pointsize': '10pt',

"pointsize": "10pt",
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
'figure_align': 'htbp',
"figure_align": "htbp",
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pyttb.tex', 'pyttb Documentation',
'Danny Dunlavy, Nick Johnson', 'manual'),
(
master_doc,
"pyttb.tex",
"pyttb Documentation",
"Danny Dunlavy, Nick Johnson",
"manual",
),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pyttb', 'pyttb Documentation',
[author], 1)
]
man_pages = [(master_doc, "pyttb", "pyttb Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -169,13 +169,19 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pyttb', 'pyttb Documentation',
author, 'Danny Dunlavy, Nick Johnson', 'Python Tensor Toolbox',
'Miscellaneous'),
(
master_doc,
"pyttb",
"pyttb Documentation",
author,
"Danny Dunlavy, Nick Johnson",
"Python Tensor Toolbox",
"Miscellaneous",
),
]


# -- Extension configuration -------------------------------------------------
# Autodoc settings
autoclass_content = "class"
autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"
27 changes: 14 additions & 13 deletions pyttb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
# LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
# U.S. Government retains certain rights in this software.

__version__ = '1.3.8'
__version__ = "1.3.8"

import warnings

from pyttb.cp_als import cp_als
from pyttb.cp_apr import *
from pyttb.export_data import export_data
from pyttb.import_data import import_data
from pyttb.khatrirao import khatrirao
from pyttb.ktensor import ktensor
from pyttb.sptensor import sptensor
from pyttb.tensor import tensor
from pyttb.pyttb_utils import *
from pyttb.sptenmat import sptenmat
from pyttb.sptensor import sptensor
from pyttb.sptensor3 import sptensor3
from pyttb.sumtensor import sumtensor
from pyttb.symktensor import symktensor
from pyttb.symtensor import symtensor
from pyttb.tenmat import tenmat
from pyttb.tensor import tensor
from pyttb.ttensor import ttensor

from pyttb.pyttb_utils import *
from pyttb.khatrirao import khatrirao
from pyttb.cp_apr import *
from pyttb.cp_als import cp_als
from pyttb.tucker_als import tucker_als

from pyttb.import_data import import_data
from pyttb.export_data import export_data

import warnings
def ignore_warnings(ignore=True):
if ignore:
warnings.simplefilter('ignore')
warnings.simplefilter("ignore")
else:
warnings.simplefilter('default')
warnings.simplefilter("default")


ignore_warnings(True)
Loading

0 comments on commit 992772b

Please sign in to comment.