Skip to content

Commit

Permalink
Revert some requests import changes
Browse files Browse the repository at this point in the history
introduced in #18003 .
In particular, when using requests in the tests to connect to Galaxy
or the ToolShed it's not needed to use the modified headers.

Also:
- Move some imports after conditional imports.
- Fix type annotations in `lib/tool_shed/test/base/populators.py`
- Fix typo bug in `test/unit/util/test_get_url.py`
  • Loading branch information
nsoranzo committed May 22, 2024
1 parent 6e7160b commit 3188d25
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 43 deletions.
1 change: 0 additions & 1 deletion lib/galaxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
build_tours_registry,
ToursRegistry,
)
from galaxy.util import user_agent # noqa: F401
from galaxy.util import (
ExecutionTimer,
heartbeat,
Expand Down
1 change: 0 additions & 1 deletion lib/galaxy/tools/data_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
stream_to_file,
stream_url_to_file,
)
from galaxy.util import user_agent # noqa: F401
from galaxy.util import (
in_directory,
safe_makedirs,
Expand Down
8 changes: 5 additions & 3 deletions lib/galaxy/tools/error_reports/plugins/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import os
import urllib.parse

from galaxy.util import requests

try:
import gitlab
except ImportError:
gitlab = None
from galaxy.util import string_as_bool

from galaxy.util import (
requests,
string_as_bool,
)
from .base_git import BaseGitPlugin

log = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
Self,
)

from galaxy.util import requests

try:
import grp
except ImportError:
Expand Down Expand Up @@ -125,6 +123,7 @@ def XML(text: Union[str, bytes]) -> Element:
XML,
)

from . import requests
from .custom_logging import get_logger
from .inflection import Inflector
from .path import ( # noqa: F401
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy_test/api/test_drs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
urlparse,
)

import requests

from galaxy.files import (
ConfiguredFileSources,
DictFileSourcesUserContext,
Expand All @@ -18,7 +20,6 @@
fetch_drs_to_file,
RetryOptions,
)
from galaxy.util import requests
from galaxy.util.config_parsers import parse_allowlist_ips
from galaxy_test.base.populators import DatasetPopulator
from ._framework import ApiTestCase
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from unittest import SkipTest

import pytest
import requests
from dateutil.parser import isoparse

from galaxy.util import requests
from galaxy_test.api.test_tools import TestsTools
from galaxy_test.base.api_asserts import assert_status_code_is_ok
from galaxy_test.base.populators import (
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/base/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
)

import pytest
import requests
from typing_extensions import Protocol

from galaxy.util import requests
from galaxy.util.properties import get_from_env
from .api_asserts import (
assert_error_code_is,
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from uuid import UUID

import cwltest.compare
import requests
import yaml
from bioblend.galaxyclient import GalaxyClient
from gxformat2 import (
Expand Down Expand Up @@ -98,7 +99,6 @@
from galaxy.util import (
DEFAULT_SOCKET_TIMEOUT,
galaxy_root_path,
requests,
UNKNOWN,
)
from galaxy.util.resources import resource_string
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy_test/selenium/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TYPE_CHECKING,
)

import requests
import yaml
from gxformat2 import (
convert_and_import_workflow,
Expand All @@ -38,7 +39,6 @@
asbool,
classproperty,
DEFAULT_SOCKET_TIMEOUT,
requests,
)
from galaxy.util.unittest_utils import skip_if_github_down
from galaxy_test.base import populators
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/test/base/api_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
)
from urllib.parse import urljoin

import requests
from typing_extensions import Literal

from galaxy.util import requests
from galaxy_test.base.api_asserts import (
assert_has_keys,
assert_status_code_is,
Expand Down
6 changes: 3 additions & 3 deletions lib/tool_shed/test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
Union,
)

import requests
from typing_extensions import Protocol

from galaxy.util import requests
from galaxy.util.resources import (
as_file,
resource_path,
Expand Down Expand Up @@ -189,7 +189,7 @@ def get_install_info(self, repository_metadata: RepositoryMetadata) -> InstallIn
api_asserts.assert_status_code_is_ok(revisions_response)
return from_legacy_install_info(revisions_response.json())

def update_column_maker_repo(self, repository: HasRepositoryId) -> requests.Response:
def update_column_maker_repo(self, repository: HasRepositoryId) -> RepositoryUpdate:
response = self.upload_revision(
repository,
COLUMN_MAKER_1_1_1_PATH,
Expand All @@ -211,7 +211,7 @@ def upload_revision_raw(

def upload_revision(
self, repository: HasRepositoryId, path: Traversable, commit_message: str = DEFAULT_COMMIT_MESSAGE
):
) -> RepositoryUpdate:
response = self.upload_revision_raw(repository, path, commit_message=commit_message)
if response.status_code != 200:
response_json = None
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/test/base/twilltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)

import pytest
import requests
from mercurial import (
commands,
hg,
Expand Down Expand Up @@ -52,7 +53,6 @@
from galaxy.tool_shed.util.repository_util import check_for_updates
from galaxy.util import (
DEFAULT_SOCKET_TIMEOUT,
requests,
smart_str,
)
from galaxy_test.base.api_asserts import assert_status_code_is_ok
Expand Down
3 changes: 1 addition & 2 deletions scripts/api/fetch_to_library.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import argparse
import json

import requests
import yaml

from galaxy.util import requests


def main():
parser = argparse.ArgumentParser(description="Upload a directory into a data library")
Expand Down
2 changes: 1 addition & 1 deletion scripts/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import sys

from galaxy.util import requests
import requests


class RemoteGalaxy:
Expand Down
9 changes: 1 addition & 8 deletions scripts/api/upload_to_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
import os
import sys

try:
from galaxy.util import requests
except ImportError:
print(
"Could not import the requests module. See http://docs.python-requests.org/en/latest/"
" or install with 'pip install requests'"
)
raise
import requests


def upload_file(base_url, api_key, history_id, filepath, **kwargs):
Expand Down
3 changes: 1 addition & 2 deletions scripts/resumable_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import os

import click
import requests
from tusclient import client
from tusclient.storage import filestorage

from galaxy.util import requests

UPLOAD_ENDPOINT = "/api/upload/resumable_upload"
SUBMISSION_ENDPOINT = "/api/tools/fetch"
CHUNK_SIZE = 10**7
Expand Down
2 changes: 1 addition & 1 deletion scripts/tool_shed/api/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from galaxy.util import requests
import requests


def delete(api_key, url, data, return_formatted=True):
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_interactivetools_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
)

import pytest
import requests

from galaxy.util import requests
from galaxy_test.base import api_asserts
from galaxy_test.base.populators import (
DatasetPopulator,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_job_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tempfile
from typing import Dict

import requests
from sqlalchemy import select
from tusclient import client

Expand All @@ -28,7 +29,6 @@
ensure_object_added_to_session,
transaction,
)
from galaxy.util import requests
from galaxy_test.base import api_asserts
from galaxy_test.base.populators import DatasetPopulator
from galaxy_test.driver import integration_util
Expand Down
2 changes: 1 addition & 1 deletion test/unit/tool_shed/test_shed_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from io import BytesIO

import pytest
import requests
from whoosh import index

from galaxy.util import requests
from tool_shed.util.shed_index import build_index

URL = "https://github.com/mvdbeek/toolshed-test-data/blob/master/toolshed_community_files.tgz?raw=true"
Expand Down
8 changes: 3 additions & 5 deletions test/unit/util/test_get_url.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pytest
import responses
import requests
from werkzeug.wrappers.response import Response

from galaxy.util import (
requests,
url_get,
)
from galaxy.util import url_get


@responses.activate
Expand All @@ -29,7 +27,7 @@ def test_get_url_retry_after(httpserver):
attempts = []

def retry_handler(request):
attempts.append(requests)
attempts.append(request)
if len(attempts) < 4:
return Response("try again later", status=429, content_type="text/plain")
else:
Expand Down
6 changes: 2 additions & 4 deletions test/unit/webapps/test_client_disconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
from typing import Optional

import pytest
import requests
import uvicorn
from fastapi import status
from fastapi.applications import FastAPI
from requests import ReadTimeout
from starlette.middleware.base import BaseHTTPMiddleware

from galaxy.util import (
requests,
sockets,
)
from galaxy.util import sockets

error_encountered: Optional[str] = None

Expand Down

0 comments on commit 3188d25

Please sign in to comment.