chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
807 stars 132 forks source link

pydantic v2 #1017

Open bitxeno opened 11 months ago

bitxeno commented 11 months ago

I follow this link https://github.com/chaquo/chaquopy/issues/657 to build pydantic v2.4.2,but download package step report error:

build-wheel.py: python3.10 -m pip --disable-pip-version-check install cffi==1.15.1 setuptools-rust==1.2.0
Requirement already satisfied: cffi==1.15.1 in /home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages (1.15.1)
Requirement already satisfied: setuptools-rust==1.2.0 in /home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages (1.2.0)
Requirement already satisfied: pycparser in /home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages (from cffi==1.15.1) (2.21)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages (from setuptools-rust==1.2.0) (4.8.0)
Requirement already satisfied: setuptools>=46.1 in /home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages (from setuptools-rust==1.2.0) (67.0.0)
Requirement already satisfied: semantic-version<3,>=2.8.2 in /home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages (from setuptools-rust==1.2.0) (2.10.0)
build-wheel.py: cd /mnt/d/dev/chaquopy/server/pypi/packages/pydantic/build/2.4.2
build-wheel.py: rm -rf /mnt/d/dev/chaquopy/server/pypi/packages/pydantic/build/2.4.2/cp310-cp310-android_21_x86_64
build-wheel.py: mkdir -p /mnt/d/dev/chaquopy/server/pypi/packages/pydantic/build/2.4.2/cp310-cp310-android_21_x86_64
build-wheel.py: python3.10 -m pip --disable-pip-version-check download --no-deps --no-binary pydantic --no-build-isolation pydantic==2.4.2
Collecting pydantic==2.4.2
  Using cached pydantic-2.4.2.tar.gz (654 kB)
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [53 lines of output]
      Traceback (most recent call last):
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
          hook = backend.prepare_metadata_for_build_wheel
      AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_wheel'

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/build.py", line 56, in build_wheel
          return os.path.basename(next(builder.build(wheel_directory, ['standard'])))
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 93, in build
          self.metadata.validate_fields()
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/metadata/core.py", line 243, in validate_fields
          _ = self.version
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/metadata/core.py", line 128, in version
          self._version = self._get_version()
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/metadata/core.py", line 222, in _get_version
          core_metadata = self.core
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/metadata/core.py", line 166, in core
          metadata_hooks = self.hatch.metadata.hooks
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/metadata/core.py", line 1539, in hooks
          metadata_hook = self.plugin_manager.metadata_hook.get(hook_name)
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/plugin/manager.py", line 97, in get
          return self.collect().get(name)
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/plugin/manager.py", line 67, in collect
          self.third_party_plugins.load()
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatchling/plugin/manager.py", line 106, in load
          self.manager.load_setuptools_entrypoints('hatch')
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/pluggy/_manager.py", line 398, in load_setuptools_entrypoints
          plugin = ep.load()
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
          module = import_module(match.group('module'))
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/importlib/__init__.py", line 126, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 883, in exec_module
        File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatch_fancy_pypi_readme/hooks.py", line 12, in <module>
          from ._builder import build_text
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatch_fancy_pypi_readme/_builder.py", line 7, in <module>
          from ._fragments import Fragment
        File "/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/hatch_fancy_pypi_readme/_fragments.py", line 14, in <module>
          from jsonschema import Validator
      ImportError: cannot import name 'Validator' from 'jsonschema' (/home/apps/miniconda3/envs/build-wheel-310/lib/python3.10/site-packages/jsonschema/__init__.py)
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
build-wheel.py: Warning: pip download returned exit status 1
build-wheel.py: Error: Can't find downloaded source archive. Does the name and version in the package's meta.yaml match the filename shown above?

how to fix this?

IsakTheHacker commented 11 months ago

Related: #995

Saeppo commented 10 months ago

This worked for me.

python {
            version 3.8
            pip {
                install "pydantic<2"
            }
 }
mhsmith commented 10 months ago

Originally posted by @caarmen in https://github.com/chaquo/chaquopy/issues/995#issuecomment-1817681622

Would like to be able to use pydantic 2. Some libs seem to require it (ex: ariadne-codegen: https://github.com/mirumee/ariadne-codegen/pull/186 )

mhsmith commented 10 months ago

Originally posted by @IsakTheHacker in #995

I need the pydantic package for my app which depends on the native pydantic-core package written in Rust. I have tried following the guide for building Cryptography version 39 and read #657. It is hard to understand exactly what I need to do to set up Rust support when there is no official documentation. For example, do I need to cross-compile Python as described here or is that specific to the Cryptogaphy package?

mhsmith commented 10 months ago

@IsakTheHacker: I'll try to centralize all the notes about Rust in a single place: #1030.

svdgoor commented 4 months ago

Is there a method to manually build and insert the module? I don't need the latest version each time, but since openai depends on it I cannot build my app.

I need to build for Android and iOS. Neither are currently functioning.

mhsmith commented 4 months ago

Sorry, there's no easy solution at the moment.

Actually, since openai is still compatible with pydantic version 1, there is an easy solution for that:

            pip {
                install("pydantic<2")
                install("openai")
            }