Skip to content

Commit

Permalink
Chain user agent (#94)
Browse files Browse the repository at this point in the history
* Fix multi-user-agent

This repo now has its own private class Archivist which is
the datatrails-python Archivist class but with user agent
set correctly.

AB#9572
  • Loading branch information
eccles authored Jul 11, 2024
1 parent 9d1a5d9 commit a91fa96
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ COPY requirements.txt requirements-dev.txt /tmp/
# (generated by 'task wheel') from that repo and uncomment
# the following lines. Also comment out the datatrails-archivist line in
# requirements.txt.
# cp ~/git/datatrails-python/dist/*.whl .
# That way one can test an unreleased version of github datatrails-samples.
# NB dont forget to recomment before merging !!
#COPY datatrails*.whl /tmp/
#RUN python3 -m pip -qq install /tmp/datatrails*.whl \
# && rm -f /tmp/datatrails*.whl
# COPY datatrails*.whl /tmp/
# RUN python3 -m pip -qq install /tmp/datatrails*.whl \
# && rm -f /tmp/datatrails*.whl

RUN python3 -m pip -qq install --upgrade pip \
&& python3 -m pip -qq install -r /tmp/requirements-dev.txt \
Expand Down
16 changes: 16 additions & 0 deletions archivist_samples/archivist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Local Archivist class
"""

# pylint: disable=missing-docstring
# pylint: disable=too-few-public-methods

from archivist.archivist import Archivist as _Archivist

from .about import __version__ as VERSION
from .constants import USER_AGENT_PREFIX


class Archivist(_Archivist):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_agent = f"{USER_AGENT_PREFIX}{VERSION}"
2 changes: 1 addition & 1 deletion archivist_samples/c2pa/c2pa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..testing.assets import make_assets_create, AttachmentDescription

if TYPE_CHECKING:
from archivist.archivist import Archivist
from ..archivist import Archivist

LOGGER = logging.getLogger(__name__)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion archivist_samples/document/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..testing.assets import make_assets_create, AttachmentDescription

if TYPE_CHECKING:
from archivist.archivist import Archivist
from ..archivist import Archivist

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion archivist_samples/sbom_document/software_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sys import exit as sys_exit
from typing import List, Optional

from archivist import archivist as type_helper
from .. import archivist as type_helper

from ..testing.assets import make_assets_create, AttachmentDescription

Expand Down
6 changes: 2 additions & 4 deletions archivist_samples/testing/archivist_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import logging
from sys import exit as sys_exit

from archivist.archivist import Archivist
from archivist.logger import set_logger

from ..about import __version__ as VERSION
from .constants import USER_AGENT_PREFIX
from ..archivist import Archivist

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -114,11 +112,11 @@ def endpoint(args):
args.url,
authtoken,
partner_id=args.partner_id,
user_agent=f"{USER_AGENT_PREFIX}{VERSION}",
)

if arch is None:
LOGGER.error("Critical error. Aborting.")
sys_exit(1)

LOGGER.info("User agent is %s", arch.user_agent)
return arch
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pyyaml~=6.0.1
# the following lines. Also do similar in the Dockerfile.
# That way one can test an unreleased version of github datatrails-samples.
# NB dont forget to uncomment before merging !!
datatrails-archivist==0.31.2
datatrails-archivist==0.31.3

0 comments on commit a91fa96

Please sign in to comment.