Skip to content

Commit a91fa96

Browse files
authored
Chain user agent (#94)
* 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
1 parent 9d1a5d9 commit a91fa96

8 files changed

Lines changed: 26 additions & 11 deletions

File tree

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ COPY requirements.txt requirements-dev.txt /tmp/
77
# (generated by 'task wheel') from that repo and uncomment
88
# the following lines. Also comment out the datatrails-archivist line in
99
# requirements.txt.
10+
# cp ~/git/datatrails-python/dist/*.whl .
1011
# That way one can test an unreleased version of github datatrails-samples.
1112
# NB dont forget to recomment before merging !!
12-
#COPY datatrails*.whl /tmp/
13-
#RUN python3 -m pip -qq install /tmp/datatrails*.whl \
14-
# && rm -f /tmp/datatrails*.whl
13+
# COPY datatrails*.whl /tmp/
14+
# RUN python3 -m pip -qq install /tmp/datatrails*.whl \
15+
# && rm -f /tmp/datatrails*.whl
1516

1617
RUN python3 -m pip -qq install --upgrade pip \
1718
&& python3 -m pip -qq install -r /tmp/requirements-dev.txt \

archivist_samples/archivist.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Local Archivist class
2+
"""
3+
4+
# pylint: disable=missing-docstring
5+
# pylint: disable=too-few-public-methods
6+
7+
from archivist.archivist import Archivist as _Archivist
8+
9+
from .about import __version__ as VERSION
10+
from .constants import USER_AGENT_PREFIX
11+
12+
13+
class Archivist(_Archivist):
14+
def __init__(self, *args, **kwargs):
15+
super().__init__(*args, **kwargs)
16+
self.user_agent = f"{USER_AGENT_PREFIX}{VERSION}"

archivist_samples/c2pa/c2pa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from ..testing.assets import make_assets_create, AttachmentDescription
2222

2323
if TYPE_CHECKING:
24-
from archivist.archivist import Archivist
24+
from ..archivist import Archivist
2525

2626
LOGGER = logging.getLogger(__name__)
2727

archivist_samples/document/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from ..testing.assets import make_assets_create, AttachmentDescription
2222

2323
if TYPE_CHECKING:
24-
from archivist.archivist import Archivist
24+
from ..archivist import Archivist
2525

2626
LOGGER = logging.getLogger(__name__)
2727

archivist_samples/sbom_document/software_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sys import exit as sys_exit
1515
from typing import List, Optional
1616

17-
from archivist import archivist as type_helper
17+
from .. import archivist as type_helper
1818

1919
from ..testing.assets import make_assets_create, AttachmentDescription
2020

archivist_samples/testing/archivist_parser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
import logging
1414
from sys import exit as sys_exit
1515

16-
from archivist.archivist import Archivist
1716
from archivist.logger import set_logger
1817

19-
from ..about import __version__ as VERSION
20-
from .constants import USER_AGENT_PREFIX
18+
from ..archivist import Archivist
2119

2220
LOGGER = logging.getLogger(__name__)
2321

@@ -114,11 +112,11 @@ def endpoint(args):
114112
args.url,
115113
authtoken,
116114
partner_id=args.partner_id,
117-
user_agent=f"{USER_AGENT_PREFIX}{VERSION}",
118115
)
119116

120117
if arch is None:
121118
LOGGER.error("Critical error. Aborting.")
122119
sys_exit(1)
123120

121+
LOGGER.info("User agent is %s", arch.user_agent)
124122
return arch

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pyyaml~=6.0.1
77
# the following lines. Also do similar in the Dockerfile.
88
# That way one can test an unreleased version of github datatrails-samples.
99
# NB dont forget to uncomment before merging !!
10-
datatrails-archivist==0.31.2
10+
datatrails-archivist==0.31.3

0 commit comments

Comments
 (0)