-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add version file and include in HTTP request user-agent (#21)
- Created a version file to store the current SDK version - Enhanced HTTP requests to include SDK version, language, and system version in the user-agent header - Improved traceability and debugging with detailed user-agent information in requests
- Loading branch information
Showing
7 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
.idea/ | ||
.venv/ | ||
.DS_Store | ||
__pycache__/ | ||
dist/ | ||
debug.* | ||
.env | ||
.env_private | ||
scripts/ | ||
scripts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import platform | ||
import sys | ||
from functools import lru_cache | ||
|
||
VERSION = "0.1.1" | ||
|
||
|
||
@lru_cache(maxsize=1) | ||
def user_agent(): | ||
print("调用了") | ||
python_version = ".".join(map(str, sys.version_info[:2])) | ||
|
||
os_name = platform.system().lower() | ||
if os_name == "darwin": | ||
os_name = "macos" | ||
|
||
if os_name == "macos": | ||
os_version = platform.mac_ver()[0] | ||
elif os_name == "windows": | ||
os_version = platform.win32_ver()[0] | ||
elif os_name == "linux": | ||
try: | ||
import distro | ||
|
||
os_version = distro.version(pretty=False, best=True) | ||
except ImportError: | ||
os_version = platform.release() | ||
else: | ||
os_version = platform.release() | ||
|
||
return f"cozepy/{VERSION} python/{python_version} {os_name}/{os_version}".lower() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from cozepy import VERSION | ||
from cozepy.version import user_agent | ||
|
||
|
||
def test_user_agent(): | ||
res = user_agent() | ||
assert f"cozepy/{VERSION}" in res | ||
assert "python" in res |