def parse_requirements(req_file): """Parse the requirements from a anysnake.toml file See readme. """ used_files = [str(Path(req_file).absolute())] with open(req_file) as op: p = tomlkit.loads(op.read()) if "base" in p and "global_config" in p["base"]: fn = replace_env_vars(p["base"]["global_config"]) with open(fn) as op: gconfig = tomlkit.loads(op.read()) used_files.insert(0, p["base"]["global_config"]) p = merge_config(gconfig, p) paths = [("base", "storage_path")] if "env" in p: for k in p["env"]: if isinstance(p["env"][k], str): paths.append(("env", k)) for path in paths: if path[0] in p: if path[1] in p[path[0]]: p[path[0]][path[1]] = replace_env_vars(p[path[0]][path[1]]) p["used_files"] = used_files return p
def test_coverage_include_all_packages(): """Coverage source should include all packages. 1. From the main pyproject.toml. 2. From test helpers pyproject.toml. 3. The tests package. """ ini_parser = configparser.ConfigParser() ini_parser.read(".coveragerc") coverage_sources = ini_parser["run"]["source"].strip().splitlines() pyproject_toml = tomlkit.loads(open("pyproject.toml").read()) packages = [ re.sub(r"\.py$", "", p["include"]) for p in pyproject_toml["tool"]["poetry"]["packages"] ] pyproject_toml = tomlkit.loads(open("tests/helpers/pyproject.toml").read()) helpers = [ re.sub(r"\.py$", "", p["include"]) for p in pyproject_toml["tool"]["poetry"]["packages"] ] assert coverage_sources == packages + helpers + ["tests"]
def test_coverage_include_all_packages(): """ Coverage source should include packages: * from the main pyproject.toml, * from test helpers pyproject.toml, * the tests package """ ini_parser = configparser.ConfigParser() ini_parser.read(".coveragerc") coverage_sources = ini_parser["run"]["source"].strip().splitlines() pyproject_toml = tomlkit.loads(open("pyproject.toml").read()) packages = [ p["include"].rstrip(".py") for p in pyproject_toml["tool"]["poetry"]["packages"] ] pyproject_toml = tomlkit.loads(open("tests/helpers/pyproject.toml").read()) helpers = [ p["include"].rstrip(".py") for p in pyproject_toml["tool"]["poetry"]["packages"] ] assert coverage_sources == packages + helpers + ["tests"]
def _init(path): result = {} try: with io.open(path, "rt", encoding="utf-8") as f: result = tomlkit.loads(f.read()).value except ValueError as e: print("\n\n" + repr(e) + " while loading settings file: " + path + "\n\n") print(sys.exc_info()) except IOError as e: print("\n\n" + repr(e) + " while loading settings file: " + path + "\nAttempting to recover...\n\n") result, num_default_added = _deep_merge_defaults(result, _DEFAULT_SETTINGS) # Temporary piece of code to seamlessly migrate clipboards to JSON if result["paths"]["SAVED_CLIPBOARD_PATH"].endswith(".toml"): old_clipboard = result["paths"]["SAVED_CLIPBOARD_PATH"] import json clipboard = {} new_path = old_clipboard[:-4] + "json" print("\n\n Migrating clipboard from {} to {}".format( old_clipboard, new_path)) with io.open(old_clipboard, "rt", encoding="utf-8") as f: clipboard = tomlkit.loads(f.read()).value formatted_data = unicode(json.dumps(clipboard, ensure_ascii=False)) with io.open(new_path, "wt", encoding="utf-8") as f: f.write(formatted_data) result["paths"]["SAVED_CLIPBOARD_PATH"] = new_path if os.path.exists(old_clipboard): os.remove(old_clipboard) if not num_default_added: _save(result, _SETTINGS_PATH) if num_default_added > 0: print("Default settings values added: %d " % num_default_added) _save(result, _SETTINGS_PATH) return result
def test_bump_pyproject(temp_path: Path): from_path = temp_path / 'pyproject.toml' from_path.write_text( dedent(""" [tool.poetry] name = "check-me" version = "1.2.3" [tool.poetry.dependencies] python = "*" [[tool.poetry.source]] name = "pypi" url = "https://pypi.org/pypi" """)) before_toml = tomlkit.loads(from_path.read_text()) config = Config() config.attach({ 'project': str(temp_path), 'from': { 'format': 'poetry', 'path': 'pyproject.toml' }, }) command = ProjectBumpCommand(argv=['fix'], config=config) result = command() assert result is True after_toml = tomlkit.loads(from_path.read_text()) assert after_toml['tool']['poetry'][ 'version'] == '1.2.4', 'Version was not bumped properly' after_toml['tool']['poetry']['version'] = '1.2.3' assert after_toml == before_toml, 'Bump command altered attributes other than version'
def test_poetry_avoid_additional_dependencies(): """Python package should not have any of additional dependencies.""" pyproject_toml = tomlkit.loads(open("pyproject.toml").read()) deps = list(pyproject_toml["tool"]["poetry"].get("dependencies", {})) assert deps == ["python"] pyproject_toml = tomlkit.loads(open("tests/helpers/pyproject.toml").read()) deps = list(pyproject_toml["tool"]["poetry"].get("dependencies", {})) assert not deps
def test_config_values_to_text(test_case, expected): test_case.create() _config_example.write_example_config('test') _, content = pathlib.Path('test').read_text('utf8').split( '# START OF ACTUAL CONFIG FILE') content = content.lstrip() test_file = pathlib.Path('test.toml') test_file.write_text(content, 'utf8') if test_case.default is not None: tomlkit.loads(test_file.read_text('utf8')) assert expected == content, content
def load_config(): """Load the configuration object by merging the default options with the user configuration file. """ with open(DEFAULT_PATH) as f: config = tomlkit.loads(f.read()) if os.path.isfile(CONFIG_PATH): with open(CONFIG_PATH) as f: config.update(tomlkit.loads(f.read())) return config
def main() -> None: """main.""" args = get_args() dict_toml_origin: dict = {} with open(args.originfile, "r") as f: dict_toml_origin = loads(f.read()) logging.debug(json.dumps(dict_toml_origin, indent=4)) with open(getenv("SOURCE_DIR_NAME", "failed") + "/pyproject.toml") as f: upstream_contents = f.read() dict_toml_upstream = loads(upstream_contents) dict_toml_origin["tool"]["poetry"].update( { "dev-dependencies": dict_toml_upstream["tool"]["poetry"]["dev-dependencies"], }, ) logging.info("merged: tool.poetry.dev-dependencies ...") dict_toml_origin["tool"].update( { "coverage": { "run": dict_toml_upstream["tool"]["coverage"]["run"] }, }, ) logging.info("merged: tool.coverage.run ...") dict_toml_origin["tool"].update( { "pytest": { "ini_options": dict_toml_upstream["tool"]["pytest"]["ini_options"], }, }, ) logging.info("merged: tool.pytest.ini_options ...") for key2 in ["black", "isort"]: dict_toml_origin["tool"].update( {key2: dict_toml_upstream["tool"][key2]}) logging.debug(json.dumps(dict_toml_origin, indent=4)) logging.info("merged: " + key2 + " ...") logging.debug(json.dumps(dict_toml_origin, indent=4)) with open(args.originfile, "w") as f: f.write( re.sub("(\n$)+", "\n", dumps(dict_toml_origin), flags=re.MULTILINE), ) logging.info("file write.")
def load(cls, f, encoding=None): content = f.read() if encoding is not None: content = content.decode(encoding) _data = tomlkit.loads(content) if "source" not in _data: # HACK: There is no good way to prepend a section to an existing # TOML document, but there's no good way to copy non-structural # content from one TOML document to another either. Modify the # TOML content directly, and load the new in-memory document. sep = "" if content.startswith("\n") else "\n" content = plette.pipfiles.DEFAULT_SOURCE_TOML + sep + content data = tomlkit.loads(content) return cls(data)
def main(*, config_path: str = DEFAULT_CONFIG_PATH) -> None: """Main entry point for the default bot launcher.""" log.info("Loading config") config_data = Path(config_path).read_text() config: util.config.Config = tomlkit.loads(config_data) # Initialize Sentry reporting here to exempt config syntax errors and query # the user's report_errors value, defaulting to enabled if not specified if config["bot"].get("report_errors", True): log.info("Initializing Sentry error reporting") util.sentry.init() # Use preliminary loop for config upgrading loop = asyncio.get_event_loop() aiorun.run(_upgrade(config, config_path), stop_on_unhandled_errors=True, loop=loop) loop.close() loop = setup_asyncio(config) # Start bot log.info("Initializing bot") aiorun.run(Bot.create_and_run(config, loop=loop), loop=loop)
def __init__(self, flatfile_location=None, url=None, user=None, password=None): self.imoobject = None if (not flatfile_location) and (not url): # Try to load the configuration file try: with CONFIG_FILE_PATH.open("rt") as inpf: config = tomlkit.loads("".join(inpf.readlines())) location = config["repositories"][0]["location"] self.imoobject = ImoFlatFile(location) except FileNotFoundError: log.warning('IMO config file "%s" not found.', str(CONFIG_FILE_PATH)) log.warning( "Have you run the initial setup procedure ", "(python -m litebird_sim.install_imo)?", ) except tomlkit.exceptions.NonExistentKey: log.warning('no repositories in file "%s"', str(CONFIG_FILE_PATH)) if flatfile_location: self.imoobject = ImoFlatFile(flatfile_location) if url: raise NotImplementedError( "access to remote IMOs is not supported yet") self.queried_objects = set() # type: Set[Tuple[type, UUID]]
def _get_build_func(): pyproject = Path('pyproject.toml') if not pyproject.exists(): return data = tomlkit.loads(pyproject.read_text(encoding='utf-8')) if 'tool' not in data: return if 'jupyter-packaging' not in data['tool']: return if 'builder' not in data['tool']['jupyter-packaging']: return section = data['tool']['jupyter-packaging'] if 'func' not in section['builder']: raise ValueError('Missing `func` specifier for builder') func_data = section['builder']['func'] mod_name, _, func_name = func_data.rpartition('.') # If the module fails to import, try importing as a local script try: mod = importlib.import_module(mod_name) except ImportError: try: sys.path.insert(0, os.getcwd()) mod = importlib.import_module(mod_name) finally: sys.path.pop(0) func = getattr(mod, func_name) kwargs = section.get('build-args', {}) return functools.partial(func, **kwargs)
def load(self, conf_file): """ Reads the problem definition :param conf_file: Path to the file to open or a file descriptor """ self._conf_file = pth.abspath( conf_file) # for resolving relative paths conf_dirname = pth.dirname(self._conf_file) with open(conf_file, "r") as file: d = file.read() self._conf_dict = tomlkit.loads(d) # FIXME: Could structure of configuration file be checked more thoroughly ? for key in [KEY_INPUT_FILE, KEY_OUTPUT_FILE]: if key not in self._conf_dict: raise FASTConfigurationError(missing_key=key) if not isinstance(self._conf_dict.get(TABLE_MODEL), dict): raise FASTConfigurationError(missing_section=TABLE_MODEL) # Looking for modules to register module_folder_paths = self._conf_dict.get(KEY_FOLDERS, []) for folder_path in module_folder_paths: folder_path = pth.join(conf_dirname, folder_path) if not pth.exists(folder_path): _LOGGER.warning("SKIPPED %s: it does not exist.") else: OpenMDAOSystemRegistry.explore_folder(folder_path)
def add_hook(test_repo: Path, name: str, cmd: str, after_push: bool = False) -> None: """ Patch the configuration file so that we can also test hooks. """ cfg_path = test_repo / "pyproject.toml" parsed = tomlkit.loads(cfg_path.text()) if after_push: key = "after_push" else: key = "before_commit" if key not in parsed["tool"]["tbump"]: parsed["tool"]["tbump"][key] = tomlkit.aot() hook_config = tomlkit.table() hook_config.add("cmd", cmd) hook_config.add("name", name) parsed["tool"]["tbump"][key].append(hook_config) from pprint import pprint pprint(parsed) cfg_path.write_text(tomlkit.dumps(parsed)) tbump.git.run_git(test_repo, "add", ".") tbump.git.run_git(test_repo, "commit", "--message", "update hooks")
def test_end_to_end_using_pyproject_toml(test_repo: Path) -> None: tbump_toml_path = test_repo / "tbump.toml" # Convert tbump config to a config inside a tool.tbump section: tbump_config = tomlkit.loads(tbump_toml_path.read_text()) tools_config = tomlkit.table() tools_config.add("tbump", tbump_config) pyproject_config = tomlkit.table() pyproject_config.add("tool", tools_config) to_write = tomlkit.dumps(pyproject_config) # Write the pyproject.toml and remove tbump.toml pyproject_toml_path = test_repo / "pyproject.toml" pyproject_toml_path.write_text(to_write) tbump_toml_path.unlink() tbump.git.run_git(test_repo, "add", ".") tbump.git.run_git(test_repo, "commit", "--message", "move tbump config inside pyproject.toml") _, previous_commit = tbump.git.run_git_captured(test_repo, "rev-parse", "HEAD") tbump.main.main( ["-C", str(test_repo), "1.2.41-alpha-2", "--non-interactive"]) assert bump_done(test_repo, previous_commit, using_pyproject=True)
def test_build_requires_not_pinned(): """Build requirements of pyproject.toml files should not have versions.""" for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]: pyproject_toml = tomlkit.loads(open(pyproject_toml).read()) requires = pyproject_toml["build-system"]["requires"] for require in requires: assert len(re.split(r"=+", require)) == 1
def from_path(cls, resource_path: Path) -> BuiltinStyle: """Create a built-in style from a resource path.""" without_suffix = resource_path.with_suffix("") src_path = builtin_resources_root().parent.parent package_path = resource_path.relative_to(src_path) from_resources_root = without_suffix.relative_to(builtin_resources_root()) root, *path_remainder = package_path.parts path_remainder_without_suffix = (*path_remainder[:-1], without_suffix.parts[-1]) bis = BuiltinStyle( py_url=furl(scheme=Scheme.PY, host=root, path=path_remainder), py_url_without_ext=furl(scheme=Scheme.PY, host=root, path=path_remainder_without_suffix), path_from_repo_root=resource_path.relative_to(repo_root()).as_posix(), path_from_resources_root=from_resources_root.as_posix(), ) bis.pypackage_url = PythonPackageURL.from_furl(bis.py_url) bis.identify_tag = from_resources_root.parts[0] toml_dict = tomlkit.loads(bis.pypackage_url.content_path.read_text(encoding="UTF-8")) keys = list(toml_dict.keys()) keys.remove(PROJECT_NAME) bis.files = keys try: # Intentionally break the doc generation when styles don't have [nitpick.meta]name meta = toml_dict["nitpick"]["meta"] bis.name = meta["name"] bis.url = meta.get("url") except KeyError as err: raise SyntaxError(f"Style file missing [nitpick.meta] information: {bis}") from err return bis
def load_configs(): """Build configs from defaults and pyproject.toml.""" package_root_path = Path( subprocess.check_output( ["git", "rev-parse", "--show-toplevel"], universal_newlines=True ).split("\n")[0] ) pyproject_path = package_root_path / "pyproject.toml" if not pyproject_path.exists(): raise FileNotFoundError( f"Config file not found at: '{pyproject_path}' " "(must be run from project root)" ) with pyproject_path.open() as f: pyproject = tomlkit.loads(f.read()) poetry = pyproject["tool"]["poetry"] package_name = poetry["name"] package_description = poetry["description"] configs = { **_DEFAULT_CONFIGS, "package_name": package_name, "description": package_description, "base_dir": package_root_path, } if "jgt_tools" in pyproject["tool"]: configs = {**configs, **pyproject["tool"]["jgt_tools"]} return configs
def _validate_engine_path(): ''' Validates path 'Engine Path' in settings.toml ''' if not sys.platform.startswith('win'): return '' try: import natlink # pylint: disable=import-error except ImportError: return '' if os.path.isfile(_SETTINGS_PATH): with io.open(_SETTINGS_PATH, "rt", encoding="utf-8") as toml_file: data = tomlkit.loads(toml_file.read()).value engine_path = data["paths"]["ENGINE_PATH"] if os.path.isfile(engine_path): return engine_path else: engine_path = _find_natspeak() data["paths"]["ENGINE_PATH"] = engine_path try: formatted_data = str(tomlkit.dumps(data)) with io.open(_SETTINGS_PATH, "w", encoding="utf-8") as toml_file: toml_file.write(formatted_data) printer.out( "Setting engine path to {}".format(engine_path)) except Exception as e: printer.out("Error saving settings file {} {} ".format( e, _SETTINGS_PATH)) return engine_path else: return _find_natspeak()
def validate_pyproject_toml(): """Validate that 'pyproject.toml' is consistent with 'setup.json'.""" # Read the requirements from 'setup.json' setup_cfg = _load_setup_cfg() install_requirements = [ Requirement.parse(r) for r in setup_cfg['install_requires'] ] for requirement in install_requirements: if requirement.name == 'reentry': reentry_requirement = requirement break else: raise DependencySpecificationError( "Failed to find reentry requirement in 'setup.json'.") pyproject_file = ROOT / 'pyproject.toml' if not pyproject_file.exists(): raise DependencySpecificationError( "The 'pyproject.toml' file is missing!") pyproject = toml.loads(pyproject_file.read_text(encoding='utf8')) pyproject_requires = [ Requirement.parse(r) for r in pyproject['build-system']['requires'] ] if reentry_requirement not in pyproject_requires: raise DependencySpecificationError( "Missing requirement '{}' in 'pyproject.toml'.".format( reentry_requirement)) click.secho('Pyproject.toml dependency specification is consistent.', fg='green')
def dump_documents(args: argparse.Namespace): fn_mapping = f'{args.output_prefix}.json' fn_docs = f'{args.output_prefix}.ndjson' if os.path.exists(fn_mapping) or os.path.exists(fn_docs): # obviously we can overwrite the files that pops into existence # after the check, but we don't care logging.error("File already exists!") sys.exit(-1) with open(args.input) as f: t_doc = tomlkit.loads(f.read()) doc_ids = set() for q_body in t_doc['queries'].values(): ids = q_body.get('doc_id', []) doc_ids |= set(ids) client = MiniClient(args.host, args.port) mapping = client.get_mapping(args.index) with open(fn_mapping, 'x') as f: json.dump(mapping, f) with open(fn_docs, 'x') as f: for doc_id in doc_ids: src = client.get_source(args.index, doc_id) json.dump({"index": {"_id": doc_id}}, f) f.write('\n') json.dump(src, f) f.write('\n')
def _read(self) -> None: """ Reads build.toml file into array of build definition Each build definition will have empty function list, which will be populated from the current template.yaml file """ LOG.debug("Instantiating build definitions") self._function_build_definitions = [] self._layer_build_definitions = [] document = {} try: txt = self._filepath.read_text() document = tomlkit.loads(txt) except OSError: LOG.debug("No previous build graph found, generating new one") function_build_definitions_table = document.get( BuildGraph.FUNCTION_BUILD_DEFINITIONS, []) for function_build_definition_key in function_build_definitions_table: function_build_definition = _toml_table_to_function_build_definition( function_build_definition_key, function_build_definitions_table[function_build_definition_key] ) self._function_build_definitions.append(function_build_definition) layer_build_definitions_table = document.get( BuildGraph.LAYER_BUILD_DEFINITIONS, []) for layer_build_definition_key in layer_build_definitions_table: layer_build_definition = _toml_table_to_layer_build_definition( layer_build_definition_key, layer_build_definitions_table[layer_build_definition_key]) self._layer_build_definitions.append(layer_build_definition)
def site(): base = Path('website') with (base/'content'/'index.toml').open() as toml, \ (base/'style'/'index.css').open() as css: data = loads(toml.read()) with html(lang='en') as document: with head(): meta(charset='utf-8') meta(name='description', content=f'{SHARED.info.person_name} (engineer|designer)') meta(name='keywords', content=','.join(SHARED.meta.keywords)) meta(name='author', content=f'{SHARED.info.person_name}') title(SHARED.info.person_name) link(rel='shortcut icon', type='image/x-icon', href='favicon.ico') link(rel='icon', type='image/x-icon', href='favicon.ico') style(raw(css.read())) script(src='website/js/anim.js') script(src='website/js/index.js') with body(): _block('engineer', data['engineer']) _block('designer', data['designer']) with div(id='handler'): div(raw('«»')) script('main();', type='text/javascript') copyright = comment(f'Copyright (C) 2015 - {datetime.now().year} ' f'{SHARED.info.person_name}. ' 'All rights reserved.') return f'<!DOCTYPE html>{copyright}{document.render(pretty=False)}'
def get_pyproject(path): from vistir.compat import Path if not path: return if not isinstance(path, Path): path = Path(path) if not path.is_dir(): path = path.parent pp_toml = path.joinpath("pyproject.toml") setup_py = path.joinpath("setup.py") if not pp_toml.exists(): if setup_py.exists(): return None else: pyproject_data = {} with io.open(pp_toml.as_posix(), encoding="utf-8") as fh: pyproject_data = tomlkit.loads(fh.read()) build_system = pyproject_data.get("build-system", None) if build_system is None: if setup_py.exists(): requires = ["setuptools", "wheel"] backend = "setuptools.build_meta" else: requires = ["setuptools>=38.2.5", "wheel"] backend = "setuptools.build_meta" build_system = {"requires": requires, "build-backend": backend} pyproject_data["build_system"] = build_system else: requires = build_system.get("requires") backend = build_system.get("build-backend") return (requires, backend)
def _get_config_file(project_path: Path) -> ConfigFile: toml_path = project_path / "tbump.toml" if toml_path.exists(): doc = tomlkit.loads(toml_path.read_text()) return TbumpTomlConfig(toml_path, doc) pyproject_path = project_path / "pyproject.toml" if pyproject_path.exists(): doc = tomlkit.loads(pyproject_path.read_text()) try: doc["tool"]["tbump"] except KeyError: raise ConfigNotFound(project_path) return PyprojectConfig(pyproject_path, doc) raise ConfigNotFound(project_path)
def test_poetry_deps_are_ordered(): """Dependencies of pyproject.toml files should be in order.""" for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]: pyproject_toml = tomlkit.loads(open(pyproject_toml).read()) deps = list(pyproject_toml["tool"]["poetry"].get("dependencies", {})) if deps: assert deps == ["python"] + sorted(deps[1:])
def read_toml(cls, path_or_buff, aot: Optional[str] = "row", aot_only: bool = True, **kwargs) -> __qualname__: r""" Reads a TOML file. .. caution:: This is provided as a preview. It may have issues and may change. Args: path_or_buff: Path or buffer aot: The name of the array of tables (i.e. ``[[ table ]]``) If None, finds the unique outermost TOML key, implying ``aot_only``. aot_only: Fail if any outermost keys other than the AOT are found kwargs: Passed to ``Utils.read`` """ import tomlkit txt = IoUtils.read(path_or_buff, **kwargs) data = tomlkit.loads(txt) if len(data.keys()) == 0: return cls.new_df() if aot_only and len(data.keys()) > 1 or aot is None: raise ValueError(f"Multiple outermost TOML keys: {data.keys()}") if aot is None: aot = next(iter(data.keys())) data = data[aot] df = pd.DataFrame([pd.Series(d) for d in data]) return cls._convert_typed(df)
def _comp_toml_cmd(src_toml, cmd) -> bool: """Compare TOML files after running a xinstall sub-command. """ # test on 1.toml dir_ = BASE_DIR / "output" / cmd / src_toml.name dir_.mkdir(parents=True, exist_ok=True) shutil.copy2(src_toml, dir_ / "pyproject.toml") cmd = f"xinstall {cmd} -ic -d {dir_}" sp.run(cmd, shell=True, check=True) diff = DeepDiff( tomlkit.loads(src_toml.read_text()), tomlkit.loads((dir_ / "pyproject.toml").read_text()), ignore_order=True ) print(diff) return not diff
def generate_poetry_content(self): template = POETRY_DEFAULT if self._license: template = POETRY_WITH_LICENSE content = loads(template) poetry_content = content["tool"]["poetry"] poetry_content["name"] = self._project poetry_content["version"] = self._version poetry_content["description"] = self._description poetry_content["authors"].append(self._author) if self._license: poetry_content["license"] = self._license poetry_content["dependencies"]["python"] = self._python for dep_name, dep_constraint in self._dependencies.items(): poetry_content["dependencies"][dep_name] = dep_constraint for dep_name, dep_constraint in self._dev_dependencies.items(): poetry_content["dev-dependencies"][dep_name] = dep_constraint # Add build system build_system = table() build_system_version = ">=" + BUILD_SYSTEM_MIN_VERSION if BUILD_SYSTEM_MAX_VERSION is not None: build_system_version += ",<" + BUILD_SYSTEM_MAX_VERSION build_system.add("requires", ["poetry-core" + build_system_version]) build_system.add("build-backend", "poetry.core.masonry.api") content.add("build-system", build_system) return dumps(content)
def generate_poetry_content(self): template = POETRY_DEFAULT if self._license: template = POETRY_WITH_LICENSE content = loads(template) poetry_content = content["tool"]["poetry"] poetry_content["name"] = self._project poetry_content["version"] = self._version poetry_content["description"] = self._description poetry_content["authors"].append(self._author) if self._license: poetry_content["license"] = self._license poetry_content["dependencies"]["python"] = self._python for dep_name, dep_constraint in self._dependencies.items(): poetry_content["dependencies"][dep_name] = dep_constraint for dep_name, dep_constraint in self._dev_dependencies.items(): poetry_content["dev-dependencies"][dep_name] = dep_constraint return dumps(content)