Skip to content

Commit

Permalink
refactor(tools): prepare for migration from Requests to httpx
Browse files Browse the repository at this point in the history
This commit prepares for migrating from Requests to httpx by adjusting imports and usage in LDAP, command line tools, and GUI code.
  • Loading branch information
laurent-laporte-pro committed Sep 4, 2023
1 parent 066357a commit 2e896d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion antarest/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from multiprocessing import Process
from pathlib import Path

import requests
try:
# `httpx` is a modern alternative to the `requests` library
import httpx as requests
except ImportError:
# noinspection PyUnresolvedReferences, PyPackageRequirements
import requests

import uvicorn # type: ignore
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction, QApplication, QMenu, QSystemTrayIcon
Expand Down
7 changes: 6 additions & 1 deletion antarest/login/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
from dataclasses import dataclass
from typing import Dict, List, Optional

import requests
try:
# `httpx` is a modern alternative to the `requests` library
import httpx as requests
except ImportError:
# noinspection PyUnresolvedReferences, PyPackageRequirements
import requests

from antarest.core.config import Config
from antarest.core.model import JSON
Expand Down
15 changes: 12 additions & 3 deletions antarest/tools/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
from zipfile import ZipFile

import numpy as np
import requests
from requests import Session

try:
# The HTTPX equivalent of `requests.Session` is `httpx.Client`.
import httpx as requests
from httpx import Client as Session
except ImportError:
# noinspection PyUnresolvedReferences, PyPackageRequirements
import requests

# noinspection PyUnresolvedReferences,PyPackageRequirements
from requests import Session

from antarest.core.cache.business.local_chache import LocalCache
from antarest.core.config import CacheConfig
Expand Down Expand Up @@ -48,7 +57,7 @@ def __init__(
session: Optional[Session] = None,
):
self.study_id = study_id
self.session = session or requests.session()
self.session = session or Session()
# TODO fix this
self.session.verify = False
self.host = host
Expand Down

0 comments on commit 2e896d1

Please sign in to comment.