From dda7eaaf94d56813f48570b277752318555301f6 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 13 Nov 2023 02:05:54 +1100 Subject: [PATCH] Refactor dependencies and their tests (#1686) * Refactor dependencies and their tests Tackles #. Supersede #. * setup.py * Remove false dependencies: virtualenv or sh * Add Cython, on behalf of p4a. Could be removed when p4a is updated. * Add sphinx for docs, pytest for tests, and kivy-ios for ios builds. * Flake8 fixes * android.yml * Stop installing Cython so setup.py can be tested. * Stop making installs editable. Unnecessary and deprecated by PEP. * Remove false dependencies: automake, and ssl hacks * Give job's names at the right level of abstraction. * ios.yml * Stop installing Cython so setup.py can be tested. * Stop making installs editable. Unnecessary and deprecated by PEP. * Remove false dependencies: cookiecutter and pbxproj * Specify [ios] so dependencies are correctly installed. * Give job's names at the right level of abstraction. * Dockerfile * Make Cython version match setup.py. * I don't understand Docker enough to know whether this runs setup.py, so I don't know if cython is required here or not. * tox.ini * Simplify by assuming py3 * Installation.rst * Move the pip install buildozer instruction into individual sections, so we can specify [ios] * Stop claiming Buildozer will work on earlier versions. setup.py explicitly rejects them. * Stop recommending to upgrade pip. If Buildozer needs a particular minimum version of pip, it should say so in setup.py. * Stop recommending to install Cython or virtualenv manually. * Minor copy-edits. * Reinstate automake install Rolling back to change to allow other changes to be merged while this one is resolved. * Add automake to Android installation instructions --- .github/workflows/android.yml | 18 ++++++---------- .github/workflows/ios.yml | 3 +-- .github/workflows/pypi-release.yml | 6 +++--- Dockerfile | 2 +- docs/source/installation.rst | 34 +++++++++++++++++------------- setup.py | 22 ++++++++++++++----- tox.ini | 9 +++----- 7 files changed, 51 insertions(+), 43 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 44475bd60..b4fa15d9b 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -3,7 +3,7 @@ on: [push, pull_request] env: PYTHONFORANDROID_PREREQUISITES_INSTALL_INTERACTIVE: 0 -name: Android +name: Android Integration jobs: Integration: strategy: @@ -20,8 +20,7 @@ jobs: - uses: actions/checkout@v4 - name: Setup environment run: | - pip install -e . - pip install Cython==0.29.36 + pip install . - run: buildozer --help - run: buildozer init - name: SDK, NDK and p4a download @@ -32,17 +31,14 @@ jobs: # Install OS specific dependencies - name: Install Linux dependencies if: matrix.os == 'ubuntu-latest' - run: sudo apt -y install automake - - name: Install macOS dependencies - if: matrix.os == 'macOS-latest' - run: | - brew install automake - sudo ln -sfn /usr/local/opt/openssl /usr/local/ssl - - name: buildozer android debug + # Required by some p4a recipes, but not + # installed by p4a on Linux. + run: sudo apt -y install automake + - name: Debug Build run: | touch main.py buildozer android debug - - name: buildozer android release (aab) + - name: Release Build (aab) run: | touch main.py export BUILDOZER_ALLOW_ORG_TEST_DOMAIN=1 diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index a9c7e97fc..01e6702bf 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -15,8 +15,7 @@ jobs: - uses: actions/checkout@v4 - name: Setup environment run: | - pip install -e . - pip install Cython==0.29.36 cookiecutter pbxproj + pip install .[ios] - name: Check buildozer installation run: | buildozer --help diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index a7dad04ab..5117551c6 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -10,12 +10,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.x - - name: Install dependencies + - name: Install build dependencies run: | - python -m pip install --upgrade setuptools wheel twine + python -m pip install --upgrade setuptools wheel twine build - name: Build run: | - python setup.py sdist bdist_wheel + python -m build twine check dist/* - name: Publish package if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') diff --git a/Dockerfile b/Dockerfile index 5132b4faf..8347e18d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,6 @@ WORKDIR ${WORK_DIR} COPY --chown=user:user . ${SRC_DIR} # installs buildozer and dependencies -RUN pip3 install --user --upgrade Cython==0.29.36 wheel pip virtualenv ${SRC_DIR} +RUN pip3 install --user --upgrade "Cython<3.0" wheel pip ${SRC_DIR} ENTRYPOINT ["buildozer"] diff --git a/docs/source/installation.rst b/docs/source/installation.rst index df03b9be2..2fb5b3a37 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -2,15 +2,12 @@ Installation ============ -Buildozer is tested on Python 3.8 and above but may work on -earlier versions, back to Python 3.3. -Depending the platform you want to target, you might need more tools installed. -Buildozer tries to give you hints or tries to install few things for +Depending the platform you want to target, you might need a few dependencies installed. +Buildozer tries to give you hints and tries to install few things for you, but it doesn't cover every situation. -First, install the buildozer project with:: +Buildozer is tested on Python 3.8 and above. - pip3 install --user --upgrade buildozer Targeting Android ----------------- @@ -18,19 +15,24 @@ Targeting Android Android on Ubuntu 20.04 and 22.04 (64bit) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -(expected to work as well in later version, but only regularly tested in the latest LTS) +(Buildozer is expected to work in later versions of Ubuntu, but it is only regularly tested on the latest LTS version +of Ubuntu.) :: sudo apt update - sudo apt install -y git zip unzip openjdk-17-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev - pip3 install --user --upgrade Cython==0.29.33 virtualenv # the --user should be removed if you do this in a venv + sudo apt install -y git zip unzip openjdk-17-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev automake # add the following line at the end of your ~/.bashrc file export PATH=$PATH:~/.local/bin/ If openjdk-17 is not compatible with other installed programs, for Buildozer the minimum compatible openjdk version is 11. +Then install the buildozer project with:: + + pip3 install --user --upgrade buildozer + + Android on Windows 10 or 11 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -40,6 +42,10 @@ These instructions were tested with WSL 1 and Ubuntu 18.04 LTS, and WSL2 with Ub After installing WSL and Ubuntu on your Windows machine, open Ubuntu, run the commands listed in the previous section, and restart your WSL terminal to enable the path change. +Install the buildozer project with:: + + pip3 install --user --upgrade buildozer + Copy your Kivy project directory from the Windows partition to the WSL partition, and follow the Quickstart Instructions. **Do not** change to the project directory on the Windows partition and build there, this may give unexpected and obscure fails. For debugging, WSL does not have direct access to USB. Copy the .apk file to the Windows partition and run ADB (Android Debug Bridge) from a Windows prompt. ADB is part of Android Studio, if you do not have this installed you can install just the platform tools which also contain ADB. @@ -51,7 +57,7 @@ For debugging, WSL does not have direct access to USB. Copy the .apk file to the Before Using Buildozer ~~~~~~~~~~~~~~~~~~~~~~ -If you wish, clone your code to a new folder, where the build process will run. +If you wish, clone your code to a new folder where the build process will run. You don't need to create a virtualenv for your code requirements. But just add these requirements to a configuration file called buildozer.spec as you will see in the following sections. @@ -62,7 +68,7 @@ Android on macOS :: - python3 -m pip install --user --upgrade Cython==0.29.33 virtualenv # the --user should be removed if you do this in a venv + python3 -m pip install --user --upgrade buildozer # the --user should be removed if you do this in a venv TroubleShooting @@ -97,16 +103,14 @@ Targeting IOS Install XCode and command line tools (through the AppStore) - Install homebrew (https://brew.sh) :: brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer autoconf automake - -Install pip and virtualenv +Install Buildozer and its ios dependencies :: - python3 -m pip install --user --upgrade pip virtualenv kivy-ios + python3 -m pip install --user --upgrade buildozer[ios] diff --git a/setup.py b/setup.py index 3f1489303..928d7a16a 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,6 @@ sys.exit(1) - def find_version(*file_paths): # Open in Latin-1 so that we avoid encoding errors. # Use codecs.open for Python 2 compatibility @@ -61,12 +60,26 @@ def find_version(*file_paths): license='MIT', packages=[ 'buildozer', 'buildozer.targets', 'buildozer.libs', 'buildozer.scripts' - ], + ], package_data={'buildozer': ['default.spec']}, include_package_data=True, - install_requires=['pexpect', 'virtualenv', 'sh'], + install_requires=[ + 'pexpect', + # Cython is required by both kivy-ios and python-for-android. + # However, python-for-android does not include it in its dependencies + # and kivy-ios's dependencies are not always checked, so it is included + # here. + # Restricted version because python-for-android's recipes can't handle + # later versions. + 'cython<3.0' + ], + extras_require={ + 'test': ['pytest'], + 'docs': ['sphinx'], + 'ios': ['kivy-ios'], + }, classifiers=[ - 'Development Status :: 5 - Production/Stable', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Topic :: Software Development :: Build Tools', 'Programming Language :: Python :: 3', @@ -74,7 +87,6 @@ def find_version(*file_paths): 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', - ], entry_points={ 'console_scripts': [ diff --git a/tox.ini b/tox.ini index 9a24f225e..00446fcf9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,12 @@ [tox] -envlist = pep8,py3 +envlist = pep8 [testenv] deps = pytest - py3: coverage -commands = pytest tests/ - -[testenv:py3] -# for py3 env we will get code coverage + coverage commands = + pytest tests/ coverage run --branch --source=buildozer -m pytest {posargs:tests/} coverage report -m