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

use python package-specific "user agent" string #665

Merged
merged 2 commits into from Oct 9, 2023

Conversation

melange396
Copy link
Contributor

closes #660

@melange396
Copy link
Contributor Author

@capnrefsmmat thoughts?

@capnrefsmmat
Copy link
Contributor

Seems reasonable to me. I had considered putting the version information in the user-agent previously, but didn't know how to get the version information without hardcoding it in a constant somewhere.

@@ -7,12 +7,22 @@
import pandas as pd
import numpy as np
from delphi_epidata import Epidata
from delphi_epidata.delphi_epidata import _HEADERS
from pkg_resources import get_distribution, DistributionNotFound
Copy link
Collaborator

Choose a reason for hiding this comment

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

I couldn't find documentation for pkg_resources. My guess is it comes from setuptools which is being deprecated.

Maybe use importlib.metadata to future-proof? From docs:

importlib.metadata is a library that provides access to the metadata of an installed Distribution Package, such as its entry points or its top-level names (Import Packages, modules, if any). Built in part on Python’s import system, this library intends to replace similar functionality in the entry point API and metadata API of pkg_resources. Along with importlib.resources, this package can eliminate the need to use the older and less efficient pkg_resources package.

> import pkg_resources
> import importlib.metadata
> print(pkg_resources.get_distribution('wheel'))
> print(importlib.metadata.version('wheel'))
wheel 0.41.2
0.41.2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I shamelessly stole the version determination code from the delphi-epidata python client (that this client depends on): https://github.com/cmu-delphi/delphi-epidata/blob/d42517e714d6d1deebb6cffcdf3fb5adadc54481/src/client/delphi_epidata.py#L17-L25

I dont see where setuptools (as a whole) is being deprecated, but pkg_resources did get marked as such about half a year ago... But before we rush into yanking it out: importlib.metadata requires python3.8 or a fancy requirements directive to pull in its backport, so its not such a simple drop-in replacement. There are also two other files in this repo that already use pkg_resources (

and ), plus one in covidcast-indicators (https://github.com/cmu-delphi/covidcast-indicators/blob/39c02fa228fcb4de2b3f3d19469e862861351a18/_delphi_utils_python/delphi_utils/geomap.py#L15) as well as the aforementioned delphi-epidata client.

Lets kick this down the road a bit -- ill make GH issues to remove pkg_resources in each of the 3 repos.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it, thanks for the clarifications. Not super critical as Python packaging evolves super slowly, so makes sense to just stay consistent with our other code.

# Point API requests to the default endpoint
Epidata.BASE_URL = "https://api.covidcast.cmu.edu/epidata"
Epidata.BASE_URL = "https://api.covidcast.cmu.edu/epidata/api.php"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
Epidata.BASE_URL = "https://api.covidcast.cmu.edu/epidata/api.php"
Epidata.BASE_URL = "https://api.covidcast.cmu.edu/epidata"

whoops, i mustve edited the wrong version of the file which got api.php back into the BASE_URL

@melange396 melange396 merged commit 5f3990e into rzatserkovnyi/api-php-refactor Oct 9, 2023
1 check passed
@melange396 melange396 deleted the distinct-user-agent branch October 9, 2023 21:19
melange396 added a commit that referenced this pull request Oct 12, 2023
* Remove usage of PHP alias in the Python client

* Bump version

* Update Python-packages/covidcast-py/setup.py

* use python package-specific "user agent" string (#665)

* Deprecate _async_fetch_epidata & update docs

* Update changelog, re-regenerate docs

* Handle deprecation warning in tests

---------

Co-authored-by: melange396 <george.haff@gmail.com>
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.

None yet

3 participants