From a1bf7b49d1ad1f6799e0ed98428e87d3cec52c7a Mon Sep 17 00:00:00 2001 From: Levi Vande Kamp Date: Fri, 15 Apr 2022 12:49:20 -0500 Subject: [PATCH] Updated readme and build script --- README.md | 66 +++++++++++++++++++++++++++++- pyinstaller_build/build.sh | 13 +++--- pyinstaller_build/how_to_build.txt | 59 -------------------------- pyinstaller_build/test.sh | 12 +++++- 4 files changed, 83 insertions(+), 67 deletions(-) delete mode 100644 pyinstaller_build/how_to_build.txt diff --git a/README.md b/README.md index 13e9396..09ab6c1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A Python 3 interface for code by Cristian Ioan Vasile from http See the original readme, pyTWTL-readme.txt, for information on pyTWTL. This package can be installed directly from GitHub: -``` +```bash pip install git+https://github.com/levivk/pyTWTL-python3@master ``` ## Usage @@ -17,3 +17,67 @@ alphabet = out['alphabet'] # The alphabet set dfa_normal = out['normal'] # The normal dfa dfa_relaxed = out['infinity'] # The relaxed dfa ``` + +## How to build + +If you want to use this on a different architecture or otherwise run into problems that requires rebundling the Python 2 code, below is how you do that. + +### Ubuntu + +This method runs a Ubuntu 18.04 docker container and runs pyinstaller there. No need to install Python 2. + +```bash +# install git, and docker +sudo apt install git docker.io -y + +# clone this repository +git clone https://github.com/levivk/pyTWTL-python3 +cd pyTWTL-python3/pyinstaller_build + +# run the build script +./build.sh + +# run the test +./test.sh + +# You should get a few hundred lines of yaml output and no errors +``` + +### MacOS + +Tested on macOS Catalina Version 10.15.7 and Monterey Version 12.3 + +```bash +# install homebrew https://brew.sh/ +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + +# install pyenv +brew install pyenv +echo 'eval "$(pyenv init --path)"' >> ~/.zprofile +echo 'eval "$(pyenv init -)"' >> ~/.zshrc + +# Now close your shell and reopen it + +# install python 2.7 with dev libraries +env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 2.7.18 +pyenv global 2.7.18 + +# clone this repository +git clone https://github.com/levivk/pyTWTL-python3 +cd pyTWTL-python3/pyinstaller_build + +# install dependencies +pip install -r requirements.txt + +# run the build script +bash build.sh + +# run the test +bash test.sh + +# You should get a few hundred lines of yaml output and no errors + +# Uninstall python 2.7 +pyenv global system +pyenv uninstall 2.7.18 +``` diff --git a/pyinstaller_build/build.sh b/pyinstaller_build/build.sh index 82cfbfd..372407a 100755 --- a/pyinstaller_build/build.sh +++ b/pyinstaller_build/build.sh @@ -3,14 +3,15 @@ # cd to script dir cd $(dirname $0) -# copy to respective folder if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Use docker to run in Ubuntu 18.04 - docker build -t pytwtl . - docker create --name pytwtl-cont pytwtl + sudo docker build -t pytwtl . + sudo docker create --name pytwtl-cont pytwtl rm -rf ../pyTWTL/bin-linux/* - docker cp pytwtl-cont:/b/dist/twtl_translate/. ../pyTWTL/bin-linux/ - docker rm pytwtl-cont + sudo docker cp pytwtl-cont:/b/dist/twtl_translate/. ../pyTWTL/bin-linux/ + sudo docker rm pytwtl-cont + # change ownership + sudo chown $(whoami):$(id -gn) -R ../pyTWTL/bin-linux/* elif [[ "$OSTYPE" == "darwin"* ]]; then # remove dist and run pyinstaller @@ -18,7 +19,7 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then pyinstaller twtl_translate.spec # Copy to folder rm -rf ../pyTWTL/bin-darwin/* - cp -ra dist/twtl_translate/. ../pyTWTL/bin-darwin/ + cp -ra dist/twtl_translate/. ../pyTWTL/bin-darwin/ else echo "Unsupported OS type:" "$OSTYPE" fi diff --git a/pyinstaller_build/how_to_build.txt b/pyinstaller_build/how_to_build.txt deleted file mode 100644 index 62a2824..0000000 --- a/pyinstaller_build/how_to_build.txt +++ /dev/null @@ -1,59 +0,0 @@ -Ubuntu 20.04 - -# install git, curl, binutils, and python 2.7 -sudo apt install git curl binutils python2-dev -y - -# install pip -curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python2 - -# clone this repository -git clone https://github.com/levivk/pyTWTL-python3 -cd pyTWTL-python3/pyinstaller_build - -# install the requirements -python2 -m pip install -r requirements.txt -export PATH=$PATH:/home/$USER/.local/bin - -# run the build script -bash build.sh - -# run the test -bash test.sh - -# You should get a few hundred lines of yaml output and no errors - -# Uninstall python 2.7 -sudo apt purge python2 -y -sudo apt autoremove -y - -Mac OS (macOS Catalina Version 10.15.7 and Monterey Version 12.3) - -# install homebrew https://brew.sh/ - -/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - -# install pyenv -brew install pyenv -echo 'eval "$(pyenv init --path)"' >> ~/.zprofile -echo 'eval "$(pyenv init -)"' >> ~/.zshrc - -# Now close your shell and reopen it - -# install python 2.7 with dev libraries -env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 2.7.18 -pyenv global 2.7.18 - -# install dependencies -pip install -r requirements.txt - -# run the build script -bash build.sh - -# run the test -bash test.sh - -# You should get a few hundred lines of yaml output and no errors - -# Uninstall python 2.7 -pyenv global system -pyenv uninstall 2.7.18 diff --git a/pyinstaller_build/test.sh b/pyinstaller_build/test.sh index 44e4a42..4790d5a 100755 --- a/pyinstaller_build/test.sh +++ b/pyinstaller_build/test.sh @@ -1,3 +1,13 @@ #! /bin/bash cd $(dirname $0) -./dist/twtl_translate/twtl_translate "[H^1 r2]^[0,10]" --kind=both + +# cd to script dir +cd $(dirname $0) + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + ../pyTWTL/bin-linux/twtl_translate "[H^1 r2]^[0,10]" --kind=both +elif [[ "$OSTYPE" == "darwin"* ]]; then + ../pyTWTL/bin-darwin/twtl_translate "[H^1 r2]^[0,10]" --kind=both +else + echo "Unsupported OS type:" "$OSTYPE" +fi