Skip to content

Set user agent header when making API requests #17

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

Merged
merged 1 commit into from
May 27, 2022
Merged

Conversation

zeke
Copy link
Member

@zeke zeke commented May 19, 2022

The user agent for requests from this library are currently defaulting to something like python-requests/2.27.1. This PR updates the client to set a user agent header in the form replicate-python@<version>, so we can more easily identify where our API traffic is coming from.

@zeke zeke requested a review from bfirsh May 19, 2022 22:18
@zeke
Copy link
Member Author

zeke commented May 19, 2022

Hmm. This worked locally but I guess putting the version in the replicate directory won't work because then setup tries to load replicate/__init__.py?

Looks like there a ton of hacky ways to get around this.. not sure which one is least offensive.

@zeke zeke requested a review from evilstreak May 19, 2022 22:24
@zeke zeke requested a review from bfirsh May 19, 2022 23:41
@bfirsh
Copy link
Member

bfirsh commented May 20, 2022

We also probably want to set __version__ = package_version in replicate/__init__.py. That's a standard location for Python package versions.

@zeke
Copy link
Member Author

zeke commented May 20, 2022

Like this? 5aa9b3f

@bfirsh
Copy link
Member

bfirsh commented May 20, 2022

Nope -- you can just do from .package_version import package_version.

@zeke
Copy link
Member Author

zeke commented May 25, 2022

Ah I see. It's only setup.py that can't safely do import.

@zeke zeke force-pushed the set-user-agent branch 3 times, most recently from 6d37bff to 1ff3570 Compare May 25, 2022 20:26
@zeke
Copy link
Member Author

zeke commented May 25, 2022

This is ready for another look.

@bfirsh
Copy link
Member

bfirsh commented May 25, 2022

As an aside package_version is a bit weird -- I've never seen that before. It's either in package/__init__.py or in package/version.py.

We could move the other version.py out of the way (into models/?) or rename to _version.py.

This pattern's rather nice, with __about__.py:

https://github.com/pypa/warehouse/blob/64ca42e42d5613c8339b3ec5e1cb7765c6b23083/warehouse/__about__.py
https://github.com/pypa/warehouse/blob/64ca42e42d5613c8339b3ec5e1cb7765c6b23083/warehouse/__init__.py

We'll also want to rename package_version = ... in the file to __version__ = ... so we can import it directly.

Signed-off-by: Zeke Sikelianos <zeke@sikelianos.com>

make package version importable

Signed-off-by: Zeke Sikelianos <zeke@sikelianos.com>

get package version by reading and executing the version file

Signed-off-by: Zeke Sikelianos <zeke@sikelianos.com>

set __version__

Signed-off-by: Zeke Sikelianos <zeke@sikelianos.com>

Update __init__.py

Signed-off-by: Zeke Sikelianos <zeke@sikelianos.com>

use __about__

Signed-off-by: Zeke Sikelianos <zeke@sikelianos.com>
@zeke zeke force-pushed the set-user-agent branch from b1b63a2 to c73c2d8 Compare May 27, 2022 21:13
@zeke
Copy link
Member Author

zeke commented May 27, 2022

Updated it to use __about__. This is ready for another look.

@zeke zeke requested a review from bfirsh May 27, 2022 21:15
@bfirsh
Copy link
Member

bfirsh commented May 27, 2022

Marvellous!

@bfirsh bfirsh merged commit 6ffed38 into main May 27, 2022
@bfirsh bfirsh deleted the set-user-agent branch May 27, 2022 21:16
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.

2 participants