Code Monkey home page Code Monkey logo

cg-stubs's Introduction

CG Stubs

Python stubs for VFX and Animation

These stubs are intended to be used with a type checker like mypy to provide static type checking of python code, as well as analysis and completion in IDEs like PyCharm and VSCode with Pylance.

Supported libraries and applications:

Note that pymel now has very excellent stubs included (more info here).

Installing

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

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.

Next, you'll need to check out a custom build of mypy (until my PR gets merged):

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. Requires python 3.7+:

cd cg-stubs
python3 -m venv .venv
. .venv/bin/activate
pip install -r nox-requirements.txt
nox -s 'generate(ocio)'

If this fails, here's a more foolproof approach:

# setup your env, e.g. setpkg python-3.7
unset PYTHONPATH
python3 -m venv .venv37
. .venv37/bin/activate
python3 -m pip install -r nox-requirements.txt
rm -rf .nox
python3 -m nox -s 'generate(ocio)'

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:

echo "/path/to/cg-stubs/ocio/stubs/" > /path/to/venv/lib/python3.7/site-packages/ocio.pth

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.

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

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

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)'

To publish to a custom registry:

poetry config repositories.pypi-nexus https://nexus.myorg/repository/pypi/
nox -s 'publish(ocio)' --  --repository pypi-nexus -u pypi -p 'whatever'

cg-stubs's People

Contributors

chadrik avatar nrusch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.