codinn / applaud

Python client library for App Store Connect API.
MIT License
23 stars 5 forks source link

Not able to install Applaud with pip3 in Xcode Cloud #1

Closed abbeycode closed 2 years ago

abbeycode commented 2 years ago

Hi! I want to interact with App Store Connect from my Xcode Cloud builds, and wrote a script using Applaud to do so. I can't successfully get Applaud installed there, though. Here's what I have:

ci_scripts/ci_pre_xcodebuild.sh

#!/bin/zsh

# This script gets run automatically by Xcode Cloud before xcodebuild is invoked. It calls the Python script

export PATH="/Users/local/Library/Python/3.8/bin:$PATH"

echo "Installing Python dependencies"
pip3 install applaud --user
pip3 install requests --user

echo "Running Python script…"
./my_script.py

my_script.py

#!/usr/bin/env python3

import requests

from applaud.connection import Connection
from applaud.schemas.requests import *
from applaud.schemas.responses import AppScreenshotSetsResponse

When running pip3 install applaud --user I get these errors (full output further below):

ERROR: Could not find a version that satisfies the requirement applaud (from versions: none) ERROR: No matching distribution found for applaud

Installing Requests works fine (pip3 install requests --user).

Full output

source /Volumes/Task/ci_build.env && source /Volumes/Task/ci_plan.env && cd /Volumes/workspace/repository/ci_scripts && bash /Volumes/workspace/repository/ci_scripts/ci_pre_xcodebuild.sh
Installing Python dependencies
ERROR: Could not find a version that satisfies the requirement applaud (from versions: none)
ERROR: No matching distribution found for applaud
WARNING: You are using pip version 20.2.3; however, version 22.0.4 is available.
You should consider upgrading via the '/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip' command.
Collecting requests
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
Collecting idna<4,>=2.5; python_version >= "3"
  Downloading idna-3.3-py3-none-any.whl (61 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
Collecting charset-normalizer~=2.0.0; python_version >= "3"
  Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
  Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Installing collected packages: idna, urllib3, charset-normalizer, certifi, requests
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.12 idna-3.3 requests-2.27.1 urllib3-1.26.8
WARNING: You are using pip version 20.2.3; however, version 22.0.4 is available.
You should consider upgrading via the '/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip' command.
Running Python script…
Traceback (most recent call last):
  File "./my_script.py", line 5, in <module>
    from applaud.connection import Connection
ModuleNotFoundError: No module named 'applaud'

I have tried many different ways of upgrading pip, and even installing pyenv (which I've ruled out because the Python installation for pyenv uses Homebrew which is incredibly slow in Xcode Cloud, and didn't work besides). What am I doing wrong, and how is installing Applaud different from installing Requests?

abbeycode commented 2 years ago

As I'm continuing to debug, it looks like the reason is applaud requires Python ≥ 3.9, while Xcode 13.3 is shipping with 3.8.9. I'm hesitant to install a new Python version on it, since that will likely require Homebrew, which as mentioned in the original posting, I'm trying hard to avoid. I'll continue to update with what I find.

yangyubo commented 2 years ago

applaud uses very limited type hints features in Python 3.9, it's very easy to replace these code, for example:

# Python 3.9:
list[Union[App, Build, BetaTester]]]
# 3.8 counterpart
from typing import List
List[Union[App, Build, BetaTester]]]

The same is true for Dict and other types. You can fork applaudgen and make slight modifications to generate your own package in case you insist Python 3.8.

Yang

abbeycode commented 2 years ago

Thanks so much for that amazing suggestion. I got it working! This is my fork:

https://github.com/abbeycode/applaudgen.git (the python-3.8 branch).

To use it instead of the pip module, this is how I modified my ci_scripts/ci_pre_xcodebuild.sh script:

# All Xcode Cloud scripts run in Bash, but the is-at-least command from zsh is perfect for this
/bin/zsh <<'EOF'
autoload is-at-least

# Fail if Xcode Cloud ever gets upgraded to Python 3.9, so I can remove the hack
if is-at-least 3.9 $(cut -d' ' -f2 <<< "$(python3 --version)"); then
    echo "No more need to manually install Applaud fork. Update script to call 'pip3 install applaud'"
    exit 1
else
    echo "Installing Applaud from a custom fork (instead of Pip) because Python is < 3.9"
fi
EOF

CLONEDIR=$(mktemp -d)/applaudgen
echo "Cloning applaud fork to ${CLONEDIR}"
git clone -b python-3.8 https://github.com/abbeycode/applaudgen.git --single-branch $CLONEDIR

echo "Installing Applaudgen's dependencies"
pip3 install jinja2

echo "Running Applaudgen"
$CLONEDIR/applaudgen.py -o applaud
rm -rf $CLONEDIR

echo "Installing Applaud's dependencies"
pip3 install requests
pip3 install deprecated
pip3 install pydantic
pip3 install email_validator
pip3 install --upgrade "pip>=20.3" # authlib needs Rust
pip3 install authlib

This is working now, using various calls (including multi-part screenshot uploads).