Patent-Disclosure-Skill Environment Isolation Strategy: How It Keeps CadQuery Dependencies Separated

The patent-disclosure-skill project isolates its heavy CadQuery dependencies by creating a dedicated virtual environment in tools/cad-env and sanitizing all subprocess environments through the isolated_env() function.

The patent-disclosure-skill repository implements a robust environment isolation strategy for dependencies to prevent the heavyweight CadQuery CAD library from polluting the host Python installation. This approach ensures reproducible builds and eliminates conflicts between system packages and the specialized tooling required for patent disclosure workflows.

How the Isolation Works: Three Complementary Layers

The isolation strategy operates at multiple levels to guarantee clean, deterministic dependency resolution.

Clean Environment for Subprocesses

The isolated_env() function in cad_venv.py creates a pristine environment dictionary for all CAD-related subprocesses.

From skills/patent-disclosure/tools/cad_venv.py (lines 30-38), the function:

  • Strips all PIP_* environment variables to ignore user or system pip configuration
  • Removes PYTHONPATH, PYTHONHOME, and PYTHONUSERBASE to prevent host-site-packages leakage
  • Sets PYTHONNOUSERSITE=1 to disable user site-packages entirely
  • Enforces UTF-8 I/O via PYTHONUTF8=1 and PYTHONIOENCODING=utf-8

# Example: creating the isolated environment dict

from cad_venv import isolated_env

clean_env = isolated_env()

# clean_env now has no PIP_* vars, no PYTHONPATH, etc.

Isolated pip Invocations During Bootstrap

The virtual environment bootstrap process in bootstrap_cad_venv.py uses isolated pip invocations to guarantee clean package installation.

At lines 68-75, the code:

  • Passes the --isolated flag to pip, forcing it to ignore all user-wide and environment-wide configuration
  • Supplies an explicit --index-url (or mirror list) so resolution never falls back to locally-configured indexes

# Example: bootstrapping the CAD venv (simplified)

from bootstrap_cad_venv import bootstrap

# This will:

# 1. Probe the current status with cad_venv.status()

# 2. Find a supported Python interpreter (3.10-3.12)

# 3. Create a fresh venv if needed

# 4. Run pip in isolated mode with explicit mirrors

st = bootstrap(pypi_only=False, extra_index=["https://my.private/mirror"])
print(st)   # => {'ok': True, 'reason': 'ready', …}

Runtime Isolation in Pipeline Steps

The run_step_to_views.py module demonstrates consumption of the isolated environment during actual workflow execution.

At lines 22-23, each CAD-related step calls isolated_env() before launching subprocesses. This ensures that even later workflow stages do not inherit stray PYTHONPATH or PIP_ settings from the user's shell.


# Example: using the isolated env when invoking a CAD-related step

from run_step_to_views import some_step

# The step internally does:

# env = isolated_env()

# subprocess.run([...], env=env, …)

some_step(...)

Key Source Files and Their Responsibilities

File Purpose
skills/patent-disclosure/tools/cad_venv.py Defines isolated_env, utilities for locating the venv, and status reporting
skills/patent-disclosure/tools/bootstrap_cad_venv.py Creates the cad-env virtual environment and installs CadQuery using isolated pip
skills/patent-disclosure/tools/run_step_to_views.py Consumes the isolated environment during later pipeline steps

What This Isolation Strategy Guarantees

According to the patent-disclosure-skill source code, the three-layer approach ensures:

  1. CadQuery is confined to tools/cad-env — compatible with Python 3.10-3.12, never leaking into the global interpreter
  2. Deterministic pip index resolution — the bootstrap tries Chinese mirrors first, then official PyPI, never using user-defined pip.conf or --extra-index-url
  3. Sanitized subprocess inheritance — CAD parsing steps cannot accidentally import host-side libraries that might clash with the isolated CadQuery build

Summary

  • Dedicated virtual environment: All CadQuery dependencies live in tools/cad-env, separate from host Python
  • Aggressive environment sanitization: isolated_env() removes PIP_*, PYTHONPATH, PYTHONHOME, and PYTHONUSERBASE variables
  • Isolated pip bootstrap: --isolated flag plus explicit index URLs prevent configuration pollution
  • Runtime enforcement: Every CAD subprocess receives the sanitized environment via isolated_env()

Frequently Asked Questions

What Python versions does the patent-disclosure-skill environment support?

The bootstrap process probes for Python 3.10 through 3.12. This range is compatible with the CadQuery library's current requirements, ensuring the isolated environment uses a supported interpreter.

Why remove PYTHONPATH specifically during environment isolation?

PYTHONPATH allows users to inject arbitrary directories into Python's module search path. Removing it prevents the host's site-packages or development libraries from shadowing or conflicting with the clean packages installed inside tools/cad-env.

How does the isolated pip bootstrap handle network or index failures?

The bootstrap_cad_venv.py module implements a fallback strategy: it first attempts installation through a configurable list of mirrors (optimized for Chinese networks), then falls back to official PyPI. The explicit --index-url or --extra-index-url arguments ensure pip never consults user configuration that might specify unreachable or incorrect indexes.

Can I use patent-disclosure-skill's isolation strategy for other heavy dependencies?

Yes. The pattern in cad_venv.py is generic: create a dedicated venv path, define an isolated_env() function that scrubs environment variables, and invoke all related subprocesses with that cleaned environment. The same approach works for any dependency stack that conflicts with host packages.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →