From 99bc8138d4e26062ed738b19b066ab1ad008a9f4 Mon Sep 17 00:00:00 2001 From: TunaLobster Date: Fri, 13 Oct 2023 11:26:18 -0500 Subject: [PATCH 1/5] Setup: Add venv for Ubuntu Lunar --- Sphinxsetup.sh | 26 ++++++++++++++++++++------ update.sh | 5 +++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Sphinxsetup.sh b/Sphinxsetup.sh index fc68368440..4425bb4b6b 100755 --- a/Sphinxsetup.sh +++ b/Sphinxsetup.sh @@ -10,11 +10,21 @@ fi DISTRIBUTION_ID=$(lsb_release -i -s) if [ ${DISTRIBUTION_ID} = 'Ubuntu' ]; then DISTRIBUTION_CODENAME=$(lsb_release -c -s) - if [ ${DISTRIBUTION_CODENAME} = 'focal' ] || [ ${DISTRIBUTION_CODENAME} = 'bionic' ]; then - sudo add-apt-repository universe + if [ ${DISTRIBUTION_CODENAME} = 'focal' ] || [ ${DISTRIBUTION_CODENAME} = 'bionic' ] || [ ${DISTRIBUTION_CODENAME} = 'lunar' ]; then + sudo add-apt-repository universe -y fi fi +# create a Python venv on more recent releases: +if [ ${DISTRIBUTION_CODENAME} == 'lunar' ]; then + sudo apt install python3.11-venv + python3 -m venv $HOME/venv-ardupilot-wiki --upgrade-deps + + # activate it: + SOURCE_LINE="source $HOME/venv-ardupilot-wiki/bin/activate" + $SOURCE_LINE +fi + sudo apt-get -y update sudo apt-get install -y unzip git imagemagick curl wget make python3 @@ -38,12 +48,16 @@ if [ "$(python --version)" == "Python 3.6.9" ]; then GET_PIP_URL="https://bootstrap.pypa.io/pip/3.6/get-pip.py" fi -curl "$GET_PIP_URL" -o get-pip.py -python3 get-pip.py -rm -f get-pip.py +PIP_USER_ARGUMENT="" +if [ ${DISTRIBUTION_CODENAME} != 'noble' ]; then + curl "$GET_PIP_URL" -o get-pip.py + python3 get-pip.py + rm -f get-pip.py + PIP_USER_ARGUMENT="--user" +fi # Install required python packages -python3 -m pip install --user --upgrade -r requirements.txt +python3 -m pip install $PIP_USER_ARGUMENT --upgrade -r requirements.txt # Reset the value of DISPLAY if grep -qi -E '(Microsoft|WSL)' /proc/version; then diff --git a/update.sh b/update.sh index 0f119c0a2f..c5483dc6e5 100755 --- a/update.sh +++ b/update.sh @@ -31,6 +31,11 @@ lock_file build.lck || { echo "$(date +%s) already locked" >>build.lck.log exit 1 } +# activate Python venv on more recent releases: +if [ ${DISTRIBUTION_CODENAME} == 'lunar' ]; then + SOURCE_LINE="source $HOME/venv-ardupilot-wiki/bin/activate" + $SOURCE_LINE +fi test -n "$FORCEBUILD" || { (cd ardupilot_wiki && git fetch > /dev/null 2>&1) From 6cf809a8b91d93949d29cfa527261eba75e3fd2e Mon Sep 17 00:00:00 2001 From: TunaLobster Date: Fri, 1 Mar 2024 17:06:24 -0600 Subject: [PATCH 2/5] Setup: Update for Ubuntu Noble with venv --- Sphinxsetup.sh | 12 ++++++------ update.sh | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sphinxsetup.sh b/Sphinxsetup.sh index 4425bb4b6b..ffbd039eca 100755 --- a/Sphinxsetup.sh +++ b/Sphinxsetup.sh @@ -10,14 +10,17 @@ fi DISTRIBUTION_ID=$(lsb_release -i -s) if [ ${DISTRIBUTION_ID} = 'Ubuntu' ]; then DISTRIBUTION_CODENAME=$(lsb_release -c -s) - if [ ${DISTRIBUTION_CODENAME} = 'focal' ] || [ ${DISTRIBUTION_CODENAME} = 'bionic' ] || [ ${DISTRIBUTION_CODENAME} = 'lunar' ]; then + if [ ${DISTRIBUTION_CODENAME} = 'focal' ] || [ ${DISTRIBUTION_CODENAME} = 'bionic' ] || [ ${DISTRIBUTION_CODENAME} = 'noble' ]; then sudo add-apt-repository universe -y fi fi +sudo apt-get -y update +sudo apt-get install -y unzip git imagemagick curl wget make python3 + # create a Python venv on more recent releases: -if [ ${DISTRIBUTION_CODENAME} == 'lunar' ]; then - sudo apt install python3.11-venv +if [ ${DISTRIBUTION_CODENAME} = 'noble' ]; then + sudo apt install python3-venv python3 -m venv $HOME/venv-ardupilot-wiki --upgrade-deps # activate it: @@ -25,9 +28,6 @@ if [ ${DISTRIBUTION_CODENAME} == 'lunar' ]; then $SOURCE_LINE fi -sudo apt-get -y update -sudo apt-get install -y unzip git imagemagick curl wget make python3 - # Install packages release specific if [ ${DISTRIBUTION_CODENAME} = 'bionic' ]; then sudo apt-get install -y python3-distutils diff --git a/update.sh b/update.sh index c5483dc6e5..5191950412 100755 --- a/update.sh +++ b/update.sh @@ -32,7 +32,7 @@ lock_file build.lck || { exit 1 } # activate Python venv on more recent releases: -if [ ${DISTRIBUTION_CODENAME} == 'lunar' ]; then +if [ ${DISTRIBUTION_CODENAME} == 'noble' ]; then SOURCE_LINE="source $HOME/venv-ardupilot-wiki/bin/activate" $SOURCE_LINE fi From 8a2b21feaf5f70b8c3a2f5e98beb4e02ce176b54 Mon Sep 17 00:00:00 2001 From: TunaLobster Date: Fri, 27 Sep 2024 17:51:47 -0500 Subject: [PATCH 3/5] Setup: Don't add Ubuntu universe on noble --- Sphinxsetup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sphinxsetup.sh b/Sphinxsetup.sh index ffbd039eca..4458a773bf 100755 --- a/Sphinxsetup.sh +++ b/Sphinxsetup.sh @@ -10,7 +10,7 @@ fi DISTRIBUTION_ID=$(lsb_release -i -s) if [ ${DISTRIBUTION_ID} = 'Ubuntu' ]; then DISTRIBUTION_CODENAME=$(lsb_release -c -s) - if [ ${DISTRIBUTION_CODENAME} = 'focal' ] || [ ${DISTRIBUTION_CODENAME} = 'bionic' ] || [ ${DISTRIBUTION_CODENAME} = 'noble' ]; then + if [ ${DISTRIBUTION_CODENAME} = 'focal' ] || [ ${DISTRIBUTION_CODENAME} = 'bionic' ]; then sudo add-apt-repository universe -y fi fi From 3e70392db0dbdf3c36dd62245cf7e90590ea44e3 Mon Sep 17 00:00:00 2001 From: TunaLobster Date: Fri, 27 Sep 2024 17:54:24 -0500 Subject: [PATCH 4/5] update.py: Add checks for Python 3.11 not having distutils and pkg_resources --- update.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/update.py b/update.py index 08443e95d5..a077e3fbef 100755 --- a/update.py +++ b/update.py @@ -31,7 +31,6 @@ from __future__ import print_function, unicode_literals import argparse -import distutils import errno import filecmp import json @@ -51,17 +50,25 @@ from concurrent.futures import ThreadPoolExecutor from typing import Optional, Dict, List +if sys.version_info <= (3,11): + import distutils -from sphinx.application import Sphinx -import rst_table +try: + from sphinx.application import Sphinx +except ModuleNotFoundError as e: + print("Please make sure that you have run the SphinxSetup script for your system and that you have activated the arudpilot-wiki-venv if it was created on your system") + print(e) + sys.exit(1) from codecs import open from datetime import datetime # while flake8 says this is unused, distutils.dir_util.mkpath fails # without the following import on old versions of Python: -from distutils import dir_util # noqa: F401 +if sys.version_info <= (3, 11): + from distutils import dir_util # noqa: F401 from frontend.scripts import get_discourse_posts +import rst_table if sys.version_info < (3, 8): print("Minimum python version is 3.8") @@ -771,7 +778,11 @@ def copy_static_html_sites(site, destdir): def check_imports(): '''check key imports work''' - import pkg_resources + try: + import pkg_resources + except ModuleNotFoundError: + debug("Unable to check imports using pkg_resources") + return # package names to check the versions of. Note that these can be different than the string used to import the package requires = ["sphinx_rtd_theme>=1.3.0", "sphinxcontrib.youtube>=1.2.0", "sphinx>=7.1.2", "docutils<0.19"] for r in requires: From f60d96d24a4b49d7096c39114dd10088b21d06b9 Mon Sep 17 00:00:00 2001 From: TunaLobster Date: Fri, 27 Sep 2024 18:29:39 -0500 Subject: [PATCH 5/5] Update.py: Replace distutils with os.makedirs and fix flake8 warnings --- update.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/update.py b/update.py index a077e3fbef..c956c20313 100755 --- a/update.py +++ b/update.py @@ -50,26 +50,20 @@ from concurrent.futures import ThreadPoolExecutor from typing import Optional, Dict, List -if sys.version_info <= (3,11): - import distutils +from frontend.scripts import get_discourse_posts +import rst_table + +from codecs import open +from datetime import datetime try: - from sphinx.application import Sphinx + from sphinx.application import Sphinx # noqa: F401 except ModuleNotFoundError as e: - print("Please make sure that you have run the SphinxSetup script for your system and that you have activated the arudpilot-wiki-venv if it was created on your system") + print("Please make sure that you have run the SphinxSetup script for your system and that you have activated the", + "arudpilot-wiki-venv if it was created on your system") print(e) sys.exit(1) -from codecs import open -from datetime import datetime -# while flake8 says this is unused, distutils.dir_util.mkpath fails -# without the following import on old versions of Python: -if sys.version_info <= (3, 11): - from distutils import dir_util # noqa: F401 - -from frontend.scripts import get_discourse_posts -import rst_table - if sys.version_info < (3, 8): print("Minimum python version is 3.8") sys.exit(1) @@ -372,14 +366,14 @@ def make_backup(site, destdir, backupdestdir): debug('Backing up: %s' % wiki) targetdir = os.path.join(destdir, wiki) - distutils.dir_util.mkpath(targetdir) + os.makedirs(targetdir, exist_ok=True) if not os.path.exists(targetdir): fatal("FAIL backup when looking for folder %s" % targetdir) bkdir = os.path.join(backupdestdir, str(building_time + '-wiki-bkp'), str(wiki)) debug('Checking %s' % bkdir) - distutils.dir_util.mkpath(bkdir) + os.makedirs(bkdir, exist_ok=True) debug('Copying %s into %s' % (targetdir, bkdir)) try: subprocess.check_call(["rsync", "-a", "--delete", targetdir + "/", bkdir])