Skip to content

Commit

Permalink
chore(doc): Add Sphinx build (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA authored Apr 17, 2024
1 parent 795c0c3 commit f692b70
Show file tree
Hide file tree
Showing 23 changed files with 666 additions and 349 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tests/**/actual
.vscode
*.swp
node_modules
docs/source/api_docs/generated/
21 changes: 7 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ repos:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/PyCQA/isort
rev: '5.12.0'
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: '22.10.0'
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: '5.0.4'
hooks:
- id: flake8
args:
- --show-source
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.21.0
hooks:
Expand All @@ -39,3 +25,10 @@ repos:
files: ^tests/examples/([^/]*)/dependencies.yaml$
args: ["--schemafile", "src/rapids_dependency_file_generator/schema.json"]
- id: check-github-workflows
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff
files: src/.*$
- id: ruff-format
files: src/.*$
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?= -n -v -W --keep-going
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
32 changes: 32 additions & 0 deletions docs/source/_templates/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:members:
:show-inheritance:
:inherited-members:

{% block methods %}
.. automethod:: __init__

{% if methods %}
.. rubric:: {{ _('Methods') }}

.. autosummary::
{% for item in methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
66 changes: 66 additions & 0 deletions docs/source/_templates/module.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{ fullname | escape | underline}}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes

.. autosummary::
:toctree:
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}

.. autosummary::
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. rubric:: {{ _('Classes') }}

.. autosummary::
:toctree:
:template: class.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. rubric:: {{ _('Exceptions') }}

.. autosummary::
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
:template: module.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
9 changes: 9 additions & 0 deletions docs/source/api_docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
API
===

.. autosummary::
:toctree: generated/
:template: module.rst
:recursive:

rapids_dependency_file_generator
63 changes: 63 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import datetime

from packaging.version import Version

import rapids_dependency_file_generator

DFG_VERSION = Version(rapids_dependency_file_generator.__version__)
project = "rapids-dependency-file-generator"
copyright = f"2022-{datetime.datetime.today().year}, NVIDIA Corporation"
author = "NVIDIA Corporation"
release = str(DFG_VERSION)

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"numpydoc",
]

templates_path = ["_templates"]
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "pydata_sphinx_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
# documentation.
#
html_theme_options = {
"external_links": [],
# https://github.com/pydata/pydata-sphinx-theme/issues/1220
"icon_links": [],
"github_url": "https://github.com/rapidsai/dependency-file-generator",
"twitter_url": "https://twitter.com/rapidsai",
"show_toc_level": 1,
"navbar_align": "right",
}

html_static_path = ["_static"]

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

autosummary_ignore_module_all = False

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
}
15 changes: 15 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Welcome to rapids-dependency-file-generator's documentation!
============================================================

.. toctree::
:maxdepth: 2
:caption: Contents:

api_docs/index

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
]

[project.scripts]
rapids-dependency-file-generator = "rapids_dependency_file_generator.cli:main"
rapids-dependency-file-generator = "rapids_dependency_file_generator._cli:main"

[tool.setuptools]
packages = { "find" = { where = ["src"] } }
Expand All @@ -36,3 +36,12 @@ version = {attr = "rapids_dependency_file_generator._version.__version__"}

[tool.isort]
profile = "black"

[tool.ruff]
line-length = 120

[tool.ruff.lint]
select = ["E", "F", "W", "I", "D"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
2 changes: 1 addition & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:
noarch: python
script: pip install --no-build-isolation --no-deps .
entry_points:
- rapids-dependency-file-generator = rapids_dependency_file_generator.cli:main
- rapids-dependency-file-generator = rapids_dependency_file_generator._cli:main

source:
path: ../
Expand Down
12 changes: 12 additions & 0 deletions src/rapids_dependency_file_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
"""Public API for rapids-dependency-file-generator.
This API can be used by Python build tools or other tools that want to
programmatically generate ``pyproject.toml``, ``requirements.txt``, or
a Conda environment from ``dependencies.yaml``.
"""

from . import _config, _rapids_dependency_file_generator
from ._config import * # noqa: F401,F403
from ._rapids_dependency_file_generator import * # noqa: F401,F403
from ._version import __version__

__all__ = [
"__version__",
*_config.__all__,
*_rapids_dependency_file_generator.__all__,
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import os
import warnings

from ._version import __version__ as version
from .config import Output, load_config_from_file
from .constants import default_dependency_file_path
from .rapids_dependency_file_generator import (
from ._config import Output, load_config_from_file
from ._constants import default_dependency_file_path
from ._rapids_dependency_file_generator import (
delete_existing_files,
make_dependency_files,
)
from ._version import __version__ as version


def validate_args(argv):
Expand Down Expand Up @@ -90,12 +90,8 @@ def validate_args(argv):

if args.file_key_deprecated:
if args.file_key:
raise ValueError(
"The --file_key (deprecated) and --file-key arguments cannot be specified together."
)
warnings.warn(
"The use of --file_key is deprecated. Use -f or --file-key instead."
)
raise ValueError("The --file_key (deprecated) and --file-key arguments cannot be specified together.")
warnings.warn("The use of --file_key is deprecated. Use -f or --file-key instead.")
args.file_key = args.file_key_deprecated

dependent_arg_keys = ["file_key", "output", "matrix"]
Expand All @@ -111,14 +107,10 @@ def validate_args(argv):
raise ValueError(
"The --prepend-channels (deprecated) and --prepend-channel arguments cannot be specified together."
)
warnings.warn(
"The use of --prepend-channels is deprecated. Use --prepend-channel instead."
)
warnings.warn("The use of --prepend-channels is deprecated. Use --prepend-channel instead.")
args.prepend_channels = args.prepend_channels_deprecated.split(";")
if args.prepend_channels and args.output and args.output != Output.CONDA.value:
raise ValueError(
f"--prepend-channel is only valid with --output {Output.CONDA.value}"
)
raise ValueError(f"--prepend-channel is only valid with --output {Output.CONDA.value}")

# If --clean was passed without arguments, default to cleaning from the root of the
# tree where the config file is.
Expand Down Expand Up @@ -156,6 +148,4 @@ def main(argv=None):
if args.clean:
delete_existing_files(args.clean)

make_dependency_files(
parsed_config, file_keys, output, matrix, args.prepend_channels, to_stdout
)
make_dependency_files(parsed_config, file_keys, output, matrix, args.prepend_channels, to_stdout)
Loading

0 comments on commit f692b70

Please sign in to comment.