dgzlopes / cloud-detect

Module that determines a host's cloud provider.
https://pypi.org/project/cloud-detect/
MIT License
35 stars 13 forks source link

Use asyncio to speed up cloud identification #12

Closed kshivakumar closed 2 years ago

kshivakumar commented 2 years ago

Implements https://github.com/dgzlopes/cloud-detect/issues/11

Uses asyncio to check all the cloud providers concurrently and returns back a response as soon as the cloud provider is detected.

Important changes:

I manually tested the changes in Azure and GCP, it's working fine and the response comes back within a second.

kshivakumar commented 2 years ago

For some unknown reason, I get the below error on my machine(MacOS x86) during pre-commit/make test:

Reorder python imports...................................................Failed
- hook id: reorder-python-imports
- exit code: 1

Traceback (most recent call last):
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/bin/reorder-python-imports", line 8, in <module>
    sys.exit(main())
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/reorder_python_imports.py", line 685, in main
    application_directories=args.application_directories.split(':'),
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/reorder_python_imports.py", line 420, in fix_file_contents
    partitioned = step(partitioned)
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/reorder_python_imports.py", line 334, in apply_import_sorting
    sorted_blocks = sort(import_obj_to_partition.keys(), **sort_kwargs)
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/aspy/refactor_imports/sort.py", line 96, in sort
    imports_partitioned[classify_func(import_obj)].append(import_obj)
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/aspy/refactor_imports/sort.py", line 73, in classify_func
    return classify_import(obj.import_statement.module, **kwargs)
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/aspy/refactor_imports/classify.py", line 139, in classify_import
    base, application_directories,
  File "/root/.cache/pre-commit/repol5aizj_t/py_env-python3/lib/python3.7/site-packages/aspy/refactor_imports/classify.py", line 103, in _get_module_info
    assert spec.submodule_search_locations is not None
AssertionError

I tried different Python versions (3.7, 3.8, 3.9), but the error doesn't go away. Other hooks and test cases are all passing.

Update: The error occurs in setup.py file

kshivakumar commented 2 years ago

@dgzlopes Test cases are failing for Python 3.5 because the library for mocking api responses - aresponses doesn't support Python 3.5. The library uses format strings which was added in 3.6. I have to check if there's an alternative library that supports Python 3.5.

kshivakumar commented 2 years ago

@dgzlopes How important is Python 3.5 support? It's officially retired - https://endoflife.date/python. I initially thought of suggesting to remove support for Python 3.6 and below. The asynchronous api in Python kind of stabilised in Python 3.7 and has remained consistent till 3.9.

dgzlopes commented 2 years ago

Not important @kshivakumar :D

Feel free to drop it!

dgzlopes commented 2 years ago

I'll review the PR at the end of the week (I've scheduled it on my personal calendar).

Sorry for my slow pace :smile:

kshivakumar commented 2 years ago

The only thing, while running tox locally, the pre-commit hook step did some fixes on setup.py (re-ordering Python import). Do you mind committing those?

@dgzlopes Fixed it and also updated README.

kshivakumar commented 2 years ago

@dgzlopes Can we merge this if there are no further issues?

dgzlopes commented 2 years ago

Sorry for the delay! I had a mess on my GH notifications :(

Merged. I'll cut a new release.