Skip to content

Commit

Permalink
Use a 'User-Agent' header of insta-science/<version>. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois authored Jan 11, 2025
1 parent dc54ea0 commit a434a59
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 14 deletions.
4 changes: 0 additions & 4 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Build artifacts dirs.
/*.egg-info/
/build/

# Python bytecode.
__pycache__/

Expand Down
4 changes: 4 additions & 0 deletions python/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# insta-science

## 0.4.4

Use a 'User-Agent' header of `insta-science/<version>` when fetching URLs.

## 0.4.3

Implement proper HTTP error handling and add retry support in for failed `science` fetches.
Expand Down
2 changes: 1 addition & 1 deletion python/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Version Bump and Changelog

1. Bump the version in [`insta_science/version.py`](insta_science/version.py).
1. Bump the version in [`insta_science/_internal/version.py`](insta_science/_internal/version.py).
2. Run `uv run dev-cmd` as a sanity check on the state of the project.
3. Update [`CHANGES.md`](CHANGES.md) with any changes that are likely to be useful to consumers.
4. Run `uv run dev-cmd -q release -- --dry-run` as a sanity check the release will work once the
Expand Down
2 changes: 1 addition & 1 deletion python/insta_science/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
ScienceExe,
ScienceNotFound,
Url,
__version__,
ensure_installed,
)
from .version import __version__

__all__ = (
"CURRENT_PLATFORM",
Expand Down
2 changes: 2 additions & 0 deletions python/insta_science/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .model import Digest, Science, ScienceExe, Url
from .platform import CURRENT_PLATFORM, Platform
from .science import ensure_installed
from .version import __version__

__all__ = (
"CURRENT_PLATFORM",
Expand All @@ -17,5 +18,6 @@
"ScienceExe",
"ScienceNotFound",
"Url",
"__version__",
"ensure_installed",
)
2 changes: 2 additions & 0 deletions python/insta_science/_internal/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .errors import InputError
from .hashing import Digest, ExpectedDigest, Fingerprint
from .model import Url
from .version import __version__

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -95,6 +96,7 @@ def require_password(auth_type: str) -> str:

def _configured_client(url: Url, headers: Mapping[str, str] | None = None) -> httpx.Client:
headers = dict(headers) if headers else {}
headers.setdefault("User-Agent", f"insta-science/{__version__}")
auth = _configure_auth(url) if "Authorization" not in headers else None
return httpx.Client(follow_redirects=True, headers=headers, auth=auth)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Science project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

__version__ = "0.4.3"
__version__ = "0.4.4"
3 changes: 1 addition & 2 deletions python/insta_science/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

from packaging.version import Version

from . import CURRENT_PLATFORM, InputError, Platform, Science
from . import CURRENT_PLATFORM, InputError, Platform, Science, __version__
from ._internal import a_scie, parser, project, science
from ._internal.bytes import ByteAmount
from ._internal.cache import DownloadCache, download_cache
from ._internal.colors import Colors, color_support
from ._internal.du import DiskUsage
from ._internal.model import Configuration
from .version import __version__


def download(
Expand Down
3 changes: 2 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ insta-science = "insta_science.shim:main"
insta-science-util = "insta_science.util:main"

[tool.setuptools.dynamic]
version = {attr = "insta_science.version.__version__"}
version = {attr = "insta_science._internal.version.__version__"}

[tool.setuptools.packages.find]
where = ["."]
Expand All @@ -71,6 +71,7 @@ dev = [
"pytest",
"pytest-xdist",
"ruff",
"setuptools",
"types-appdirs",
"types-colorama",
"types-tqdm",
Expand Down
39 changes: 39 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2025 Science project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import atexit
import shutil
import tempfile
from pathlib import Path

from setuptools import setup

_BUILD_DIR: Path | None = None


def ensure_unique_build_dir() -> Path:
global _BUILD_DIR
if _BUILD_DIR is None:
_build_dir = Path(tempfile.mkdtemp(prefix="insta-science-dist-build."))
atexit.register(shutil.rmtree, _build_dir, ignore_errors=True)
_BUILD_DIR = _build_dir
return _BUILD_DIR


def unique_build_dir(name) -> str:
path = ensure_unique_build_dir() / name
path.mkdir()
return str(path)


if __name__ == "__main__":
setup(
# The `egg_info --egg-base`, `build --build-base` and `bdist_wheel --bdist-dir` setup.py
# sub-command options we pass below work around the otherwise default `<CWD>/build/`
# directory for all three which defeats concurrency in tests.
options={
"egg_info": {"egg_base": unique_build_dir("egg_base")},
"build": {"build_base": unique_build_dir("build_base")},
"bdist_wheel": {"bdist_dir": unique_build_dir("bdist_dir")},
}
)
35 changes: 31 additions & 4 deletions python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a434a59

Please sign in to comment.