Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Query Google NotebookLM notebooks from Claude Code for source-grounded, citation-backed answers from Gemini.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/setup_environment.py
1#!/usr/bin/env python32"""3Environment Setup for NotebookLM Skill4Manages virtual environment and dependencies automatically5"""67import os8import sys9import subprocess10import venv11from pathlib import Path121314class SkillEnvironment:15"""Manages skill-specific virtual environment"""1617def __init__(self):18# Skill directory paths19self.skill_dir = Path(__file__).parent.parent20self.venv_dir = self.skill_dir / ".venv"21self.requirements_file = self.skill_dir / "requirements.txt"2223# Python executable in venv24if os.name == 'nt': # Windows25self.venv_python = self.venv_dir / "Scripts" / "python.exe"26self.venv_pip = self.venv_dir / "Scripts" / "pip.exe"27else: # Unix/Linux/Mac28self.venv_python = self.venv_dir / "bin" / "python"29self.venv_pip = self.venv_dir / "bin" / "pip"3031def ensure_venv(self) -> bool:32"""Ensure virtual environment exists and is set up"""3334# Check if we're already in the correct venv35if self.is_in_skill_venv():36print("โ Already running in skill virtual environment")37return True3839# Create venv if it doesn't exist40if not self.venv_dir.exists():41print(f"๐ง Creating virtual environment in {self.venv_dir.name}/")42try:43venv.create(self.venv_dir, with_pip=True)44print("โ Virtual environment created")45except Exception as e:46print(f"โ Failed to create venv: {e}")47return False4849# Install/update dependencies50if self.requirements_file.exists():51print("๐ฆ Installing dependencies...")52try:53# Upgrade pip first54subprocess.run(55[str(self.venv_pip), "install", "--upgrade", "pip"],56check=True,57capture_output=True,58text=True59)6061# Install requirements62result = subprocess.run(63[str(self.venv_pip), "install", "-r", str(self.requirements_file)],64check=True,65capture_output=True,66text=True67)68print("โ Dependencies installed")6970# Install Chrome for Patchright (not Chromium!)71# Using real Chrome ensures cross-platform reliability and consistent browser fingerprinting72# See: https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python#anti-detection73print("๐ Installing Google Chrome for Patchright...")74try:75subprocess.run(76[str(self.venv_python), "-m", "patchright", "install", "chrome"],77check=True,78capture_output=True,79text=True80)81print("โ Chrome installed")82except subprocess.CalledProcessError as e:83print(f"โ ๏ธ Warning: Failed to install Chrome: {e}")84print(" You may need to run manually: python -m patchright install chrome")85print(" Chrome is required (not Chromium) for reliability!")8687return True88except subprocess.CalledProcessError as e:89print(f"โ Failed to install dependencies: {e}")90print(f" Output: {e.output if hasattr(e, 'output') else 'No output'}")91return False92else:93print("โ ๏ธ No requirements.txt found, skipping dependency installation")94return True9596def is_in_skill_venv(self) -> bool:97"""Check if we're already running in the skill's venv"""98if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):99# We're in a venv, check if it's ours100venv_path = Path(sys.prefix)101return venv_path == self.venv_dir102return False103104def get_python_executable(self) -> str:105"""Get the correct Python executable to use"""106if self.venv_python.exists():107return str(self.venv_python)108return sys.executable109110def run_script(self, script_name: str, args: list = None) -> int:111"""Run a script with the virtual environment"""112script_path = self.skill_dir / "scripts" / script_name113114if not script_path.exists():115print(f"โ Script not found: {script_path}")116return 1117118# Ensure venv is set up119if not self.ensure_venv():120print("โ Failed to set up environment")121return 1122123# Build command124cmd = [str(self.venv_python), str(script_path)]125if args:126cmd.extend(args)127128print(f"๐ Running: {script_name} with venv Python")129130try:131# Run the script with venv Python132result = subprocess.run(cmd)133return result.returncode134except Exception as e:135print(f"โ Failed to run script: {e}")136return 1137138def activate_instructions(self) -> str:139"""Get instructions for manual activation"""140if os.name == 'nt':141activate = self.venv_dir / "Scripts" / "activate.bat"142return f"Run: {activate}"143else:144activate = self.venv_dir / "bin" / "activate"145return f"Run: source {activate}"146147148def main():149"""Main entry point for environment setup"""150import argparse151152parser = argparse.ArgumentParser(153description='Setup NotebookLM skill environment'154)155156parser.add_argument(157'--check',158action='store_true',159help='Check if environment is set up'160)161162parser.add_argument(163'--run',164help='Run a script with the venv (e.g., --run ask_question.py)'165)166167parser.add_argument(168'args',169nargs='*',170help='Arguments to pass to the script'171)172173args = parser.parse_args()174175env = SkillEnvironment()176177if args.check:178if env.venv_dir.exists():179print(f"โ Virtual environment exists: {env.venv_dir}")180print(f" Python: {env.get_python_executable()}")181print(f" To activate manually: {env.activate_instructions()}")182else:183print(f"โ No virtual environment found")184print(f" Run setup_environment.py to create it")185return186187if args.run:188# Run a script with venv189return env.run_script(args.run, args.args)190191# Default: ensure environment is set up192if env.ensure_venv():193print("\nโ Environment ready!")194print(f" Virtual env: {env.venv_dir}")195print(f" Python: {env.get_python_executable()}")196print(f"\nTo activate manually: {env.activate_instructions()}")197print(f"Or run scripts directly: python setup_environment.py --run script_name.py")198else:199print("\nโ Environment setup failed")200return 1201202203if __name__ == "__main__":204sys.exit(main() or 0)