Skip to content

Commit

Permalink
Improve build instructions in README
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrik committed Aug 9, 2023
1 parent 3388f39 commit 9166760
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ 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
```

## 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.

Expand All @@ -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+:
Expand All @@ -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:

Expand All @@ -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)'
Expand Down
4 changes: 2 additions & 2 deletions katana/stubgen_katana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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
export PATH=$KATANA_HOME:$PATH
export foundry_LICENSE='[email protected]:[email protected]'
# 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/
Expand Down
1 change: 0 additions & 1 deletion ocio/stubgen_ocio.sh
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
32 changes: 2 additions & 30 deletions substance_painter/stubgen_substancepainter.sh
Original file line number Diff line number Diff line change
@@ -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'])
Expand All @@ -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
Expand Down

0 comments on commit 9166760

Please sign in to comment.