Skip to content

Commit 8475d3a

Browse files
committed
packaging, tests: reuse webutil.testutil
and other packaging tweaks
1 parent 7017bad commit 8475d3a

21 files changed

Lines changed: 134 additions & 177 deletions

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ python:
1414
path: .
1515
extra_requirements:
1616
- datastore
17+
- docs
1718
- flask
18-
- requirements: docs/requirements.txt
1919

2020
sphinx:
2121
configuration: docs/conf.py

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,10 @@ Here's how to package, test, and ship a new release.
373373
```
374374
1. Run the unit tests.
375375
```sh
376-
source local/bin/activate.csh
376+
source .venv/bin/activate.csh
377377
python -m unittest discover
378-
python -m unittest arroba.tests.mst_test_suite # more extensive, slower tests (deliberately excluded from autodiscovery)
379378
```
380379
1. Bump the version number in `pyproject.toml` and `docs/conf.py`. `git grep` the old version number to make sure it only appears in the changelog. Change the current changelog entry in `README.md` for this new version from _unreleased_ to the current date.
381-
1. Bump the version specifiers in `pyproject.toml` for `pywebutil`, `lexrpc`, and any other relevant dependencies to their most recent versions.
382380
1. Build the docs. If you added any new modules, add them to the appropriate file(s) in `docs/source/`. Then run `./docs/build.sh`. Check that the generated HTML looks fine by opening `docs/_build/html/index.html` and looking around.
383381
1. ```sh
384382
setenv ver X.Y
@@ -387,16 +385,15 @@ Here's how to package, test, and ship a new release.
387385
1. Upload to [test.pypi.org](https://test.pypi.org/) for testing.
388386
```sh
389387
uv build
390-
twine upload -r pypitest dist/arroba-$ver*
388+
twine upload -r pypitest dist/arroba-$ver.tar.gz dist/arroba-$ver-py3-none-any.whl
391389
```
392390
1. Install from test.pypi.org.
393391
```sh
394392
cd /tmp
395-
python -m venv local
396-
source local/bin/activate.csh
393+
python -m venv .venv
394+
source .venv/bin/activate.csh
397395
# make sure we force pip to use the uploaded version
398396
pip uninstall arroba
399-
pip install --upgrade pip
400397
pip install -i https://test.pypi.org/simple --extra-index-url https://pypi.org/simple arroba==$ver
401398
```
402399
1. Smoke test that the code trivially loads and runs.
@@ -414,7 +411,7 @@ Here's how to package, test, and ship a new release.
414411
1. [Click here to draft a new release on GitHub.](https://github.com/snarfed/arroba/releases/new) Enter `vX.Y` in the _Tag version_ box. Leave _Release title_ empty. Copy `### Notable changes` and the changelog contents into the description text box.
415412
1. Upload to [pypi.org](https://pypi.org/)!
416413
```sh
417-
twine upload dist/arroba-$ver*
414+
twine upload dist/dist/arroba-$ver.tar.gz dist/arroba-$ver-py3-none-any.whl
418415
```
419416
1. [Wait for the docs to build on Read the Docs](https://readthedocs.org/projects/arroba/builds/), then check that they look ok.
420417
1. On the [Versions page](https://readthedocs.org/projects/arroba/versions/), check that the new version is active, If it's not, activate it in the _Activate a Version_ section.

arroba/datastore_storage.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from multiformats import CID, multicodec, multihash
2828
from pymediainfo import MediaInfo
2929
from webutil.models import EncryptedProperty, WriteOnceBlobProperty
30+
import webutil.util
3031

3132
from .mst import MST
3233
from .repo import Repo
@@ -433,7 +434,7 @@ class AtpRemoteBlob(ndb.Model):
433434

434435

435436
@classmethod
436-
def get_or_create(cls, *, url=None, repo=None, get_fn=util.session.get,
437+
def get_or_create(cls, *, url=None, repo=None, get_fn=webutil.util.session.get,
437438
max_size=None, accept_types=None, name=''):
438439
"""Returns a new or existing :class:`AtpRemoteBlob` for a given URL.
439440
@@ -497,13 +498,14 @@ def maybe_fetch(self, get_fn=requests.get):
497498
and self.mime_type.split('/')[0] not in BLOB_REFETCH_TYPES):
498499
# already fetched, and we don't refetch this type
499500
return
500-
elif self.last_fetched and self.last_fetched >= util.now() - BLOB_REFETCH_AGE:
501+
elif (self.last_fetched
502+
and self.last_fetched >= webutil.util.now() - BLOB_REFETCH_AGE):
501503
# we've (re)fetched this recently
502504
return
503505

504506
url = self.url or self.key.id()
505507
logger.info(f'(Re)fetching blob URL {url}')
506-
self.last_fetched = util.now()
508+
self.last_fetched = webutil.util.now()
507509

508510
try:
509511
resp = get_fn(url, stream=True)

arroba/did.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import dag_cbor
2727
from multiformats import multibase, multicodec
2828
import requests
29+
from webutil.util import session
2930

3031
from . import util
3132

@@ -71,7 +72,7 @@ def resolve(did, **kwargs):
7172

7273
@cached(TTLCache(maxsize=CACHE_SIZE, ttl=CACHE_TTL.total_seconds()),
7374
lock=threading.Lock())
74-
def resolve_plc(did, get_fn=util.session.get):
75+
def resolve_plc(did, get_fn=session.get):
7576
"""Resolves a ``did:plc`` by fetching its DID document from a PLC directory.
7677
7778
The PLC directory hostname is specified in the ``PLC_HOST`` environment
@@ -111,7 +112,7 @@ def create_plc(handle, **kwargs):
111112
return write_plc(handle=handle, **kwargs)
112113

113114

114-
def update_plc(did, handle=None, get_fn=util.session.get, **kwargs):
115+
def update_plc(did, handle=None, get_fn=session.get, **kwargs):
115116
"""Updates an existing ``did:plc`` in a PLC directory.
116117
117118
Args are documented in :func:`write_plc`.
@@ -140,7 +141,7 @@ def update_plc(did, handle=None, get_fn=util.session.get, **kwargs):
140141

141142
def write_plc(did=None, handle=None, signing_key=None, rotation_key=None,
142143
new_rotation_key=None, pds_url=None, also_known_as=None,
143-
prev=None, get_fn=util.session.get, post_fn=util.session.post):
144+
prev=None, get_fn=session.get, post_fn=session.post):
144145
"""Writes a PLC operation to a PLC directory.
145146
146147
Generally used to create a new ``did:plc`` or update an existing one.
@@ -245,7 +246,7 @@ def _encode_key(key):
245246
return did_plc._replace(signing_key=signing_key, rotation_key=rotation_key)
246247

247248

248-
def write_plc_operation(op, rotation_key, did=None, post_fn=util.session.post):
249+
def write_plc_operation(op, rotation_key, did=None, post_fn=session.post):
249250
"""Signs and sends a PLC operation to the directory.
250251
251252
Args:
@@ -282,7 +283,7 @@ def write_plc_operation(op, rotation_key, did=None, post_fn=util.session.post):
282283

283284

284285
def rollback_plc(did, rotation_key, num_operations=1,
285-
get_fn=util.session.get, post_fn=util.session.post):
286+
get_fn=session.get, post_fn=session.post):
286287
"""Reverts a DID PLC document to its last version.
287288
288289
Reads a did:plc's audit log from the directory, extracts its *previous*
@@ -451,7 +452,7 @@ def plc_operation_to_did_doc(op):
451452

452453
@cached(TTLCache(maxsize=CACHE_SIZE, ttl=CACHE_TTL.total_seconds()),
453454
lock=threading.Lock())
454-
def resolve_web(did, get_fn=util.session.get):
455+
def resolve_web(did, get_fn=session.get):
455456
"""Resolves a ``did:web`` by fetching its DID document.
456457
457458
``did:web`` spec: https://w3c-ccg.github.io/did-method-web/
@@ -483,7 +484,7 @@ def resolve_web(did, get_fn=util.session.get):
483484

484485
@cached(TTLCache(maxsize=CACHE_SIZE, ttl=CACHE_TTL.total_seconds()),
485486
lock=threading.Lock())
486-
def resolve_handle(handle, get_fn=util.session.get):
487+
def resolve_handle(handle, get_fn=session.get):
487488
"""Resolves an ATProto handle to a DID.
488489
489490
Supports the DNS TXT record and HTTPS well-known methods.

arroba/firehose.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import dag_cbor
1919
from google.auth.credentials import AnonymousCredentials
2020
from multiformats import CID
21+
import webutil.util
2122

2223
from .mst import MST
2324
from . import server
@@ -350,7 +351,7 @@ def _collect(self):
350351
last_event = time.time()
351352
header, payload = process_event(event)
352353
did = payload.get('did') or payload.get('repo')
353-
delay_s = int((util.now() - datetime.fromisoformat(payload['time']))\
354+
delay_s = int((webutil.util.now() - datetime.fromisoformat(payload['time']))\
354355
.total_seconds())
355356
logger.info(f'Emitting live to {len(subscribers)} subscribers: {payload["seq"]} {did} {header.get("t")} ({delay_s} s behind)')
356357

arroba/memcache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import time
55

6-
from . import util
6+
import webutil.util
77

88
logger = logging.getLogger(__name__)
99

@@ -63,7 +63,7 @@ def acquire(self):
6363
# False if it already existed
6464
if self.client.add(self.key, 'locked', noreply=False,
6565
expire=int(self.expiration.total_seconds())):
66-
self.expires_at = util.now() + self.expiration
66+
self.expires_at = webutil.util.now() + self.expiration
6767
logger.debug(f'acquired memcache lease {self.key}')
6868
return
6969

@@ -79,7 +79,7 @@ def release(self):
7979
"""Release the lease if we still hold it (hasn't expired)."""
8080
assert self.expires_at
8181

82-
if util.now() <= self.expires_at:
82+
if webutil.util.now() <= self.expires_at:
8383
self.client.delete(self.key)
8484
logger.debug(f'released memcache lease {self.key}')
8585
else:

arroba/storage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import dag_cbor
1414
from multiformats import CID, multicodec, multihash
15+
import webutil.util
1516

1617
from . import mst as mst_mod
1718
from .repo import Write
@@ -108,7 +109,7 @@ def __init__(self, *, cid=None, decoded=None, encoded=None, seq=None,
108109
self._decoded = decoded
109110
self.seq = seq
110111
self.ops = ops
111-
self.time = time or util.now()
112+
self.time = time or webutil.util.now()
112113
self.repo = repo
113114

114115
def __str__(self):
@@ -473,7 +474,7 @@ def write_event(self, repo, type, **kwargs):
473474
'$type': f'com.atproto.sync.subscribeRepos#{type}',
474475
'seq': seq,
475476
'did': repo.did,
476-
'time': util.now().isoformat(),
477+
'time': webutil.util.now().isoformat(),
477478
**kwargs,
478479
}, seq=seq)
479480

0 commit comments

Comments
 (0)