def create_update_api(role_arn, function_arn, wiring): logger.info("creating or updating api /{}".format(wiring["pathPart"])) api_id = get_create_api() resource_id = resource(api_id, wiring["pathPart"]) uri = function_uri(function_arn, region()) api_method(api_id, resource_id, role_arn, uri, wiring) cors(api_id, resource_id)
def create_update_api(role_arn, function_arn, wiring): logger.info('creating or updating api /{}'.format(wiring['pathPart'])) api_id = get_create_api() resource_id = resource(api_id, wiring['pathPart']) uri = function_uri(function_arn, region()) api_method(api_id, resource_id, role_arn, uri, wiring) cors(api_id, resource_id)
def prepare_zip(): from pkg_resources import resource_filename as resource from json import dumps logger.info('creating/updating gimel.zip') with ZipFile('gimel.zip', 'w', ZIP_DEFLATED) as zipf: info = ZipInfo('config.json') info.external_attr = 0o664 << 16 zipf.writestr(info, dumps(config)) zipf.write(resource('gimel', 'config.py'), 'config.py') zipf.write(resource('gimel', 'gimel.py'), 'gimel.py') zipf.write(resource('gimel', 'logger.py'), 'logger.py') for root, dirs, files in os.walk(resource('gimel', 'vendor')): for file in files: real_file = os.path.join(root, file) relative_file = os.path.relpath(real_file, resource('gimel', '')) zipf.write(real_file, relative_file)
def schema(self): # Lazily load the CFR Weights schema if self._schema is None: from pkg_resources import resource_filename as resource self._schema = json.load( open(resource("cfretl", "schemas/cfr_weights.json"), "r")) return self._schema
def prepare_zip(): from pkg_resources import resource_filename as resource from config import config from json import dumps logger.info("creating/updating gimel.zip") with ZipFile("gimel.zip", "w", ZIP_DEFLATED) as zipf: info = ZipInfo("config.json") info.external_attr = 0o664 << 16 zipf.writestr(info, dumps(config)) zipf.write(resource("gimel", "config.py"), "config.py") zipf.write(resource("gimel", "gimel.py"), "gimel.py") zipf.write(resource("gimel", "logger.py"), "logger.py") for root, dirs, files in os.walk(resource("gimel", "vendor")): for file in files: real_file = os.path.join(root, file) relative_file = os.path.relpath(real_file, resource("gimel", "")) zipf.write(real_file, relative_file)
def prepare_zip(): from pkg_resources import resource_filename as resource from config import config from json import dumps logger.info('creating/updating gimel.zip') with ZipFile('gimel.zip', 'w', ZIP_DEFLATED) as zipf: info = ZipInfo('config.json') info.external_attr = 0o664 << 16 zipf.writestr(info, dumps(config)) zipf.write(resource('gimel', 'config.py'), 'config.py') zipf.write(resource('gimel', 'gimel.py'), 'gimel.py') zipf.write(resource('gimel', 'logger.py'), 'logger.py') for root, dirs, files in os.walk(resource('gimel', 'vendor')): for file in files: real_file = os.path.join(root, file) relative_file = os.path.relpath(real_file, resource('gimel', '')) zipf.write(real_file, relative_file)
def init_translation(package_name, resource_name, module_name): """Return function for specifying of places to be translated.""" lang = locale.getdefaultlocale()[0] gettext.install(module_name) def _echo(text): return text try: trans = gettext.translation( module_name, resource(package_name, resource_name), languages=[lang], ) return trans.gettext except (ImportError, FileNotFoundError): return _echo
def _config_template(): from pkg_resources import resource_filename as resource return open(resource('gimel', 'config.json.template'), 'r').read()
from pkg_resources import resource_filename as resource from pysumma import Simulation from string import Template from typing import List, Dict def read_template(path): with open(path, 'r') as f: OST_FILE = f.read() return Template(OST_FILE) resource = partial(resource, __name__) # Paths to template files INPT_FILE = resource('meta/ostIn.template') EXEC_FILE = resource('meta/model_executable.template') SAVE_FILE = resource('meta/save_parameters.template') # Templates INPT_META = read_template(INPT_FILE) EXEC_META = read_template(EXEC_FILE) SAVE_META = read_template(SAVE_FILE) class Ostrich(): """ Provides a high level interface to the OSTRICH optimization package. This class can currently only be used for single-objective optimization using the DDS algorithm as defined in the template file. Currently the metrics calculated are KGE, MAE, and MSE as defined in the evaluation
#!/usr/bin/env python # coding: utf-8 """Tests for datafile objects.""" from pkg_resources import resource_filename as resource import pytest import numpy as np from pasc.objects import datafile, floatarray from pasc.toolbox import load_data FILENAME = __file__ NC_DATAFILENAME = resource('pasc', 'data/sresa1b_ncar_ccsm3-example.nc') VALID_INIT = [load_data('pre'), load_data('pre').tas, NC_DATAFILENAME] INVALID_INIT = [232, np.arange(42), "asdad"] def test_err_not_netcdffile(): with pytest.raises(OSError) as err: _ = datafile.Datafile(FILENAME) assert "Unknown" in str(err) @pytest.mark.parametrize('dinit', VALID_INIT) def test_valid_initialisation(dinit): init = datafile.Datafile(dinit) assert isinstance(init, datafile.Datafile) @pytest.mark.parametrize('dinit', INVALID_INIT) def test_invalid_initialisation(dinit): with pytest.raises(TypeError) as err:
def _config_template(): from pkg_resources import resource_filename as resource import secrets template = open(resource('cronyo', 'config.yml.template'), 'r').read() template = template.replace("RANDOM_KEY", secrets.token_hex(40)) return template
# Configuration for yahiko_decorator follows. # If you click and drag the titlebar with the left mouse button, # you move the window. If you click and drag with the right mouse # button, you resize it. 'decorator.title.bindings': { '1': 'moveresize.move', '3': 'moveresize.resize', }, # Here we create a "Close" button on the left side of the titlebar. 'decorator.buttons.leftside': [ { 'style': { 'width': 20, 'text.color': (1.0, 1.0, 1.0), 'background.style': 'image', # This will give us the filename of the graphic file. 'background.image': resource('yahiko', 'gfx/close.png'), }, # if you click with the left mouse button, the "kill" action # is emitted. 'bindings': { '1': 'kill', } } ] }
from pkg_resources import resource_filename as resource from pyrhessys import Simulation from string import Template from typing import List, Dict def read_template(path): with open(path, 'r') as f: OST_FILE = f.read() return Template(OST_FILE) resource = partial(resource, __name__) # Paths to template files INPT_FILE = resource('template/ostIn.template') EXEC_FILE = resource('template/model_executable.template') SAVE_FILE = resource('template/save_parameters.template') # Templates INPT_META = read_template(INPT_FILE) EXEC_META = read_template(EXEC_FILE) SAVE_META = read_template(SAVE_FILE) PARAMETER = resource('meta/parameter_meta.json') class Ostrich(): """ Provides a high level interface to the OSTRICH optimization package. This class can currently only be used for single-objective optimization
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """Verification of the plan.""" import json from pkg_resources import resource_filename as resource from jsonschema import validate from jsonschema.exceptions import ValidationError SCHEMA_FILE_NAME = resource('dsplab', 'data/plan-schema.json') class VerifyError(Exception): """Verification error.""" def check_plan(plan_dict): """Check plan's dictionary.""" schema = _load_schema(SCHEMA_FILE_NAME) _check_plan_schema(plan_dict, schema) ids = _get_ids(plan_dict) for node in plan_dict["nodes"]: