From 9166760d3d8e5c3183db3440cece7f37886cf15e Mon Sep 17 00:00:00 2001 From: Chad Dombrova Date: Wed, 9 Aug 2023 11:08:50 -0700 Subject: [PATCH] Improve build instructions in README --- README.md | 44 ++++++++++++++++--- katana/stubgen_katana.sh | 4 +- ocio/stubgen_ocio.sh | 1 - substance_painter/stubgen_substancepainter.sh | 32 +------------- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 33b13ae..b15f297 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Note that [pymel](https://pypi.org/project/pymel/) now has very excellent stubs ## Installing -These are distributed as "stubs-only" python packages, so you can just pip install whichever packages you need: +These are distributed as "stubs-only" python packages, so you can just `pip install` whichever packages you need: ``` pip install types-usd types-houdini types-katana types-mari types-nuke types-opencolorio types-PySide2 types-substance_painter @@ -27,7 +27,9 @@ pip install types-usd types-houdini types-katana types-mari types-nuke types-ope ## Generating the stubs -(replace ocio with your desired package to generate) +You only need to do this if you your goal is to help improve the stubs. Otherwise, just use `pip`. + +In the instructions below, replace ocio with your desired package to generate. First, look at `ocio/stubgen_ocio.sh` to see if there are any env vars to set in the `# Custom variables` section. @@ -38,6 +40,7 @@ git clone https://github.com/LumaPictures/cg-stubs git clone https://github.com/chadrik/mypy cd mypy git checkout stubgen/shared-sig-gen-14 +cd .. ``` Next, build the stubs using [`nox`](https://nox.thea.codes/en/stable/index.html). Requires python 3.7+: @@ -62,8 +65,7 @@ rm -rf .nox python3 -m nox -s 'generate(ocio)' ``` - -## Developing +### Testing while Developing The easiest way to use the stubs while you're devleoping them is to create an editable install. Simply create a `.pth` file in the site-packages directory of the venv where your other deps live: @@ -73,11 +75,39 @@ echo "/path/to/cg-stubs/ocio/stubs/" > /path/to/venv/lib/python3.7/site-packages The name of the .pth file does not matter. Note that if you're using the mypy daemon, be sure to run `dmypy stop` to reread freshly modified stubs. -## Publishing to PyPI +### Generating the USD stubs + +The USD stubs currently require you to build a special fork of USD, until the necessary changes are merged. + +``` +git clone https://github.com/chadrik/USD +git checkout doc-stubs2 +python3 -m venv .venv +.venv/bin/activate +pip install PySide6 PyOpenGL +python3 build_scripts/build_usd.py --python-docs --docs .build +``` + +Then update the variables in `stubgen_usd.sh` and generate as normal. + +### Generating the Substance Painter stubs -To publish to pypi.org, first run the nox installation steps from the Generating section, then: +These must be generated from within the UI, because I could not figure out how to run a standlone interpreter. + +``` +import mypy.stubgen;mypy.stubgen.main(['-p', '_substance_painter']) +``` + +Then generate as normal to cleanup the stubs. + +### Generating the Houdini stubs + +The Houdini stubs currently use a completely different approach to building which will eventually be ported to nox. So this may be unapproachable for most users for now. + + +## Publishing to PyPI -(replace ocio with the package to publish) +To publish to pypi.org, first run the nox installation steps from the Generating section, then run the `publish` task (replacing ocio with the package to publish): ``` nox -s 'publish(ocio)' diff --git a/katana/stubgen_katana.sh b/katana/stubgen_katana.sh index d199b2d..01669aa 100755 --- a/katana/stubgen_katana.sh +++ b/katana/stubgen_katana.sh @@ -8,6 +8,8 @@ if [[ "$version" == "" ]]; then echo "defaulting to $version" fi +export REPO_PATH=$(git rev-parse --show-toplevel) + # Custom variables -- MYPY_ROOT=$REPO_PATH/../mypy export KATANA_HOME=/luma/soft/applications/Foundry/Linux-x86_64/katana/Katana-$version @@ -15,8 +17,6 @@ export PATH=$KATANA_HOME:$PATH export foundry_LICENSE='4101@katanalicgui.luma.ninja:5053@katanarender.luma.ninja' # End custom variables -- -PY_SITE_DIR=$(python -c "import site,os;print(os.pathsep.join(site.getsitepackages()))") -export REPO_PATH=$(git rev-parse --show-toplevel) export PYTHONPATH=$REPO_PATH:$REPO_PATH/katana:$MYPY_ROOT:$PY_SITE_DIR sitedir=$KATANA_HOME/bin/python/ diff --git a/ocio/stubgen_ocio.sh b/ocio/stubgen_ocio.sh index 08723ee..e5f6656 100755 --- a/ocio/stubgen_ocio.sh +++ b/ocio/stubgen_ocio.sh @@ -1,6 +1,5 @@ #!/bin/bash -echo $(which python) PY_SITE_DIR=$(python -c "import site,os;print(os.pathsep.join(site.getsitepackages()))") REPO_PATH=$(git rev-parse --show-toplevel) outdir=$REPO_PATH/ocio/stubs/ diff --git a/substance_painter/stubgen_substancepainter.sh b/substance_painter/stubgen_substancepainter.sh index ee8e2f0..1f93c7e 100755 --- a/substance_painter/stubgen_substancepainter.sh +++ b/substance_painter/stubgen_substancepainter.sh @@ -1,15 +1,9 @@ #!/bin/bash -# set -e -version=$1 - -# . .venv-py37-linux/bin/activate - -#setpkg -c substancepainter-$version - -outdir=$REPO_PATH/substancepainter/stubs/ +REPO_PATH=$(git rev-parse --show-toplevel) +outdir=$REPO_PATH/substance_painter/stubs/ # this must be run inside the GUI # import mypy.stubgen;mypy.stubgen.main(['-p', '_substance_painter']) @@ -21,28 +15,6 @@ outdir=$REPO_PATH/substancepainter/stubs/ sed -i 's/\b_Number\b/Union[int, float]/g' $outdir/substance_painter/event.pyi sed -i 's/from _typeshed import Incomplete/from typing import Union/g' $outdir/substance_painter/event.pyi -# I hate bash. this doesn't work. rewrite in python -#replace=$(cat <<- EOM -#typing.Union[ -# bool, -# int, -# typing.Tuple[int, int], -# typing.Tuple[int, int, int], -# typing.Tuple[int, int, int, int], -# float, -# typing.Tuple[float, float], -# typing.Tuple[float, float, float], -# typing.Tuple[float, float, float,float], -# str -#] -#EOM -# -#) -# -#echo "$replace" -#sed -i -E "s/PropertyValue[:] Incomplete/${replace//$'\n'/\\n}/g" $outdir/substance_painter/properties.pyi - - files="$outdir/substance_painter/*.pyi" for file in $files do