From 08ed33ef81aaa5a21e300fe6dfe268c3bb90f366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 22 Mar 2018 11:01:20 +0100 Subject: [PATCH] Written some documentation with Sphinx --- .gitignore | 2 + docs/Makefile | 20 +++++ docs/cli.rst | 85 +++++++++++++++++++++ docs/conf.py | 167 ++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 35 +++++++++ docs/installation.rst | 35 +++++++++ docs/license.rst | 49 +++++++++++++ docs/make.bat | 36 +++++++++ docs/packing.rst | 118 +++++++++++++++++++++++++++++ requirements-dev.txt | 5 ++ update_version.sh | 4 +- 11 files changed, 555 insertions(+), 1 deletion(-) create mode 100644 docs/Makefile create mode 100644 docs/cli.rst create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/installation.rst create mode 100644 docs/license.rst create mode 100644 docs/make.bat create mode 100644 docs/packing.rst diff --git a/.gitignore b/.gitignore index 6085592..b7abd0a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ __pycache__ /tests/blendfiles/cache_ocean/ /tests/blendfiles/T53562/blendcache_bam_pack_bug/ + +/docs/_build diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..4b3202b --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = BlenderAssetTracer +SOURCEDIR = . +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) \ No newline at end of file diff --git a/docs/cli.rst b/docs/cli.rst new file mode 100644 index 0000000..2f00347 --- /dev/null +++ b/docs/cli.rst @@ -0,0 +1,85 @@ +Commandline usage +================= + +After installation_, ``bat --help`` will show you general usage instructions. +The command structure is:: + + bat [common options] {subcommand} [subcommand-specific options] + +The common options are all optional:: + + -p, --profile Run the profiler, write to bam.prof + -v, --verbose Log INFO level and higher + -d, --debug Log everything + -q, --quiet Log at ERROR level and higher + +For most users only ``--verbose`` is useful, the other options can be very +helpful during development or debugging. + +Logging is sent to ``stderr``, whereas regular output is sent to ``stdout``. + +The available subcommands are described in the next sections. Each subcommand +also takes a ``--help`` argument to get specific usage instructions. + + +List +---- + +The ``bat list`` command lists the dependencies of a blend file. When there are +no dependencies, it outputs nothing. Example:: + + % bat list tests/blendfiles/doubly_linked.blend + tests/blendfiles/doubly_linked.blend + tests/blendfiles/linked_cube.blend + tests/blendfiles/material_textures.blend + tests/blendfiles/linked_cube.blend + tests/blendfiles/basic_file.blend + tests/blendfiles/material_textures.blend + tests/blendfiles/textures/Bricks/brick_dotted_04-bump.jpg + tests/blendfiles/textures/Bricks/brick_dotted_04-color.jpg + +By passing the ``--json`` option it outputs to JSON rather than plain text:: + + { + "/path/to/blender-asset-tracer/tests/blendfiles/material_textures.blend": [ + "/path/to/blender-asset-tracer/tests/blendfiles/textures/Bricks/brick_dotted_04-bump.jpg", + "/path/to/blender-asset-tracer/tests/blendfiles/textures/Bricks/brick_dotted_04-color.jpg" + ], + "/path/to/blender-asset-tracer/tests/blendfiles/linked_cube.blend": [ + "/path/to/blender-asset-tracer/tests/blendfiles/basic_file.blend" + ], + "/path/to/blender-asset-tracer/tests/blendfiles/doubly_linked.blend": [ + "/path/to/blender-asset-tracer/tests/blendfiles/linked_cube.blend", + "/path/to/blender-asset-tracer/tests/blendfiles/material_textures.blend" + ] + } + +Note that in this case all paths are absolute, whereas the regular output shows +paths relative to the current working directory. + + +Pack +---- + +The ``bat pack`` command takes the dependencies as shown by ``bat list`` and +copies them to a target. This target can be a directory, a ZIP file, or +S3-compatible storage:: + + bat pack [-h] [-p PROJECT] [-n] [-e [EXCLUDEs] blendfile target + +The optional arguments influence the manner of packing:: + + -p PROJECT, --project PROJECT + Root directory of your project. Paths to below this + directory are kept in the BAT Pack as well, whereas + references to assets from outside this directory will + have to be rewitten. The blend file MUST be inside the + project directory. If this option is ommitted, the + directory containing the blend file is taken as the + project directoy. + -n, --noop Don't copy files, just show what would be done. + -e [EXCLUDEs, --exclude [EXCLUDEs] + Space-separated list of glob patterns (like '*.abc') + to exclude. + +For more information see the chapter :ref:`packing`. diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..a47fa1a --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,167 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/stable/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'Blender Asset Tracer' +copyright = '2018, Sybren A. StΓΌvel' +author = 'Sybren A. StΓΌvel' + +# The short X.Y version +version = '0.2-dev' +# The full version, including alpha/beta/rc tags +release = '0.2-dev' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.doctest', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', +] + +# Add any paths that contain templates here, relative to this directory. +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' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path . +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +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' + +# 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 = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'BlenderAssetTracerdoc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # '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, 'BlenderAssetTracer.tex', 'Blender Asset Tracer Documentation', + 'Sybren A. StΓΌvel', '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, 'blenderassettracer', 'Blender Asset Tracer Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'BlenderAssetTracer', 'Blender Asset Tracer Documentation', + author, 'BlenderAssetTracer', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Extension configuration ------------------------------------------------- + +# -- Options for todo extension ---------------------------------------------- + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..26c8bb3 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,35 @@ +.. Blender Asset Tracer documentation master file, created by + sphinx-quickstart on Thu Mar 22 11:00:50 2018. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Blender Asset Tracer's documentation! +================================================ + +Blender Asset Tracer, a.k.a. BATπŸ¦‡, is the replacement of BAM_ and +blender-file_. BATπŸ¦‡ can be used to list all dependencies of a blend file, such +as linked blend files, textures, Alembic files, and caches. Furthermore, it can +be used to create a BAT Pack (see :ref:`packing`), which contains the blend file +and its dependencies. + + + +.. _BAM: https://developer.blender.org/diffusion/BAM/ +.. _blender-file: https://developer.blender.org/source/blender-file/ + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + installation + packing + cli + license + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..eb85a63 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,35 @@ +Installation +============ + +BATπŸ¦‡ can be installed with `pip`:: + + pip install blender-asset-tracer + + +Requirements and Dependencies +----------------------------- + +In order to run BAT you need Python 3.5; BAT always targets the Python version +used in the `latest Blender release`_. + +.. _`latest Blender release`: https://www.blender.org/download + +Apart from Python, BAT has very little external dependencies. When only working +with the local filesystem (which includes network shares; anything that your +computer can simply copy files to) it has no extra dependencies. Uploading to +S3-compatible storage requires the `boto3` library. + + +Development dependencies +------------------------ + +In order to start developing on BAT you need a bit more. First use Git_ to get a +copy of the source:: + + git clone https://gitlab.com/dr.sybren/blender-asset-tracer.git + virtualenv -p /path/to/python3 bat-venv + . ./bat-venv/bin/activate + cd blender-asset-tracer + pip3 install -U -r requirements-dev.txt + +.. _Git: https://git-scm.com/ diff --git a/docs/license.rst b/docs/license.rst new file mode 100644 index 0000000..e4670a4 --- /dev/null +++ b/docs/license.rst @@ -0,0 +1,49 @@ +Licence +======= + +This section describes the licenses for both the software and the documentation. + +Software +-------- + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +Documentation +------------- + +This documentation is covered by the `Creative Commons BY-SA 4.0 license`_. + +.. _`Creative Commons BY-SA 4.0 license`: https://creativecommons.org/licenses/by-sa/4.0/ + +This is a human-readable summary of (and not a substitute for) the license. +Disclaimer. You are free to: + + - Share β€” copy and redistribute the material in any medium or format + - Adapt β€” remix, transform, and build upon the material for any purpose, + even commercially. + +Under the following terms: + + - Attribution β€” You must give appropriate credit, provide a link to the + license, and indicate if changes were made. You may do so in any + reasonable manner, but not in any way that suggests the licensor endorses + you or your use. + + - ShareAlike β€” If you remix, transform, or build upon the material, you must + distribute your contributions under the same license as the original. + +No additional restrictions β€” You may not apply legal terms or technological +measures that legally restrict others from doing anything the license permits. diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..bb60a62 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=BlenderAssetTracer + +if "%1" == "" goto help + +%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.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/docs/packing.rst b/docs/packing.rst new file mode 100644 index 0000000..9474af7 --- /dev/null +++ b/docs/packing.rst @@ -0,0 +1,118 @@ +.. _packing: + +Packing +======= + +BAT can create BAT Packs. These packs take the form of a directory or a ZIP +file, and contain a blend file together with its dependencies, such as linked +blend files, textures, fonts, Alembic files, and caches. + +The blend file is inspected relative to a *project directory*. This allows BAT +to mimick the project structure as well as possible. For example, a typical +Blender Animation Studio project looks something like this:: + + /path/to/agent327 + β”œβ”€β”€ lib + β”‚Β Β  β”œβ”€β”€ chars + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent.blend + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ barber.blend + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ boris.blend + β”‚Β Β  β”œβ”€β”€ envs + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ barbershop_exterior.blend + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ barbershop_interior.blend + β”‚Β Β  β”‚Β Β  └── elevator_shaft.blend + β”‚Β Β  β”œβ”€β”€ maps + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lots-of-textures.png + β”‚Β Β  β”‚Β Β  └── lots-of-textures.jpg + β”‚Β Β  β”œβ”€β”€ nodes + β”‚Β Β  └── props + β”‚Β Β  └── shaving_cream_brush.blend + └── scenes + Β Β  β”œβ”€β”€ 01-opening + Β Β  β”‚Β Β  β”œβ”€β”€ 01_01_B-city_tilt + Β Β  β”‚Β Β  β”œβ”€β”€ 01_02_A-barbershop_ext + Β Β  β”‚Β Β  └── 01_04_B-watch + Β Β  └── 02-boris + Β Β  Β Β  └── 02_01_A-car_enter + +Of course this is a simplified view, but it serves the purpose of this +documentation. A BAT Pack for the Agent 327 model would include the +``agent.blend`` file and its textures from the ``maps`` folder. To create the +BAT Pack, use the following command:: + + cd /path/to/agent327 + bat pack -p . lib/chars/agent.blend /path/to/agent-pack + +This will create the ``/path/to/agent-pack`` directory and place the following +files there:: + /path/to/agent-pack + β”œβ”€β”€ lib + β”‚Β Β  β”œβ”€β”€ chars + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent.blend + β”‚Β Β  β”‚Β Β  └── maps + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_eyes_color.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_face_bruises_color.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_face_bump.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_face_color.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_face_spec.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_hair_mask_cut.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_hair_mask.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_hands_bump.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_hands_color.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_hands_spec.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_pattern_suit.jpg + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_shoes_color.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_shoes_leather.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_suit_bump.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_suit_color.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_suit_disp_bend.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_suit_disp_scratch.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ agent_suit_disp_stretch.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ barber_jacket_pattern.jpg + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pattern2_jacket_color.png + β”‚Β Β  β”‚Β Β  └── pattern2_jacket_normal.png + β”‚Β Β  β”œβ”€β”€ maps + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ barbershop_env_reflection.exr + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ brushes + β”‚Β Β  β”‚Β Β  β”‚Β Β  └── stitch_64.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ grunge_scratches_generic.png + β”‚Β Β  β”‚Β Β  β”œβ”€β”€ grunge_worn_drag_scratches.png-color.png + β”‚Β Β  β”‚Β Β  └── metal_painted02_spec_tileable.png-specular.png + β”‚Β Β  └── props + β”‚Β Β  └── maps + β”‚Β Β  └── fabric_leather_bright01_col_tileable.png + └── pack-info.txt + +The ``pack-info.txt`` file is created by BAT and describes that this is a BAT +Pack for ``lib/chars/agent.blend``. + + +Out-of-project files +-------------------- + +Any files that are linked from outside the project will be placed in a special +directory ``_outside_project`` in the BAT Pack. This causes file links to +change. Let's say you want to pack a blend file +``/home/you/project/file.blend``, which uses +``/home/you/pictures/backdrop.jpg``. This will create the following BAT Pack:: + + /path/to/agent-pack + β”œβ”€β”€ file.blend + β”œβ”€β”€ _outside_project + β”‚Β Β  └── home + β”‚Β Β  Β Β  └── you + β”‚Β Β  Β Β  └── pictures + β”‚Β Β  Β Β  └── backdrop.jpg + └── pack-info.txt + +The ``file.blend`` will be rewritten so that it refers to the ``backdrop.jpg`` +inside the BAT pack, using a relative path. In this sense, the BAT Pack is a +"portable" version of the blend file. + + +ZIP files +--------- + +BAT can pack to a ZIP file, simply by ending the target name with ``.zip``:: + + bat pack file.blend /path/to/packed-file.zip diff --git a/requirements-dev.txt b/requirements-dev.txt index 68e773f..c0794d8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,3 +5,8 @@ pytest pytest-cov radon # for the 'radon cc' command pyprof2calltree # for converting profiler output to KCacheGrind input + +# For documentation +sphinx +sphinx-autobuild +sphinx_rtd_theme diff --git a/update_version.sh b/update_version.sh index 90bb9cd..2d82d8f 100755 --- a/update_version.sh +++ b/update_version.sh @@ -6,10 +6,12 @@ if [ -z "$1" ]; then fi sed "s/version='[^']*'/version='$1'/" -i setup.py +sed "s/version = '[^']*'/version = '$1'/" -i docs/conf.py +sed "s/release = '[^']*'/release = '$1'/" -i docs/conf.py sed "s/__version__\s*=\s*'[^']*'/__version__ = '$1'/" -i blender_asset_tracer/__init__.py git diff echo echo "Don't forget to commit and tag:" -echo git commit -m \'Bumped version to $1\' setup.py blender_asset_tracer/__init__.py +echo git commit -m \'Bumped version to $1\' setup.py blender_asset_tracer/__init__.py docs/conf.py echo git tag -a v$1 -m \'Tagged version $1\'