Repository: amitdev/lru-dict (language: python)

Issue:
Architecture errors on macosx-10.9-universal2-3.10/lru.o
Hi when installing `web3` on a 2017 mac installation breaks with multiple `Unsupported architecture` errors.

Fix:
`ARCHFLAGS="-arch x86_64"  pip install web3`

Full stack:
```
      building 'lru' extension
      creating build
      creating build/temp.macosx-10.9-universal2-3.10
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -I/Users/jeanpaulruizdepraz/Documents/software/sni/web3_py/venv/include -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c lru.c -o build/temp.macosx-10.9-universal2-3.10/lru.o
      In file included from lru.c:1:
      In file included from /Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/Python.h:11:
      In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/limits.h:21:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/limits.h:63:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
      #error Unsupported architecture
       ^
      In file included from lru.c:1:
      In file included from /Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/Python.h:11:
      In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/limits.h:21:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/limits.h:64:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/limits.h:8:2: error: architecture not supported
      #error architecture not supported
       ^
      In file included from lru.c:1:
      In file included from /Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/Python.h:25:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:71:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_types.h:27:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:33:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported
      #error architecture not supported
       ^
      In file included from lru.c:1:
      In file included from /Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/Python.h:25:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:71:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_types.h:27:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'
      typedef __int64_t       __darwin_blkcnt_t;      /* total blocks */
              ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:56:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
      typedef __int32_t       __darwin_blksize_t;     /* preferred block size */
              ^
      note: '__int128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:57:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
      typedef __int32_t       __darwin_dev_t;         /* dev_t */
              ^
      note: '__int128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:60:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
      typedef __uint32_t      __darwin_gid_t;         /* [???] process and group IDs */
              ^
      note: '__uint128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:61:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
      typedef __uint32_t      __darwin_id_t;          /* [XSI] pid_t, uid_t, or gid_t*/
              ^
      note: '__uint128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:62:9: error: unknown type name '__uint64_t'
      typedef __uint64_t      __darwin_ino64_t;       /* [???] Used for 64 bit inodes */
              ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:68:9: error: unknown type name '__darwin_natural_t'
      typedef __darwin_natural_t __darwin_mach_port_name_t; /* Used by mach */
              ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:70:9: error: unknown type name '__uint16_t'; did you mean '__uint128_t'?
      typedef __uint16_t      __darwin_mode_t;        /* [???] Some file attributes */
              ^
      note: '__uint128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:71:9: error: unknown type name '__int64_t'
      typedef __int64_t       __darwin_off_t;         /* [???] Used for file sizes */
              ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:72:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
      typedef __int32_t       __darwin_pid_t;         /* [???] process and group IDs */
              ^
      note: '__int128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:73:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
      typedef __uint32_t      __darwin_sigset_t;      /* [???] signal set */
              ^
      note: '__uint128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:74:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
      typedef __int32_t       __darwin_suseconds_t;   /* [???] microseconds */
              ^
      note: '__int128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:75:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
      typedef __uint32_t      __darwin_uid_t;         /* [???] user IDs */
              ^
      note: '__uint128_t' declared here
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:76:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
      typedef __uint32_t      __darwin_useconds_t;    /* [???] microseconds */
              ^
      note: '__uint128_t' declared here
      In file included from lru.c:1:
      In file included from /Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/Python.h:25:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:71:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_types.h:43:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
      typedef __uint32_t      __darwin_wctype_t;
              ^
      note: '__uint128_t' declared here
      In file included from lru.c:1:
      In file included from /Library/Frameworks/Python.framework/Versions/3.10/include/python3.10/Python.h:25:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:75:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_va_list.h:31:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/types.h:37:2: error: architecture not supported
      #error architecture not supported
       ^
      fatal error: too many errors emitted, stopping now [-ferror-limit=]
      20 errors generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
```


Discussion / hints:
lru-dict 1.1.8 has prebuilt wheels now so it should work out of the box without you having to compile it
> lru-dict 1.1.8 has prebuilt wheels now so it should work out of the box without you having to compile it

I don't know. On a Mac M1 (osx-arm64) I tried install web3 with `pip install web3`  (version 5.31.3) and it ends with no error but at runtime (import web3), 2 issues for librairies that doesn't have good osx-arm64  implementation : pycryptodome & lru-dict. 
I am in a Conda environnement (miniforge), 
I don't know if it is mandatory but I have updated Xcode to the last version available, 
After that, and I have install with conda this 2 libs after uninstalling them through web3 installation  : 
`conda install pycryptodome`
`conda install lru-dict`
I think it downgrade  `pycryptodome` from   v3.16.0 to  v3.15.0 
and install good build `lru-dict` v 1.1.8 for osx-arm64
I tried this with python 3.9 and 3.10, and seems to work well.
So still a problem with pip for lru-dict solved with conda
Facing the same issue with Mac M1.
```sh
pipenv run flask run 
```

```                  
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

Error: While importing 'example.app', an ImportError was raised:

Traceback (most recent call last):
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
    __import__(module_name)
  File "/Users/so/Documents/n/my-app/my-app-flask/example/app.py", line 2, in <module>
    from login_flask.ressource import register_auth_blueprint
  File "/Users/so/Documents/n/my-app/my-app-flask/login_flask/ressource.py", line 11, in <module>
    from .validation import Validation
  File "/Users/so/Documents/n/my-app/my-app-flask/login_flask/validation.py", line 5, in <module>
    from web3 import Web3
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/__init__.py", line 4, in <module>
    from web3.main import (
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/main.py", line 74, in <module>
    from web3._utils.module import (
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/_utils/module.py", line 18, in <module>
    from web3.module import (
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/module.py", line 28, in <module>
    from web3.providers.persistent import (
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/providers/__init__.py", line 1, in <module>
    from .async_base import (  # noqa: F401
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/providers/async_base.py", line 24, in <module>
    from web3.middleware import (
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/middleware/__init__.py", line 20, in <module>
    from .async_cache import (  # noqa: F401
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/middleware/async_cache.py", line 18, in <module>
    from web3.middleware.cache import (
  File "/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/web3/middleware/cache.py", line 17, in <module>
    import lru
ImportError: dlopen(/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/lru.cpython-310-darwin.so, 0x0002): tried: '/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/lru.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/lru.cpython-310-darwin.so' (no such file), '/Users/so/.local/share/virtualenvs/my-app-flask-jL4T8VRQ/lib/python3.10/site-packages/lru.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
```
`lru-dict` was installed with `web3`. It installed the latest version which is `1.2.0`.
I had to downgrade `lru-dict` from `1.2.0` to `1.1.8`. So i had to specify the use of the lib in my requirements (which wasn't needed for it was taken care by `web3`)
> lru-dict 1.1.8 has prebuilt wheels now so it should work out of the box without you having to compile it

Unfortunately, there are no wheels on PyPI for macOS ARM64.

Fix patch:
diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml
index f27f0b0..0bd3ccb 100644
--- a/.github/workflows/build-and-deploy.yml
+++ b/.github/workflows/build-and-deploy.yml
@@ -8,10 +8,10 @@ jobs:
     runs-on: ${{ matrix.os }}
     strategy:
       matrix:
-        os: [ubuntu-20.04, windows-2019, macOS-11]
+        os: [ubuntu-22.04, windows-2022, macOS-11]
 
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - name: Set up QEMU
         if: runner.os == 'Linux'
         uses: docker/setup-qemu-action@v2
@@ -19,10 +19,15 @@ jobs:
           platforms: all
       # Used to host cibuildwheel
       - name: Build wheels
-        uses: pypa/cibuildwheel@v2.12.0
+        uses: pypa/cibuildwheel@v2.16.2
         env:
           # configure cibuildwheel to build native archs ('auto'), and some emulated ones
           CIBW_ARCHS_LINUX: auto aarch64 ppc64le
+          CIBW_ARCHS_MACOS: x86_64 arm64 universal2
+          CIBW_TEST_REQUIRES: .[test]
+          CIBW_TEST_COMMAND: pytest {project}
+          # arm64 cannot be tested on a x86_64 CI runner
+          CIBW_TEST_SKIP: "*-macosx_arm64"
       - uses: actions/upload-artifact@v3
         with:
           path: ./wheelhouse/*.whl
@@ -31,7 +36,7 @@ jobs:
     name: Build source distribution
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - name: Build sdist
         run: pipx run build --sdist
       - uses: actions/upload-artifact@v3
@@ -44,13 +49,13 @@ jobs:
     runs-on: ubuntu-latest
     if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
     steps:
-    - uses: actions/setup-python@v2
+    - uses: actions/setup-python@v4
     - uses: actions/download-artifact@v3
       with:
         name: artifact
         path: dist
     - name: Publish package
-      uses: pypa/gh-action-pypi-publish@v1.5.0
+      uses: pypa/gh-action-pypi-publish@release/v1
       with:
         verbose: true
         user: __token__
diff --git a/setup.py b/setup.py
index deca7df..99c090c 100644
--- a/setup.py
+++ b/setup.py
@@ -21,11 +21,11 @@
         'Operating System :: POSIX',
         'Programming Language :: C',
         'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: 3.10',
         'Programming Language :: Python :: 3.11',
+        'Programming Language :: Python :: 3.12',
         'Programming Language :: Python :: Implementation :: CPython',
         'Topic :: Software Development :: Libraries :: Python Modules',
         ],


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index bbf4a1a..622cdfb 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -1,16 +1,19 @@
 name: Tests
 
-on: [push]
+on: [push, pull_request]
+
+env:
+  PYTHON_VERSIONS: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.8", "pypy-3.9", "pypy-3.10"]
 
 jobs:
   test:
     runs-on: ubuntu-22.04
     strategy:
       matrix:
-        python: ["3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.7, pypy-3.8, pypy-3.9]
+        python: ${{fromJson(env.PYTHON_VERSIONS)}}
 
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - uses: actions/setup-python@v4
         with:
           python-version: ${{ matrix.python }}
@@ -21,10 +24,10 @@ jobs:
     runs-on: ubuntu-22.04
     strategy:
       matrix:
-        python: ["3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.7, pypy-3.8, pypy-3.9]
+        python: ${{fromJson(env.PYTHON_VERSIONS)}}
 
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - uses: actions/setup-python@v4
         with:
           python-version: ${{ matrix.python }}