#-------------------------------------------------------------------------------
#  [1] Homebrew initialization:
#
#      The four packages 1) Qt6, 2) Ruby, 3) Python, and 4) libgit2 are required.
#      A typical installation flow is shown below.
#-------------------------------------------------------------------------------
   $ brew install qt@6
   $ brew install ruby@3.3
   $ brew install python@3.12
   $ brew install libgit2

#---------------------------------------------------------------------------------------------------
#  [2] Installation process of different Python modules using 'pip':
#
#    This DMG is built with Homebrew python@3.12, where we cannot use the legacy "pip3" command.
#    More precisely, we will get the following errors, if we attempt.
#      $ python3 -m pip install pandas scipy matplotlib XlsxWriter openpyxl
#      error: externally-managed-environment
#
#      × This environment is externally managed
#      ╰─> To install Python packages system-wide, try brew install
#          xyz, where xyz is the package you are trying to
#          install.
#
#          If you wish to install a Python library that isn't in Homebrew,
#          use a virtual environment:
#
#          python3 -m venv path/to/venv
#          source path/to/venv/bin/activate
#          python3 -m pip install xyz
#
#          If you wish to install a Python application that isn't in Homebrew,
#          it may be easiest to use 'pipx install xyz', which will manage a
#          virtual environment for you. You can install pipx with
#
#          brew install pipx
#
#          You may restore the old behavior of pip by passing
#          the '--break-system-packages' flag to pip, or by adding
#          'break-system-packages = true' to your pip.conf file. The latter
#          will permanently disable this error.
#
#          If you disable this error, we STRONGLY recommend that you additionally
#          pass the '--user' flag to pip, or set 'user = true' in your pip.conf
#          file. Failure to do this can result in a broken Homebrew installation.
#
#          Read more about this behavior here: <https://peps.python.org/pep-0668/>
#
#      note: If you believe this is a mistake, please contact your Python installation or OS
#      distribution provider.
#      You can override this, at the risk of breaking your Python installation or OS,
#      by passing --break-system-packages.
#      hint: See PEP 668 for the detailed specification.
#
#    To avoid this error, use a virtual environment as suggested above.
#---------------------------------------------------------------------------------------------------
$ which pip3
/usr/local/opt/python@3.12/bin/pip3

$ pip3 list
Package Version
------- -------
pip     24.2
wheel   0.44.0

$ python3 -m venv $HOME/opt/HBPy312

$ source $HOME/opt/HBPy312/bin/activate

(HBPy312) $ pip3 install pandas scipy matplotlib XlsxWriter openpyxl klayout

(HBPy312) $ pip3 list

Package         Version
--------------- -----------
contourpy       1.3.0
cycler          0.12.1
et-xmlfile      1.1.0
fonttools       4.53.1
kiwisolver      1.4.7
klayout         0.29.6
matplotlib      3.9.2
numpy           2.1.1
openpyxl        3.1.5
packaging       24.1
pandas          2.2.3
pillow          10.4.0
pip             24.2
pyparsing       3.1.4
python-dateutil 2.9.0.post0
pytz            2024.2
scipy           1.14.1
six             1.16.0
tzdata          2024.1
XlsxWriter      3.2.0

#-------------------------------------------------------------------------------
#  [3] Set the "KLAYOUT_PYTHONPATH" environment variable:
#      (Ref. https://www.klayout.de/forum/discussion/2557/)
#-------------------------------------------------------------------------------
The best approach is to create a script bundle (launching service Bash script),
as shown in "KLayoutHomebrew.app.Bash".

#-------------------------------------------------------------------------------
#  [4] Python module import test:
#
#      Run this sample python from "Macro Development" with such a sample CSV.
#-------------------------------------------------------------------------------
'''
# Enter your Python code here
import os
import numpy as np
import scipy
import matplotlib
import pandas as pd

sampleCSV = os.environ["HOME"] + "/KLayout/sampleCSV.csv"
df = pd.read_csv( sampleCSV, comment='#' )
print(df)
'''

== Output ==
      X[mm]  Y[mm]   Ratio[]
0       0.0    3.1  1.006617
1       2.7   -1.5  1.006607
2      -2.7   -1.5  1.006321
3       0.0    9.2  1.006651
4       5.9    7.0  1.006211
...     ...    ...       ...
1805  -30.3  140.7  0.994904
1806  -24.3  141.9  0.994266
1807  -18.3  142.8  0.994888
1808  -12.2  143.4  0.994146
1809   -6.1  143.8  0.993552

[1810 rows x 3 columns]

#------------------
# End of File
#------------------
