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

Conversation

RichieCahill
Copy link
Contributor

This is a super small pr. I dont think it requires any new tests because of its nature.
Please let me know if I did anything wrong.

@dimitarOnGithub
Copy link

@adehad / @studioj this one looks good to me as-is, but I wonder if the constructor would be a better place for this warning considering it wouldn't be visible until the code attempts to execute the _fetch_pages method? I think it'd be better if the import, along with the assignment of the async_workers and async_class, happens in the constructor itself, that way you get an instant warning that a requirement is missing.

Copy link
Contributor

@adehad adehad left a comment

Choose a reason for hiding this comment

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

Thanks for the initial review @dimitarOnGithub and for the PR @RichieCahill. I think we should tackle this in a more obvious way if possible, I've added some suggestions in the review

jira/client.py Outdated
Comment on lines 580 to 590
try:
from requests_futures.sessions import FuturesSession

options["async_class"] = FuturesSession
except ImportError:
msg = (
"async option requires requests-futures to be installed. "
"falling back to synchronous implementation."
)
warnings.warn(msg)
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to:

  1. do the import check outside the scope of this class, then either set FutureSession as None if it is not imported or have a boolean variable, eg. _has_async_support.
  2. This warning can be emitted in init as you have done if the async option is passed incorrectly.
    Furthermore I would augment this warning message with a suggestion of how to install this extra requirement, as we do have this as an extra, it may be appropriate to say, this can be installed using the 'async' extra, e.g. pip install jira[async]
  3. I would be tempted to modify the option itself to be False and then no further code changes need to be made in the dependency functions.
  4. Code that needs the async may check for the boolean or that the imported class is not None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ive updated the code based on your suggestion. Im unclear on what 3 means.

if (
async_class 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
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?

@RichieCahill RichieCahill marked this pull request as draft July 11, 2024 04:17
@RichieCahill
Copy link
Contributor Author

should we insted of warning if async=true and requests_futures isnt installed just raise an exception

@RichieCahill RichieCahill marked this pull request as ready for review August 3, 2024 14:45
Copy link

github-actions bot commented Sep 4, 2024

Label error. Requires exactly 1 of: bug, enhancement, major, minor, patch, skip-changelog. Found:

@RichieCahill
Copy link
Contributor Author

@adehad please take a look at this pr i have updated parts of it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants