Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding warning when requests_futures isnt installed #1863

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
except ImportError:
pass

try:
from requests_futures.sessions import FuturesSession
except ImportError:
FuturesSession = None
pass


LOG = _logging.getLogger("jira")
LOG.addHandler(_logging.NullHandler())
Expand Down Expand Up @@ -571,7 +577,16 @@ def __init__(

if server:
options["server"] = server

if async_:
if FuturesSession is None:
msg = (
"async option requires requests-futures to be installed. "
"falling back to synchronous implementation.\n"
"to enable async, install the 'async' extra, e.g. pip install jira[async]"
)
warnings.warn(msg)

options["async"] = async_
options["async_workers"] = async_workers

Expand Down Expand Up @@ -789,16 +804,6 @@ def _fetch_pages(
Returns:
ResultList
"""
async_workers = None
async_class = None
if self._options["async"]:
try:
from requests_futures.sessions import FuturesSession

async_class = FuturesSession
except ImportError:
pass
async_workers = self._options.get("async_workers")

def json_params() -> dict[str, Any]:
# passing through json.dumps and json.loads ensures json
Expand Down Expand Up @@ -847,13 +852,15 @@ def json_params() -> dict[str, Any]:
)
page_start = (startAt or start_at_from_response or 0) + page_size
if (
async_class is not None
self._options["async"]
and FuturesSession is not None
and not is_last
and (total is not None and len(items) < total)
):
async_fetches = []
future_session = async_class(
session=self._session, max_workers=async_workers
future_session = FuturesSession(
session=self._session,
max_workers=self._options["async_workers"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to preserve the original code I would suggest keep this as

Suggested change
max_workers=self._options["async_workers"],
max_workers=self._options.get("async_workers"),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what value dose preserve the original code add in this case?

)
for start_index in range(page_start, total, page_size):
page_params = json_params()
Expand All @@ -875,7 +882,7 @@ def json_params() -> dict[str, Any]:
)
items.extend(next_items_page)
while (
async_class is None
not self._options["async"]
and not is_last
and (total is None or page_start < total)
and len(next_items_page) == page_size
Expand Down
Loading