codemagic-ci-cd / cli-tools

Various utilities to managing Android and iOS app builds, code signing, and deployment.
https://codemagic.io/start/
GNU General Public License v3.0
235 stars 39 forks source link

Use `packaging` package instead of deprecated `distutils.version` to fix GitHub macOS 13 runner. #369

Closed Jonas-Sander closed 8 months ago

Jonas-Sander commented 8 months ago

When running the following command on macos-13 runners on GitHub...

  app-store-connect fetch-signing-files $BUNDLE_ID \
    --platform IOS \
    --type MAC_APP_STORE \
    --strict-match-identifier \
    --create

we very often face the following error:

   shell: /bin/bash -e {0}
  env:
    CERTIFICATE_PRIVATE_KEY: ***
    APP_STORE_CONNECT_KEY_IDENTIFIER: ***
    APP_STORE_CONNECT_ISSUER_ID: ***
    APP_STORE_CONNECT_PRIVATE_KEY: ***
    BUNDLE_ID: de.codingbrain.sharezone.app
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/Current/bin/app-store-connect", line 5, in <module>
    from codemagic.tools import AppStoreConnect
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/codemagic/tools/__init__.py", line 1, in <module>
    from .android_app_bundle import AndroidAppBundle
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/codemagic/tools/android_app_bundle.py", line 12, in <module>
    from codemagic.models import AndroidSigningInfo
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/codemagic/models/__init__.py", line 6, in <module>
    from .code_sign_entitlements import CodeSignEntitlements
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/codemagic/models/code_sign_entitlements.py", line 8, in <module>
    from distutils.version import LooseVersion
ModuleNotFoundError: No module named 'distutils'
Error: Process completed with exit code 1.

It seems like with Python 3.12 the distutils package was removed:

PEP 632: Remove the distutils package. See the migration guide for advice replacing the APIs it provided. The third-party Setuptools package continues to provide distutils, if you still require it in Python 3.12 and beyond.

The the migration guide says the following:

For these modules or types, use the standards-defined Python Packaging Authority packages specified:

distutils.version — use the packaging package

So I guess the distutils package needs to be removed and be replaced with the packaging package.

Note: I copied the above text from the migration guide only partially - maybe there are other usages of the distutils package which need to be replaced in a different way. See the migration guide document for more information.

A current workaround for the issue is to install the third-party setuptools package (I'm still testing it out, will provide feedback if it worked for me in the near future. EDIT: Seems to be working.)

priitlatt commented 8 months ago

@Jonas-Sander version 0.47.0 fixes this.

Jonas-Sander commented 8 months ago

Thanks 🙏