aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/Bucket.py
blob: 61276c75ab0720f46ad4c9de79ba49d076ff2368 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright 2016-2020 Andrew Myers, David Grote, Maxence Thevenet
#
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL

import numpy as np

class Bucket(object):
    """
    The purpose of this class is to be a named bucket for holding attributes.
    This attributes will be concatenated into a string and passed into argv during initialization.
    """
    def __init__(self, instancename, **defaults):
        self._localsetattr('instancename', instancename)
        self._localsetattr('argvattrs', {})
        for name, value in defaults.items():
            self.add_new_attr(name, value)

    def _localsetattr(self, name, value):
        object.__setattr__(self, name, value)

    def add_new_attr(self, name, value):
        """Names starting with "_" are make instance attributes.
        Otherwise the attribute is added to the args list.
        """
        if name.startswith('_'):
            self._localsetattr(name, value)
        else:
            self.argvattrs[name] = value

    def __setattr__(self, name, value):
        self.add_new_attr(name, value)

    def __getattr__(self, name):
        try:
            return self.argvattrs[name]
        except KeyError:
            return object.__getattr__(self, name)

    def check_consistency(self, vname, value, errmsg):
        if vname in self.argvattrs:
            assert (self.argvattrs[vname] is None) or (self.argvattrs[vname] == value), Exception(errmsg)

    def attrlist(self):
        "Concatenate the attributes into a string"
        result = []
        for attr, value in self.argvattrs.items():
            if value is None:
                continue
            # --- repr is applied to value so that for floats, all of the digits are included.
            # --- The strip is then needed when value is a string.
            if isinstance(value, str):
                rhs = value
            elif np.iterable(value):
                if len(value) == 0:
                    # --- Skip if empty
                    continue
                # --- For lists, tuples, and arrays make a space delimited string of the values.
                # --- The lambda is needed in case this is a list of strings.
                rhs = ' '.join(map(lambda s : repr(s).strip("'\""), value))
            elif isinstance(value, bool):
                rhs = 1 if value else 0
            else:
                rhs = value
            attrstring = '{0}.{1} = {2}'.format(self.instancename, attr, repr(rhs).strip("'\""))
            result += [attrstring]
        return result

ption> Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-react (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2023-11-27Remove support for simple objects in endpoints (#9181)Gravatar Bjorn Lu 56-529/+206
* Deprecate simple object from endpoints * Update changeset * Add missing Response return Co-authored-by: Happydev <81974850+MoustaphaDev@users.noreply.github.com> * Update .changeset/clever-beds-notice.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Happydev <81974850+MoustaphaDev@users.noreply.github.com> Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-11-28Remove shiki lang path property support (#9196)Gravatar Bjorn Lu 7-427/+22
2023-11-28Remove deprecated features from Astro 3.0 (#9168)Gravatar Bjorn Lu 47-398/+95
2023-11-28Remove deprecated markdown-remark APIs (#9182)Gravatar Bjorn Lu 4-59/+7
2023-11-27[ci] release (#9180)astro@3.6.1Gravatar Houston (Bot) 32-65/+63
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-11-24Remove vercel deprecated analytics option (#9184)Gravatar Bjorn Lu 3-30/+12
2023-11-24[ci] formatGravatar Guspan Tanadi 1-2/+1
2023-11-24style: highlight markdown Tip Note section CONTRIBUTING (#9123)Gravatar Guspan Tanadi 1-5/+7
2023-11-23fix scroll restoration issue on webKit browsers (#9186)Gravatar Martin Trapp 2-1/+7
* fix scroll restoration issue on webKit browsers * add changeset * Update .changeset/shaggy-socks-glow.md * Update .changeset/shaggy-socks-glow.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-11-23fix(middleware): rename internal middleware id (#9173)Gravatar Arsh 2-1/+6
* rename internal middleware id * add changeset
2023-11-23fix: Changelog formatting for 3.6.0 View Transition events (#9176)Gravatar Martin Trapp 1-3/+3
Co-authored-by: Eva Decker <itsevadecker@gmail.com>
2023-11-22[ci] formatGravatar Eva Decker 1-3/+3
2023-11-22Fix View Transitions code block formatting (#9174)Gravatar Eva Decker 1-3/+3
2023-11-22Rename entryPoint to entrypoint (#9161)Gravatar Bjorn Lu 14-26/+38
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2023-11-22Fix esbuild warning for local dev (#9160)Gravatar Bjorn Lu 1-1/+1
2023-11-22[ci] release (#9165)astro@3.6.0Gravatar Houston (Bot) 34-90/+83
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>