Skip to content

Commit

Permalink
Wrap pydocstring to support users w/o pydocstring
Browse files Browse the repository at this point in the history
  • Loading branch information
kimt33 committed Sep 17, 2017
1 parent b36aca8 commit efbe3de
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 40 deletions.
2 changes: 1 addition & 1 deletion wfns/backend/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
from wfns.backend.slater import find_num_trans
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring


@docstring(indent_level=1)
Expand Down
2 changes: 1 addition & 1 deletion wfns/backend/integrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
from wfns.backend import slater
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class
# TODO: store fraction of integrals
# TODO: check that two electron integrals are in physicist's notation (check symmetry)

Expand Down
2 changes: 1 addition & 1 deletion wfns/backend/math_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from itertools import permutations, combinations
import numpy as np
from scipy.misc import comb
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring


@docstring(indent_level=1)
Expand Down
2 changes: 1 addition & 1 deletion wfns/backend/sd_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
from itertools import combinations, product
from wfns.backend import slater
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring

__all__ = ['sd_list']

Expand Down
2 changes: 1 addition & 1 deletion wfns/backend/slater.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"""
import gmpy2
import numpy as np
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring


# FIXME: necessary?
Expand Down
2 changes: 1 addition & 1 deletion wfns/hamiltonian/chemical_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from wfns.backend.integrals import OneElectronIntegrals, TwoElectronIntegrals
from wfns.backend import slater
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class


@docstring_class(indent_level=1)
Expand Down
2 changes: 1 addition & 1 deletion wfns/hamiltonian/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""
import numpy as np
from wfns.backend import slater
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring

__all__ = ['density_matrix']

Expand Down
2 changes: 1 addition & 1 deletion wfns/solver/ci_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import scipy.linalg
from wfns.wavefunction.ci.ci_wavefunction import CIWavefunction
from wfns.hamiltonian.chemical_hamiltonian import ChemicalHamiltonian
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/solver/equation_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from wfns.hamiltonian.chemical_hamiltonian import ChemicalHamiltonian
import wfns.backend.slater as slater
import wfns.backend.sd_list as sd_list
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring


# FIXME: copies most of system_solver for initialization and docstring
Expand Down
2 changes: 1 addition & 1 deletion wfns/solver/orb_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from wfns.wavefunction.nonorth.jacobi import JacobiWavefunction
from wfns.hamiltonian.chemical_hamiltonian import ChemicalHamiltonian
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring


@docstring(indent_level=1)
Expand Down
2 changes: 1 addition & 1 deletion wfns/solver/system_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wfns.backend import slater, sd_list
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from wfns.hamiltonian.chemical_hamiltonian import ChemicalHamiltonian
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring


@docstring(indent_level=1)
Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/base_wavefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import six
import numpy as np
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/ci/ci_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wfns.wavefunction.geminals.ap1rog import AP1roG
from wfns.backend.sd_list import sd_list
from wfns.backend import slater
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/ci/ci_wavefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from wfns.backend import slater
from wfns.backend.sd_list import sd_list
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/ci/doci.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""DOCI wavefunction."""
from __future__ import absolute_import, division, print_function
from wfns.wavefunction.ci.ci_wavefunction import CIWavefunction
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/ci/fci.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Full Configuration Interaction wavefunction."""
from __future__ import absolute_import, division, print_function
from wfns.wavefunction.ci.ci_wavefunction import CIWavefunction
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/geminals/ap1rog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wfns.backend import slater
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from wfns.wavefunction.geminals.apig import APIG
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/geminals/apg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import, division, print_function
from wfns.wavefunction.geminals.base_geminal import BaseGeminal
from wfns.backend.graphs import generate_complete_pmatch
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/geminals/apig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import, division, print_function
import numpy as np
from wfns.wavefunction.geminals.base_geminal import BaseGeminal
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/geminals/apr2g.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wfns.wavefunction.geminals.apig import APIG
from wfns.wavefunction.geminals.base_geminal import BaseGeminal
from wfns.backend import slater, math_tools
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/geminals/apsetg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import, division, print_function
from wfns.backend import graphs
from wfns.wavefunction.geminals.base_geminal import BaseGeminal
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
17 changes: 1 addition & 16 deletions wfns/wavefunction/geminals/base_geminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from wfns.backend import slater
from wfns.backend import math_tools
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down Expand Up @@ -353,21 +353,6 @@ def get_overlap(self, sd, deriv=None):
where :math:`N_{gem}` is the number of geminals, :math:`\mathbf{m}` is a Slater determinant.
Parameters
----------
sd : int
Integer that describes the occupation of a Slater determinant as a bitstring.
See `wfns.backend.slater` for details.
deriv : {int, None}
Index (within the flattened array of parameters) with respect to which the overlap is
derivatized.
Default is no derivatization
Returns
-------
overlap : float
Overlap of the geminal wavefunction and the Slater determinant.
Raises
------
TypeError
Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/nonorth/jacobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from wfns.backend import slater
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from wfns.wavefunction.nonorth.nonorth_wavefunction import NonorthWavefunction
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion wfns/wavefunction/nonorth/nonorth_wavefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from wfns.backend import slater
from wfns.wavefunction.base_wavefunction import BaseWavefunction
from wfns.wavefunction.ci.ci_wavefunction import CIWavefunction
from pydocstring.wrapper import docstring_class
from wfns.wrapper.docstring import docstring_class

__all__ = []

Expand Down
1 change: 1 addition & 0 deletions wfns/wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from __future__ import absolute_import

from . import python_wrapper
from . import docstring
51 changes: 51 additions & 0 deletions wfns/wrapper/docstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Wrapper for the pydocstring module."""
from functools import wraps


# FIXME: this function is copied from pydocstring
def kwarg_wrapper(wrapper):
"""Wraps the keyword arguments into the wrapper.
The wrapper behaves differently when used as a decorator if the arguments are given. i.e.
@decorator vs @decorator(). Therefore, the default keyword values of the wrapper must be changed
(with another wrapper).
"""
@wraps(wrapper)
def new_wrapper(obj=None, **kwargs):
"""Reconstruction of the provided wrapper so that keyword arguments are rewritten.
When a wrapper is used as a decorator and is not called (i.e. no parenthesis),
then the wrapee (wrapped object) is automatically passed into the decorator. This function
changes the "default" keyword arguments so that the decorator is not called (so that the
wrapped object is automatically passed in). If the decorator is called,
e.g. `x = decorator(x)`, then it simply needs to return the wrapped value.
"""
# the decorator is evaluated.
if obj is None and len(kwargs) > 0:
# Since no object is provided, we need to turn the wrapper back into a form so that it
# will automatically pass in the object (i.e. turn it into a function) after overwriting
# the keyword arguments
return lambda orig_obj: wrapper(orig_obj, **kwargs)
else:
# Here, the object is provided OR keyword argument is not provided.
# If the object is provided, then the wrapper can be executed.
# If the object is not provided and keyword argument is not provided, then an error will
# be raised.
return wrapper(obj, **kwargs)

return new_wrapper


try:
import pydocstring
except ModuleNotFoundError:
@kwarg_wrapper
def docstring(obj, **kwargs):
return obj

@kwarg_wrapper
def docstring_class(obj, **kwargs):
return obj
else:
docstring = pydocstring.wrapper.docstring
docstring_class = pydocstring.wrapper.docstring_class
2 changes: 1 addition & 1 deletion wfns/wrapper/python_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
from subprocess import call
import numpy as np
from pydocstring.wrapper import docstring
from wfns.wrapper.docstring import docstring

dirname = os.path.dirname(os.path.abspath(__file__))

Expand Down

0 comments on commit efbe3de

Please sign in to comment.