def check(source_dir): pyproject = pjoin(source_dir, 'pyproject.toml') if isfile(pyproject): log.info('Found pyproject.toml') else: log.error('Missing pyproject.toml') return False try: with open(pyproject) as f: pyproject_data = toml_load(f) # Ensure the mandatory data can be loaded buildsys = pyproject_data['build-system'] requires = buildsys['requires'] backend = buildsys['build-backend'] backend_path = buildsys.get('backend-path') log.info('Loaded pyproject.toml') except (TomlDecodeError, KeyError): log.error("Invalid pyproject.toml", exc_info=True) return False hooks = Pep517HookCaller(source_dir, backend, backend_path) sdist_ok = check_build_sdist(hooks, requires) wheel_ok = check_build_wheel(hooks, requires) if not sdist_ok: log.warning('Sdist checks failed; scroll up to see') if not wheel_ok: log.warning('Wheel checks failed') return sdist_ok
def toml(location: str) -> dict: """Returns back the configuration found within the projects [TOML](https://github.com/toml-lang/toml#toml) config (if there is one). Generally this is a `pyproject.toml` file at the root of the project with a `[tool.portray]` section defined. """ try: toml_config = toml_load(location) tools = toml_config.get("tool", {}) config = tools.get("portray", {}) config["file"] = location if "modules" not in config: if "poetry" in tools and "name" in tools["poetry"]: config["modules"] = [tools["poetry"]["name"]] elif ( "flit" in tools and "metadata" in tools["flit"] and "module" in tools["flit"]["metadata"] ): config["modules"] = [tools["flit"]["metadata"]["module"]] return config except Exception: warnings.warn(f"No {location} config file found") return {}
def convert_old_conf_to_new() -> None: for instance_directory in BubblejailDirectories.\ iter_instances_path(): if (instance_directory / FILE_NAME_SERVICES).is_file(): continue print(f"Converting {instance_directory.stem}") old_conf_path = instance_directory / 'config.toml' with open(old_conf_path) as old_conf_file: old_conf_dict = toml_load(old_conf_file) new_conf: Dict[str, Any] = {} try: services_list = old_conf_dict.pop('services') except KeyError: services_list = [] for service_name in services_list: new_conf[service_name] = {} try: old_service_dict = old_conf_dict.pop('service') except KeyError: old_service_dict = {} for service_name, service_dict in old_service_dict.items(): new_conf[service_name] = service_dict new_conf['common'] = old_conf_dict with open(instance_directory / FILE_NAME_SERVICES, mode='x') as f: toml_dump(new_conf, f)
def __check_and_process(self, file: str): """ loads the file and process :param file: file path :return: None :exception: Exception """ data = None file_extension = Path(file).suffix if file_extension not in self.SUPPORTED_FILES: raise Exception( "Unsupported file format!. file format must be yaml, json, ini, toml & cfg" ) else: file_stream = open(file) if file_extension in self.YAML_EXTENSION: data = yaml_load(file_stream) elif file_extension in self.TOML_EXTENSION: data = toml_load(open(file)) elif file_extension in self.CONFIG_EXTENSION: config_parser = ConfigParser() config_parser.read_file(open(file)) data = config_parser._sections elif file_extension in self.JSON_EXTENSION: data = json_load(open(file)) if data: self.__process(data) return data
def executable_names(root='.'): with open(join(root, 'Cargo.toml')) as toml: toml = toml_load(toml) package_name = toml['package']['name'] try: return package_name, toml['lib']['name'] except KeyError: return (package_name, None)
def profile_get(cls, profile_name: str) -> BubblejailProfile: profile_file_name = profile_name + '.toml' for profiles_directory in cls.iter_profile_directories(): possible_profile_path = profiles_directory / profile_file_name if possible_profile_path.is_file(): with open(possible_profile_path) as profile_file: return BubblejailProfile(**toml_load(profile_file)) raise BubblejailException(f"Profile {profile_name} not found")
def main(): args = parser.parse_args() with open(args.config) as f: config = toml_load(f) app = create_wsgi_app(config) if args.debug: app.run( host=args.host, port=args.port, debug=args.debug, threaded=True, ) else: server = WSGIServer((args.host, args.port), app) server.serve_forever()
def ltoml(filepath: str) -> JASM: """ :param filepath: :return: """ try: with open(filepath) as f: return toml_load(f) except NameError: raise EnvironmentError("'pip install toml' if you wanna use this!") except UnicodeDecodeError as e: return toml_loads(lstring(filepath))
def get_conf(): """Load the borgback configuration from a filename.""" conf_path = Path(XDG_CONFIG_HOME) / "borgback.toml" with conf_path.open() as fd: conf = toml_load(fd) # Infer full repository path conf["backup"]["full_name"] = conf["borg"]["repository"] + "::" + conf[ "backup"]["name"] # Convert types conf["schedule"]["backup_interval"] = timedelta( minutes=conf["schedule"]["backup_interval"]) conf["schedule"]["retry_interval"] = timedelta( minutes=conf["schedule"]["retry_interval"]) return conf
def test_load_configuration_invalid_value_toml(self): old_data = toml_load(open('./tests/data/sample.toml')) sample = {'system': "${SYSTEM:testing"} toml_dump(sample, open('./tests/data/sample.toml', mode='w+')) with pytest.raises(Exception): ConfigLoader("./tests/data/sample.toml") toml_dump(old_data, open('./tests/data/sample.toml', mode='w+')) data = ConfigLoader("./tests/data/sample.toml").get_config() assert data['system'] == 'testing' assert data['testing']['demo'] == 'default' assert data['plain'] == "value" assert data['integer'] == 1 assert data['float'] == 1.0 sample = {'system': "SYSTEM:testing}"} toml_dump(sample, open('./tests/data/sample.toml', mode='w+')) with pytest.raises(Exception): ConfigLoader("./tests/data/sample.toml") toml_dump(old_data, open('./tests/data/sample.toml', mode='w+'))
def toml(location: str) -> dict: """Returns back the configuration found within the projects [TOML](https://github.com/toml-lang/toml#toml) config (if there is one). Generally this is a `pyproject.toml` file at the root of the project with a `[tool.portray]` section defined. """ try: location_exists = os.path.exists(location) if not location_exists: warnings.warn(f'\nNo config file found at location: "{location}"') return {} except Exception as detection_error: warnings.warn(f'\nUnable to check config at "{location}" due to error: {detection_error}') try: toml_config = toml_load(location) tools = toml_config.get("tool", {}) config = tools.get("portray", {}) config["file"] = location if "modules" not in config: if "poetry" in tools and "name" in tools["poetry"]: config["modules"] = [tools["poetry"]["name"]] elif ( "flit" in tools and "metadata" in tools["flit"] and "module" in tools["flit"]["metadata"] ): config["modules"] = [tools["flit"]["metadata"]["module"]] return config except Exception as load_config_error: warnings.warn(f'\nConfig file at "{location}" has errors: {load_config_error}') return {}
def run() -> None: """ Run the tool parsing the commandline arguments """ print(f"JoSIM Tools {__version__}") parser = ArgumentParser(description="Circuit tools built on JoSIM") parser.add_argument("configuration", type=str) parser.add_help = True parser.allow_abbrev = True args = parser.parse_args() configuration = toml_load(args.configuration) try: schema_validate(instance=configuration, schema=SCHEMA_CONFIG) except SchemaValidationError as error: print("ERROR: configuration file validation failed") print(" reason: {}".format(error.message)) exit(-1) mode = configuration["mode"] if mode == "verify": verify_configuration = VerifyConfiguration.from_dict( configuration["verify"]) verifier = Verifier(verify_configuration) output = verifier.verify() if output: print("SUCCESS") else: print("FAILURE") if output.failure_time is not None: print(" TIME : {}".format(output.failure_time)) if output.failure_point is not None: print(" POINT : {}".format(output.failure_point)) elif mode == "margin": verify_configuration = VerifyConfiguration.from_dict( configuration["verify"]) margin_configuration = MarginAnalysisConfiguration.from_dict( configuration.get("margin", {})) margin_parameters: Dict[str, MarginParameterConfiguration] = {} for key, item in configuration["parameters"].items(): margin_parameters[key] = MarginParameterConfiguration.from_dict( item) margin_analysis = MarginAnalysis(verify_configuration, margin_configuration) num_threads = min(2 * len(margin_parameters), cpu_count()) margin_analysis_parameters: Dict[str, float] = {} for key, item in margin_parameters.items(): margin_analysis_parameters[key] = item.nominal result = margin_analysis.analyse(margin_analysis_parameters, num_threads) print_margin_analysis_result( result, left_size=margin_configuration.min_search, right_size=margin_configuration.max_search, ) elif mode == "yield": verify_configuration = VerifyConfiguration.from_dict( configuration["verify"]) yield_configuration = YieldAnalysisConfiguration.from_dict( configuration["yield"]) yield_parameters: Dict[str, YieldParameterConfiguration] = {} for key, item in configuration["parameters"].items(): yield_parameters[key] = YieldParameterConfiguration.from_dict(item) num_samples = yield_configuration.num_samples num_threads = min(num_samples, cpu_count()) yield_analysis = YieldAnalysis(verify_configuration, yield_parameters) yield_analysis.sample(num_samples, num_threads) print("Yield: {} / {} = {:.1f} %".format( yield_analysis.num_success(), yield_analysis.num_total(), yield_analysis.percentage() * 100, )) elif mode == "optimize": verify_configuration = VerifyConfiguration.from_dict( configuration["verify"]) margin_configuration = MarginAnalysisConfiguration.from_dict( configuration.get("margin", {})) optimize_configuration = OptimizeConfiguration.from_dict( configuration["optimize"]) optimize_parameters: Dict[str, OptimizerParameterConfiguration] = {} for key, item in configuration["parameters"].items(): optimize_parameters[ key] = OptimizerParameterConfiguration.from_dict(item) optimizer = Optimizer( verify_configuration, margin_configuration, optimize_configuration, optimize_parameters, ) optimization_parameters: Dict[str, float] = {} for key, item in optimize_parameters.items(): optimization_parameters[key] = item.nominal point = optimizer.optimize(optimization_parameters) output_file = optimize_configuration.output if output_file is not None: optimizer.margin_analysis_.verifier_.simulator_.write_file_with_updated_parameters( output_file, point) else: assert False, "INTERNAL ERROR: UNREACHABLE CODE"
from matplotlib.pyplot import plot, show, pause, close from os.path import join from ndjson import load as ndjson_load from toml import load as toml_load with open( join( toml_load('configuration.toml')['data']['path'], 'quickdraw_simplified', 'giraffe.ndjson')) as ndjson_file: data = ndjson_load(ndjson_file) for datum in data: for x, y in datum['drawing']: plot(x, y, 'r-') show(block=False) pause(1) close()
"""Configuration file for Sphinx Documentation Generator.""" from os import path as os_path from sys import path as sys_path from toml import load as toml_load sys_path.insert(0, os_path.abspath("../src")) toml_path = "{}/pyproject.toml".format(os_path.abspath("..")) parsed_toml = toml_load(toml_path) project = parsed_toml["tool"]["poetry"]["name"] copyright = "2019, Tomer Figenblat" author = "Tomer Figenblat" version = parsed_toml["tool"]["poetry"]["version"] release = version extensions = [ "sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", ] exclude_patterns = ["_build"] pygments_style = "sphinx" html_theme = "sphinx_rtd_theme" language = "en" show_authors = False linkcheck_anchors = True # sphinx.ext.todo configuration