|
42 | 42 | } |
43 | 43 | ], |
44 | 44 | "source": [ |
45 | | - "# package version printout, pip install with extras, random seed, and environment info.\n", |
46 | | - "\n", |
47 | | - "import sys\n", |
| 45 | + "# Package version, random seed, and environment info\n", |
48 | 46 | "import platform\n", |
49 | | - "print(f\"Python version: {sys.version}\")\n", |
50 | | - "print(f\"Platform: {sys.platform}\")\n", |
51 | | - "print(f\"System: {platform.system()} {platform.release()}\")\n", |
| 47 | + "import sys\n", |
| 48 | + "import logging\n", |
| 49 | + "import numpy as np\n", |
| 50 | + "\n", |
| 51 | + "# Setup logging (works in notebooks and scripts)\n", |
| 52 | + "for handler in logging.root.handlers[:]:\n", |
| 53 | + " logging.root.removeHandler(handler)\n", |
| 54 | + "\n", |
| 55 | + "logging.basicConfig(\n", |
| 56 | + " level=logging.INFO,\n", |
| 57 | + " format=\"%(asctime)s - %(levelname)s - %(message)s\"\n", |
| 58 | + ")\n", |
| 59 | + "\n", |
| 60 | + "# System info\n", |
| 61 | + "logging.info(f\"Python Version: {sys.version}\")\n", |
| 62 | + "logging.info(f\"Platform: {sys.platform}\")\n", |
| 63 | + "logging.info(f\"System: {platform.system()} {platform.release()}\")\n", |
| 64 | + "logging.info(f\"Architecture: {platform.architecture()}\")\n", |
52 | 65 | "\n", |
| 66 | + "# Import PyGeM\n", |
53 | 67 | "try:\n", |
54 | 68 | " import pygem\n", |
55 | | - " print(f\"PyGeM version: {pygem.__version__}\")\n", |
56 | 69 | "except ImportError:\n", |
57 | | - " print(\"PyGeM not found. Installing with tutorial dependencies\")\n", |
58 | | - " import subprocess\n", |
59 | | - " subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".[tut]\"])\n", |
60 | | - " import pygem\n", |
61 | | - " print(f\"PyGeM version: {pygem.__version__}\")\n", |
| 70 | + " raise ImportError(\n", |
| 71 | + " \"PyGeM not found. Please install it before running this tutorial.\\n\"\n", |
| 72 | + " \"For example, run: pip install -e '.[tut]' in your environment.\"\n", |
| 73 | + " )\n", |
62 | 74 | "\n", |
63 | | - "import numpy as np\n", |
64 | | - "np.random.seed(42)\n", |
| 75 | + "logging.info(f\"PyGeM version: {pygem.__version__}\")\n", |
65 | 76 | "\n", |
| 77 | + "# Set random seed\n", |
| 78 | + "np.random.seed(42)\n", |
| 79 | + "logging.info(\"Random seed set to 42\")\n", |
66 | 80 | "\n", |
| 81 | + "# Setup matplotlib for notebooks\n", |
67 | 82 | "try:\n", |
68 | 83 | " get_ipython().run_line_magic('matplotlib', 'inline')\n", |
69 | 84 | "except NameError:\n", |
70 | | - " # Running as .py script, no magic commands needed\n", |
71 | | - " pass\n", |
| 85 | + " pass # Running as .py script\n", |
| 86 | + "\n", |
72 | 87 | "import mpl_toolkits.mplot3d\n", |
73 | 88 | "import matplotlib.pyplot as plt\n", |
74 | 89 | "\n", |
75 | | - "import pygem\n", |
76 | | - "\n", |
77 | | - "print(pygem.__version__)\n", |
78 | 90 | "from pygem import FFD" |
79 | 91 | ] |
80 | 92 | }, |
|
0 commit comments