Skip to content

Commit

Permalink
Update for dom-toml v2
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Apr 15, 2024
1 parent 7e6d503 commit cc85a10
Show file tree
Hide file tree
Showing 50 changed files with 1,508 additions and 662 deletions.
1 change: 1 addition & 0 deletions formate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ known_third_party = [
"packaging",
"pre_commit",
"pypi_json",
"pyproject_parser",
"pyreadline",
"pytest",
"pytest_cov",
Expand Down
16 changes: 8 additions & 8 deletions repo_helper/files/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ def make_sphinx_config_dict(templates: Environment) -> Dict[str, Any]:

class PythonFormatTomlEncoder(dom_toml.TomlEncoder):

def dump_list(self, v: List) -> str:
values = DelimitedList(str(self.dump_value(u)) for u in v)
def format_inline_array(self, obj: Union[Tuple, List], nest_level: int) -> str:
values = DelimitedList(str(self.format_literal(u)) for u in obj)
single_line = f"[{values:, }]"

if len(single_line) <= self.max_width:
Expand All @@ -873,18 +873,18 @@ def dump_list(self, v: List) -> str:
retval = StringList(['['])

with retval.with_indent(" ", 1):
for u in v:
retval.append(f"{str(self.dump_value(u))},")
for u in obj:
retval.append(f"{str(self.format_literal(u))},")

retval.append(']')

return str(retval)

def dump_value(self, v: Any) -> str:
if isinstance(v, bool):
return str(v)
def format_literal(self, obj: object, *, nest_level: int = 0) -> str:
if isinstance(obj, bool):
return str(obj)

return super().dump_value(v)
return super().format_literal(obj, nest_level=nest_level)


def _template_with_custom_css(managed_message: str, filename: str) -> List[str]:
Expand Down
13 changes: 6 additions & 7 deletions repo_helper/files/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

# 3rd party
import dom_toml
import pyproject_parser
from domdf_python_tools.paths import PathPlus
from natsort import natsorted, ns
from shippinglabel import normalize
Expand Down Expand Up @@ -259,7 +260,7 @@ def make_pyproject(repo_path: pathlib.Path, templates: Environment) -> List[str]
)
if invalid_lines:
raise NotImplementedError(f"Unsupported requirement type(s): {invalid_lines}")
data["project"]["dependencies"] = sorted(parsed_requirements)
data["project"]["dependencies"] = list(map(str, sorted(parsed_requirements)))
else:
data["project"]["dynamic"] = ["dependencies"]

Expand Down Expand Up @@ -452,7 +453,7 @@ def make_pyproject(repo_path: pathlib.Path, templates: Environment) -> List[str]
del data["tool"]

# TODO: managed message
dom_toml.dump(data, pyproject_file, encoder=dom_toml.TomlEncoder)
dom_toml.dump(data, pyproject_file, encoder=pyproject_parser.PyProjectTomlEncoder)

return [pyproject_file.name]

Expand All @@ -472,7 +473,7 @@ def make_setup(repo_path: pathlib.Path, templates: Environment) -> List[str]:
setup_file.unlink(missing_ok=True)

else:
setup = templates.get_template("setup._py")
setup_template = templates.get_template("setup._py")

data = dict(
extras_require="extras_require",
Expand All @@ -487,10 +488,8 @@ def make_setup(repo_path: pathlib.Path, templates: Environment) -> List[str]:
data["data_files"] = "[('share/applications', ['{modname}.desktop'])]".format_map(templates.globals)

setup_args = sorted({**data, **templates.globals["additional_setup_args"]}.items())

setup_file.write_clean(
setup.render(additional_setup_args='\n'.join(f"\t\t{k}={v}," for k, v in setup_args))
)
setup = setup_template.render(additional_setup_args='\n'.join(f"\t\t{k}={v}," for k, v in setup_args))
setup_file.write_clean(setup)

with resource(repo_helper.files, "isort.cfg") as isort_config:
yapf_style = PathPlus(isort_config).parent.parent / "templates" / "style.yapf"
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ click==7.1.2
configconfig>=0.5.0
consolekit>=1.2.2
dict2css>=0.2.0
dom-toml>=0.5.0
dom-toml>=2.0.0
domdf-python-tools>=3.2.0
dulwich>=0.20.5
first>=2.0.2
Expand All @@ -14,6 +14,7 @@ mkrecipe>=0.3.0
natsort>=7.1.1
packaging>=20.9
pypi-json>=0.2.1
pyproject-parser>=0.11.0
ruamel.yaml>=0.17.4
shippinglabel>=1.7.1
shippinglabel-conda>=0.1.0
Expand Down
Loading

0 comments on commit cc85a10

Please sign in to comment.