Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8d680b1
appctx
JHopeCollins Jul 17, 2025
321fefa
Merge branch 'main' into JHopeCollins/appctx
JHopeCollins Aug 18, 2025
54cd6db
AppContext in __init__
JHopeCollins Aug 18, 2025
4604f3d
Merge branch 'main' into JHopeCollins/appctx
JHopeCollins Aug 27, 2025
c7e366a
Hide AppContext internal keys from user
JHopeCollins Aug 27, 2025
913eb56
updates
JHopeCollins Aug 27, 2025
cfe9954
appctx docstrings
JHopeCollins Aug 28, 2025
ec9c900
test appctx
JHopeCollins Aug 28, 2025
0a4ba8f
tidy up appctx keygen
JHopeCollins Aug 28, 2025
8104028
review comments - hide key from user completely
JHopeCollins Sep 3, 2025
d231b36
move import to top of test file
JHopeCollins Sep 3, 2025
36587cc
Update petsctools/appctx.py
JHopeCollins Sep 4, 2025
3c1b6cf
appctx: hide key_from_option from user.
JHopeCollins Sep 4, 2025
5975b82
global appctx stack
JHopeCollins Sep 10, 2025
d51cd25
numpy import inside test
JHopeCollins Sep 10, 2025
0c54caa
Merge branch 'main' into JHopeCollins/appctx
JHopeCollins Apr 22, 2026
3e7928b
use petsc.vec.norm rather than numpy.allclose for test
JHopeCollins Apr 22, 2026
660475a
trailing whitespace
JHopeCollins Apr 28, 2026
e042462
attach the appctx directly to the OptionsManager
JHopeCollins Apr 28, 2026
ffb03ef
Separate global AppContext and scoped AppContextManager
JHopeCollins Apr 29, 2026
f893063
AppContext()[option] = value?
JHopeCollins Apr 29, 2026
65f166a
make the AppContextKey a helpfully named string
JHopeCollins Apr 29, 2026
b66867e
appctx demo
JHopeCollins May 12, 2026
814967f
numpy for tests and demos
JHopeCollins May 12, 2026
813504c
tidy up appctx demo
JHopeCollins May 12, 2026
e1d3597
appctx exception
JHopeCollins May 12, 2026
f0d6db2
lint
JHopeCollins May 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions petsctools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .exceptions import PetscToolsException # noqa: F401
from .options import flatten_parameters # noqa: F401
from .utils import PETSC4PY_INSTALLED
from .appctx import AppContext
Comment thread
JHopeCollins marked this conversation as resolved.
Outdated

# Now conditionally import the functions that depend on petsc4py. If petsc4py
# is not available then attempting to access these attributes will raise an
Expand Down
28 changes: 28 additions & 0 deletions petsctools/appctx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import itertools


class AppContext:
Comment thread
connorjward marked this conversation as resolved.
def __init__(self):
self._count = itertools.count()
self._data = {}
self._missing_key = next(self._count)

@property
def missing_key(self):
return self._missing_key

def insert(self, val):
key = next(self._count)
self._data[key] = val
return key

def __getitem__(self, key):
return self._data[key]

def get(self, key, default=None):
if key == self.missing_key:
Comment thread
JHopeCollins marked this conversation as resolved.
Outdated
return default
return self._data.get(key, default=default)

def values(self):
return self._data.values()
Comment thread
JHopeCollins marked this conversation as resolved.
Outdated
Loading