Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a new SessionConfig object to allow advanced configuration of the Downloader #92

Merged
merged 16 commits into from
Jun 10, 2022

Conversation

Cadair
Copy link
Owner

@Cadair Cadair commented Jun 9, 2022

This PR introduces breaking API changes, it will form a 2.0 release of parfive.

fixes #38
fixes #29

This PR is motivated by the fact that we have been slowly growing more and more keyword arguments, environment variables etc at various levels in the class.

This PR cleans up the environment variable handling and keyword arguments to the main Downloader class by making a config object which holds the state for the instance. As well as this some of the more obscure keyword arguments are moved into a SessionConfig object.

Changes in this PR

  • A new PARFIVE_HIDE_PROGRESS environment variable will disable all progress bars.
  • The file_progress=, use_aiofiles= and notebook= keyword arguments have been moved into the new SessionConfig object which can be passed to Downloader() as the config= keyword argument.
  • The headers= keyword argument to Downloader() is now deprecated in favour of passing them as part of the SessionConfig object. They will be removed in a future release.
  • All environment variables are now evaluated at the time the Downloader class is instantiated (by the new config classes).
  • The value of the boolean environment variables now matter, they should cast to True.
  • The timeouts keyword argument has been removed from the run_download() and download() methods and replaced by an option in SessionConfig.
  • It is now possible to configure the options passed to aiohttp.ClientSession with the aiohttp_session_kwargs= keyword argument to SessionConfig.
  • It is now possible to configure debug or other levels of logging with SessionConifg where previously it could only be configured with an environment variable.
  • It is now possible to configure the HTTP chunksize with SessionConfig and the default when not using aiofiles has been increased from 100 bytes to 1024 bytes.
  • It is now possible to configure the HTTP(S) proxy URLs with SessionConfig as well as the HTTP[S]_PROXY environment variables.
  • It is now possible to customise all the timeouts supported by aiohttp by passing an aiohttp.ClientTimeout object to SessionConfig.

@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #92 (106d5c2) into main (c52cbe3) will increase coverage by 0.84%.
The diff coverage is 97.81%.

@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   92.48%   93.33%   +0.84%     
==========================================
  Files           4        5       +1     
  Lines         466      540      +74     
==========================================
+ Hits          431      504      +73     
- Misses         35       36       +1     
Impacted Files Coverage Δ
parfive/downloader.py 93.26% <95.34%> (-0.41%) ⬇️
parfive/config.py 98.87% <98.87%> (ø)
parfive/utils.py 94.54% <100.00%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c52cbe3...106d5c2. Read the comment docs.

@Cadair Cadair changed the title Unravel the API Add a new SessionConfig object to allow advanced configuration of the Downloader Jun 10, 2022
@Cadair Cadair marked this pull request as ready for review June 10, 2022 10:36
@Cadair
Copy link
Owner Author

Cadair commented Jun 10, 2022

I am going to ping people who have contributed to see if anyone wants to comment on this PR, and give people a chance to ask for tweaks before I push a major release.

@GitHK @rlaker @nabobalis @dstansby

@@ -38,6 +38,9 @@ stages:
- linux: build_docs
pytest: false

- linux: mypy
Copy link
Contributor

Choose a reason for hiding this comment

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

mypy has pre-commit hooks if you want to avoid adding another job here: https://github.com/pre-commit/mirrors-mypy

Copy link
Contributor

Choose a reason for hiding this comment

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

You could have both. It usually helps.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I only didn't put it in the pre-commit because mypy can be a little slow to run (and there wasn't any mention of the pre-commit in mypy's docs).

Copy link
Owner Author

Choose a reason for hiding this comment

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

Also I in general prefer using pre-commit for stuff which autofixes, especially with the pre-commit ci service autofixing now.

Copy link
Contributor

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

I got a bit bored reviewing this, sorry, but hopefully what I've left are some very minor but helpful comments...

parfive/config.py Outdated Show resolved Hide resolved
parfive/config.py Outdated Show resolved Hide resolved
Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

The refactoring is looking good.

I would only suggest to use a library more suited to handling env vars than manually parsing them. I've suggested pydantic below.

@@ -38,6 +38,9 @@ stages:
- linux: build_docs
pytest: false

- linux: mypy
Copy link
Contributor

Choose a reason for hiding this comment

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

You could have both. It usually helps.

parfive/config.py Outdated Show resolved Hide resolved
@Cadair
Copy link
Owner Author

Cadair commented Jun 10, 2022

Thanks for the review @GitHK, are you using the use_aiofiles= kwarg to Downloader? Would removing it cause you trouble?

@GitHK
Copy link
Contributor

GitHK commented Jun 10, 2022

Thanks for the review @GitHK, are you using the use_aiofiles= kwarg to Downloader? Would removing it cause you trouble?

No issue for me. Go ahead and remove it. We usually do periodic updates and fix these small issues.
It helps a lot when libraries point breaking changes in the changelog, upgrades are much smoother.

@Cadair
Copy link
Owner Author

Cadair commented Jun 10, 2022

@GitHK Thanks! I have pulled it now, I am going to keep headers around for people using previous versions of sunpy.

@Cadair Cadair added the breaking A Breaking change label Jun 10, 2022
@Cadair Cadair merged commit 0664d03 into main Jun 10, 2022
@Cadair Cadair deleted the api_refactor branch June 10, 2022 15:23
@Cadair
Copy link
Owner Author

Cadair commented Jun 10, 2022

I have pushed 2.0.0rc1 up to PyPI if people want to test this and open any issues.

@@ -36,6 +36,7 @@
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx_autodoc_typehints", # must be loaded after napoleon
Copy link
Contributor

Choose a reason for hiding this comment

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

How well does this work?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I have only used it in two small libraries, this one and dkist and so far very happy.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about if we used this for a bigger library that starts with the letter s?

@nabobalis
Copy link
Contributor

nabobalis commented Jun 10, 2022

Overall:

👍 on pydantic, such a great library.
👍 on the config refactor, makes things much clearer in the main downloader code.
👎 on adding type hints and using black.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
breaking A Breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Review and improve documentation of arguments Support HTTP Basic Auth
4 participants