docsweeper — Public API#
In this part we describe the public python API of Docsweeper, and show how to use it in code.
Example Usage#
The following code snippet shows how Docsweeper can be employed in code:
import docsweeper
from pathlib import Path
file_ = Path("code.py")
# create configuration object:
config = VCSCommandSetConfig(
executable="/usr/bin/git",
follow_rename=True
)
# choose version control system:
vcs = docsweeper.GitCommandSet
# run analysis and obtain results:
results = docsweeper.analyze(vcs, config, file_)
Running docsweeper.analyze_file() will parse and analyze the input file. See the
full API below for more information on the data types used for the results.
API#
This is the public Python API of Docsweeper.
Client Entry Points#
Use docsweeper.analyze_file() to retrieve statistics about the docstrings of all
the tokens in a file:
- docsweeper.analyze_file(vcs_command_set_type, vcs_command_set_config, path)#
Analyzes code file at path and return its documented token statistics.
- Parameters:
vcs_command_set_type (Type[VCSCommandSet]) – type of the version control system to use
vcs_command_set_config (VCSCommandSetConfig) – version control configuration
path (Path) – points to the code file in the file system
- Raises:
VCSExecutableError – if there is an unexpected error with the executable set in vcs_command_set_config
ParserError – if there is an unexpected error parsing path
- Returns:
each entry of the list consists of the documented token, and its docstring history statistic
- Return type:
New in version 0.3.0.
Result Data Types#
These are the types used in the return value of docsweeper.analyze_file():
- class docsweeper.DocumentedToken#
Bases:
NamedTupleData class for a python code token.
- class docsweeper.DocumentedTokenStatistic#
Bases:
NamedTupleStatistics about the docstring history of a
DocumentedToken.- code_changes: int#
How often the body of the token was changed since
last_docstring_change.
Version Control#
These classes are concerned with the interaction with the Version control system, and
are passed as parameters to docsweeper.analyze_file().
docsweeper.GitCommandSet and docsweeper.MercurialCommandSet define the
kind of version control system used, while docsweeper.VCSCommandSetConfig
provides user-defined parameters to customize version control behavior.
- class docsweeper.VCSCommandSet#
Bases:
ABCEncapsulates all commands needed for a complete version control command set.
New in version 0.4.0.
- class docsweeper.GitCommandSet#
Bases:
VCSCommandSetAn implementation of a version control command set for git.
- class docsweeper.MercurialCommandSet#
Bases:
VCSCommandSetAn implementation of a version control command set for mercurial.
- class docsweeper.VCSCommandSetConfig#
Bases:
NamedTupleConfiguration values for
VCSCommandSet.Holds configuration values that are customizable by clients.
- merge(other)#
Return a new config with merged values of this config and other.
- Parameters:
other (VCSCommandSetConfig) – entries that are not
Nonein this config are merged into the new one- Returns:
the merged config
- Return type:
- docsweeper.command_sets = {'git': (<class '_docsweeper.version_control.GitCommandSet'>, VCSCommandSetConfig(executable=PosixPath('/usr/bin/git'), follow_rename=True)), 'hg': (<class '_docsweeper.version_control.MercurialCommandSet'>, VCSCommandSetConfig(executable=PosixPath('/usr/bin/hg'), follow_rename=True))}#
Dictionary of all supported command sets and their default configuration.
New in version 0.3.0.