Snippet update¶
Snip plugin for Sphinx conf.py
. Replaces snippet containing variables:
copyright
version
release
release_date
- drain_swamp.snippet_sphinx_conf.__all__: tuple[str] = ("SnipSphinxConf", "entrypoint_name")¶
Module exports
- drain_swamp.snippet_sphinx_conf.entrypoint_name: str = "drain-swamp"¶
Will use this entrypoint. In
pyproject.toml
,[tool.drain-swamp]
- drain_swamp.snippet_sphinx_conf._logger: logging.Logger¶
Module level logger
- class drain_swamp.snippet_sphinx_conf.SnipSphinxConf(path=None)¶
Snip plugin for Sphinx conf.py snippet which sets:
copyright
version
release
release_date
This is done for every tagged release
Sphinx docs folder name is either
doc
ordocs
. If it’s something else, complain!- Variables:
path (pathlib.Path | None) – Default None. absolute path to package base folder. If None, use current working folder
- Raises:
NotADirectoryError
– From package base folder there is no doc/ or docs/ folderFileNotFoundError
– In a doc folder, Sphinx config conf.py file not found
- property SV: SemVersion | None¶
Getter for SemVersion instance.
- Returns:
After call to contents, SemVersion instance is available
- Return type:
SemVersion | None
- property author_name_left: str | None¶
Getter for author name, but just the left portion.
In Japanese, this is the full name. Otherwise would be the first name
Used within regex to replace copyright notice
- Returns:
Author name left. If contents yet to be called will be None
- Return type:
str | None
- contents(kind, package_name, copyright_start_year)¶
Create the snippet for Sphinx
conf.py
.This will set:
copyright
version
release
release_date
This is done for every tagged release
Sphinx docs folder name is either
doc
ordocs
. If it’s something else, complain!- Parameters:
kind¶ (str) – Explicit version str or “current”|”now” or “tag”.
tag
for the latest tagged version. Current for the latest version which is probably the development versionpackage_name¶ (str) – Can contain either hyphen or underscore. Both will work. From the package name can get the author name and email address. Only interested in the author name
copyright_start_year¶ (str) – This packages copyright start year
- Raises:
AssertionError
– Expected Sphinx docs folder to be eitherdoc/
ordocs/
ValueError
– Explicit version str is invalid
- classmethod now()¶
Current datetime.
- Returns:
current datetime
- Return type:
- classmethod now_to_str(strftime_str)¶
Format datetime now.
- property path_abs¶
Absolute path to
doc/conf.py
ordocs/conf.py
.- Returns:
package base folder
- Return type:
- path_abs_init()¶
Using from package base path or cwd, find doc/ or docs/ folder absolute path.
- Raises:
NotADirectoryError
– From package base folder there is no doc/ or docs/ folderFileNotFoundError
– In a doc folder, Sphinx config conf.py file not found
- property path_cwd¶
Get package base folder.
- Returns:
package base folder
- Return type:
- replace(snippet_co=None)¶
In a Sphinx conf.py file, for a given snippet, replace contents.
- Parameters:
snippet_co¶ (str | None) – Default None. id of snippet within Sphinx
conf.py
. If None, that snippet better not have an id or there be other snippets in that file- Returns:
VALIDATE_FAIL – Invalid snippet
NOMATCH – no matching snippet with snippet_co
NO_CHANGE – no replacement occurred
REPLACED – replaced contents
- Return type: