vladimirs-git / fortigate-api

Python package for configuring Fortigate (Fortios) devices using REST API
Apache License 2.0
61 stars 18 forks source link

python 3.10.5 pip install fails on not installing 'requests' before usage with poetry #3

Closed bartdorlandt closed 1 year ago

bartdorlandt commented 2 years ago

When installing the fortigate-api using pip, it crashes and fails on 'requests' not being present.

    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> [21 lines of output]
        Traceback (most recent call last):
          File "/tmp/tmp9j5_wgaq_in_process.py", line 363, in <module>
            main()
          File "/tmp/tmp9j5_wgaq_in_process.py", line 345, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "/tmp/tmp9j5_wgaq_in_process.py", line 130, in get_requires_for_build_wheel
            return hook(config_settings)
          File "/tmp/pip-build-env-6rdrkzvm/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 177, in get_requires_for_build_wheel
            return self._get_build_requires(
          File "/tmp/pip-build-env-6rdrkzvm/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 159, in _get_build_requires
            self.run_setup()
          File "/tmp/pip-build-env-6rdrkzvm/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 281, in run_setup
            super(_BuildMetaLegacyBackend,
          File "/tmp/pip-build-env-6rdrkzvm/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 174, in run_setup
            exec(code, locals())
          File "<string>", line 7, in <module>
          File "/tmp/pip-req-build-psl84rhi/fortigate_api/__init__.py", line 3, in <module>
            from fortigate_api.fortigate import Fortigate
          File "/tmp/pip-req-build-psl84rhi/fortigate_api/fortigate.py", line 12, in <module>
            import requests
        ModuleNotFoundError: No module named 'requests'
        [end of output]

Using a fresh virtualenv the following can be seen. I'm not able to understand yet, why pypi wouldn't honor the "install_requires" argument (or so it seems).

hostname ~/tmp
$ venvcreate
Requirement already satisfied: pip in ./venv/lib/python3.10/site-packages (22.0.4)
Collecting pip
  Using cached pip-22.2.1-py3-none-any.whl (2.0 MB)
Requirement already satisfied: setuptools in ./venv/lib/python3.10/site-packages (58.1.0)
Collecting setuptools
  Using cached setuptools-63.3.0-py3-none-any.whl (1.2 MB)
Installing collected packages: setuptools, pip
  Attempting uninstall: setuptools
    Found existing installation: setuptools 58.1.0
    Uninstalling setuptools-58.1.0:
      Successfully uninstalled setuptools-58.1.0
  Attempting uninstall: pip
    Found existing installation: pip 22.0.4
    Uninstalling pip-22.0.4:
      Successfully uninstalled pip-22.0.4
Successfully installed pip-22.2.1 setuptools-63.3.0
(venv) hostname ~/tmp
$ pip install fortigate-api
Collecting fortigate-api
  Using cached fortigate_api-0.2.5.tar.gz (30 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-dsvb5kv5/fortigate-api_01b828e11cff462d9af5d9c172bd885d/setup.py", line 7, in <module>
          import fortigate_api as package
        File "/tmp/pip-install-dsvb5kv5/fortigate-api_01b828e11cff462d9af5d9c172bd885d/fortigate_api/__init__.py", line 3, in <module>
          from fortigate_api.fortigate import Fortigate
        File "/tmp/pip-install-dsvb5kv5/fortigate-api_01b828e11cff462d9af5d9c172bd885d/fortigate_api/fortigate.py", line 12, in <module>
          import requests
      ModuleNotFoundError: No module named 'requests'
      [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.

python version: 3.10.5

prior versions don't seem to have this issue.

vladimirs-git commented 2 years ago

I can't reproduce this problem

bartdorlandt commented 2 years ago

It seems when creating this I left out an important detail. I was using poetry to install fortigate-api.

mkdir /tmp/ff
python3.10 -m venv .venv
poetry init
poetry add fortigate-api

output:

Using version ^0.2.6 for fortigate-api

Updating dependencies
Resolving dependencies... (0.6s)

Writing lock file

Package operations: 6 installs, 0 updates, 0 removals

  • Installing certifi (2022.6.15)
  • Installing charset-normalizer (2.1.1)
  • Installing idna (3.3)
  • Installing urllib3 (1.26.12)
  • Installing requests (2.28.1)
  • Installing fortigate-api (0.2.6): Failed

  CalledProcessError

  Command '['/private/tmp/ff/.venv/bin/python', '/Users/bart/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-22.2.2-py3-none-any.whl/pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/private/tmp/ff/.venv', '--no-deps', '/Users/bart/Library/Caches/pypoetry/artifacts/83/37/8f/35d181b16e27e34c1900d827ecfea7867d3fe0db40ba7bc12b5921af42/fortigate_api-0.2.6.tar.gz']' returned non-zero exit status 1.

  at ~/.pyenv/versions/3.10.5/lib/python3.10/subprocess.py:524 in run
       520│             # We don't call process.wait() as .__exit__ does that for us.
       521│             raise
       522│         retcode = process.poll()
       523│         if check and retcode:
    →  524│             raise CalledProcessError(retcode, process.args,
       525│                                      output=stdout, stderr=stderr)
       526│     return CompletedProcess(process.args, retcode, stdout, stderr)
       527│
       528│

The following error occurred when trying to handle this error:

  EnvCommandError

  Command ['/private/tmp/ff/.venv/bin/python', '/Users/bart/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/virtualenv/seed/wheels/embed/pip-22.2.2-py3-none-any.whl/pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/private/tmp/ff/.venv', '--no-deps', '/Users/bart/Library/Caches/pypoetry/artifacts/83/37/8f/35d181b16e27e34c1900d827ecfea7867d3fe0db40ba7bc12b5921af42/fortigate_api-0.2.6.tar.gz'] errored with the following return code 1, and output:
  Processing /Users/bart/Library/Caches/pypoetry/artifacts/83/37/8f/35d181b16e27e34c1900d827ecfea7867d3fe0db40ba7bc12b5921af42/fortigate_api-0.2.6.tar.gz
    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 'error'
    error: subprocess-exited-with-error

    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> [21 lines of output]
        Traceback (most recent call last):
          File "/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/tmpxqohejrd_in_process.py", line 363, in <module>
            main()
          File "/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/tmpxqohejrd_in_process.py", line 345, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/tmpxqohejrd_in_process.py", line 130, in get_requires_for_build_wheel
            return hook(config_settings)
          File "/private/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/pip-build-env-0pyfyeip/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
            return self._get_build_requires(config_settings, requirements=['wheel'])
          File "/private/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/pip-build-env-0pyfyeip/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
            self.run_setup()
          File "/private/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/pip-build-env-0pyfyeip/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 482, in run_setup
            super(_BuildMetaLegacyBackend,
          File "/private/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/pip-build-env-0pyfyeip/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup
            exec(code, locals())
          File "<string>", line 7, in <module>
          File "/private/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/pip-req-build-1la2_xk_/fortigate_api/__init__.py", line 3, in <module>
            from fortigate_api.fortigate import Fortigate
          File "/private/var/folders/4c/xmcy7hkn283bzd0vthnj87mw0000gn/T/pip-req-build-1la2_xk_/fortigate_api/fortigate.py", line 12, in <module>
            import requests
        ModuleNotFoundError: No module named 'requests'
        [end of output]

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

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

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

  at ~/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/env.py:1473 in _run
      1469│                 output = subprocess.check_output(
      1470│                     command, stderr=subprocess.STDOUT, env=env, **kwargs
      1471│                 )
      1472│         except CalledProcessError as e:
    → 1473│             raise EnvCommandError(e, input=input_)
      1474│
      1475│         return decode(output)
      1476│
      1477│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:

The following error occurred when trying to handle this error:

  PoetryException

  Failed to install /Users/bart/Library/Caches/pypoetry/artifacts/83/37/8f/35d181b16e27e34c1900d827ecfea7867d3fe0db40ba7bc12b5921af42/fortigate_api-0.2.6.tar.gz

  at ~/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/utils/pip.py:51 in pip_install
       47│
       48│     try:
       49│         return environment.run_pip(*args)
       50│     except EnvCommandError as e:
    →  51│         raise PoetryException(f"Failed to install {path.as_posix()}") from e
       52│

(.venv) bart@Barts-MacBook-Pro ff % python3 -V                                                                            1 ↵
Python 3.10.6
vladimirs-git commented 1 year ago

problem solved in fortigate-api 1.0.1