kevinheavey / anchorpy

The Python Anchor client.
https://kevinheavey.github.io/anchorpy/
MIT License
222 stars 59 forks source link

Cargo dependency for anchor.py #63

Closed hareeshnagaraj closed 2 years ago

hareeshnagaraj commented 2 years ago

During a docker container build with anchor.py==0.8.0 in requirements.txt we are encountering the following error -

ERROR: Could not find a version that satisfies the requirement pyheck== (from versions: 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5)
ERROR: No matching distribution found for pyheck==
bash-5.1# pip install --use-deprecated=legacy-resolver pyheck==0.1.5
Collecting pyheck==0.1.5
  Downloading pyheck-0.1.5.tar.gz (3.4 kB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-8jbs9l9k/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'maturin>=0.12,<0.13'
       cwd: None
  Complete output (57 lines):
  Collecting maturin<0.13,>=0.12
    Downloading maturin-0.12.11.tar.gz (141 kB)
    Installing build dependencies: started
    Installing build dependencies: finished with status 'done'
    Getting requirements to build wheel: started
    Getting requirements to build wheel: finished with status 'done'
      Preparing wheel metadata: started
      Preparing wheel metadata: finished with status 'done'
  Collecting tomli>=1.1.0
    Using cached tomli-2.0.1-py3-none-any.whl (12 kB)
  Building wheels for collected packages: maturin
    Building wheel for maturin (PEP 517): started
    Building wheel for maturin (PEP 517): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 /usr/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmp5xajsdl4
         cwd: /tmp/pip-install-4hr6qk0z/maturin_3c608d77a7bc49019ad66524cd05095f
    Complete output (36 lines):
    running bdist_wheel
    running build
    installing to build/bdist.linux-x86_64/wheel
    running install
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
        main()
      File "/usr/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/usr/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 204, in build_wheel
        return _build_backend().build_wheel(wheel_directory, config_settings,
      File "/tmp/pip-build-env-c2ng6n20/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 216, in build_wheel
        return self._build_with_temp_dir(['bdist_wheel'], '.whl',
      File "/tmp/pip-build-env-c2ng6n20/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 202, in _build_with_temp_dir
        self.run_setup()
      File "/tmp/pip-build-env-c2ng6n20/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 145, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 118, in <module>
        setup(
      File "/tmp/pip-build-env-c2ng6n20/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.9/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.9/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-env-c2ng6n20/overlay/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 335, in run
        self.run_command('install')
      File "/usr/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "setup.py", line 60, in run
        raise RuntimeError(
    RuntimeError: cargo not found in PATH. Please install rust (https://www.rust-lang.org/tools/install) and try again

Is there a known fix for this?

We have tried adding a rust dependency manually in a Docker build to work around it with little luck - things get stuck indefinitely in the following stage:

Collecting pyheck<0.2.0,>=0.1.4
  Using cached pyheck-0.1.5.tar.gz (3.4 kB)
  Installing build dependencies ... -

Any recommendations would be greatly appreciated!

hareeshnagaraj commented 2 years ago

I was able to resolve this by adding the following lines to my Dockerfile:

# Install Rust for anchor.py dependency
RUN curl -s --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
    source $HOME/.cargo/env

As well as:

python3 -m pip install --upgrade pip 
kevinheavey commented 2 years ago

python3 -m pip install --upgrade pip

I think this is actually the only part you need.

What you're seeing is pip trying to build pyheck from source, which it shouldn't be doing in this case.

Pyheck has prebuilt wheels on pypi for all the common platforms so you don't need to have rust installed.

However I remember some older versions of pip not being able to find these wheels. So yeah just use an up-to-date pip

hareeshnagaraj commented 2 years ago

thank for the quick reply @kevinheavey! will try with the rust installation step removed

kevinheavey commented 2 years ago

So did this work? @hareeshnagaraj

hareeshnagaraj commented 2 years ago

yes! no rust installation was necessary

raymondjacobson commented 2 years ago

Hey @kevinheavey -- Just curious, do you have any thoughts on why this wouldn't work in docker on m1? I see that there should be a wheel https://pypi.org/project/pyheck/#files, but always fails out on

#10 27.65 Collecting pyheck<0.2.0,>=0.1.4
#10 27.65   Downloading pyheck-0.1.5.tar.gz (3.4 kB)
#10 27.76   Installing build dependencies: started
#10 30.21   Installing build dependencies: finished with status 'done'
#10 30.21   Getting requirements to build wheel: started
#10 30.25   Getting requirements to build wheel: finished with status 'done'
#10 30.26   Preparing metadata (pyproject.toml): started
#10 61.25   Preparing metadata (pyproject.toml): finished with status 'error'
#10 61.26   error: subprocess-exited-with-error
#10 61.26
#10 61.26   × Preparing metadata (pyproject.toml) did not run successfully.
#10 61.26   │ exit code: 1
#10 61.26   ╰─> [7 lines of output]
#10 61.26       💥 maturin failed
#10 61.26         Caused by: Failed to read LICENSE
#10 61.26         Caused by: failed to open file `LICENSE`
#10 61.26         Caused by: No such file or directory (os error 2)
#10 61.26       Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/tmp/pip-modern-metadata-cqmo_4_l', '--interpreter', '/usr/bin/python3']' returned non-zero exit status 1.
#10 61.26       Checking for Rust toolchain....
#10 61.26       Running `maturin pep517 write-dist-info --metadata-directory /tmp/pip-modern-metadata-cqmo_4_l --interpreter /usr/bin/python3`
#10 61.26       [end of output]
kevinheavey commented 2 years ago

@raymondjacobson have you checked if your docker image is using an old version of pip?

raymondjacobson commented 2 years ago

@raymondjacobson have you checked if your docker image is using an old version of pip?

Thanks for the speedy reply! I work with @hareeshnagaraj -- just trying out our docker setup on different platforms. So pip is python3 & upgraded. Just learned that switching the dep to pyheck 0.1.4 works instead of 0.1.5! I see that anchorpy only requires 0.1.4 at the moment, so that's totally unblocking. Curious to dig into some of the diff to see what it might be. Odd!

kevinheavey commented 2 years ago

Yeah that's weird, pyheck 0.1.5 should be more portable, not less. It relaxed the Python version requirement from >=3.9 to >=3.7, and added musllinux wheels

kevinheavey commented 2 years ago

@raymondjacobson I can see that it's downloading pyheck-0.1.5.tar.gz instead of the wheel file. That only happens if it doesn't find a wheel it can use, which shouldn't be happening

kevinheavey commented 2 years ago

@raymondjacobson did you ever figure this out?

kevinheavey commented 2 years ago

@raymondjacobson did you figure out if something was wrong in the end? I'm going to be inflicting some Rust on solana-py and would like to know if there's something missing for some platform