Skip to content

Commit cfad50e

Browse files
committed
changed BabelMetadata to BabelConfig
1 parent be33883 commit cfad50e

File tree

5 files changed

+60
-60
lines changed

5 files changed

+60
-60
lines changed

babelizer/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def validate_dict_keys(
161161
Parameters
162162
----------
163163
meta : dict
164-
Configuration metadata
164+
Dictionary to validate.
165165
required : dict, optional
166166
Required keys in configuration.
167167
optional : dict, optional
@@ -170,7 +170,7 @@ def validate_dict_keys(
170170
Raises
171171
------
172172
ValidationError
173-
Raised for invalid metadata.
173+
Raised for invalid dict.
174174
"""
175175
actual = set(meta)
176176
required = set() if required is None else set(required)

babelizer/cli.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
from babelizer._files.readme import render as render_readme
2222
from babelizer._utils import get_setup_py_version
2323
from babelizer._utils import save_files
24+
from babelizer.config import BabelConfig
2425
from babelizer.errors import OutputDirExistsError
2526
from babelizer.errors import ScanError
2627
from babelizer.errors import SetupPyError
2728
from babelizer.errors import ValidationError
28-
from babelizer.metadata import BabelMetadata
2929
from babelizer.render import render
3030

3131
out = partial(click.secho, bold=True, err=True)
@@ -90,15 +90,15 @@ def init(
9090

9191
fmt = pathlib.Path(meta.name).suffix[1:] or "toml"
9292
try:
93-
babel_metadata = BabelMetadata.from_stream(cast(io.TextIOBase, meta), fmt=fmt)
93+
babel_config = BabelConfig.from_stream(cast(io.TextIOBase, meta), fmt=fmt)
9494
except (ScanError, ValidationError) as error:
9595
raise BabelizerAbort(str(error))
9696

97-
output = babel_metadata["package"]["name"]
97+
output = babel_config["package"]["name"]
9898

9999
try:
100100
new_folder = render(
101-
babel_metadata,
101+
babel_config,
102102
output,
103103
template=template,
104104
clobber=False,
@@ -149,14 +149,14 @@ def update(
149149
package_path = os.path.realpath(".")
150150
for fname in ("babel.toml", "babel.yaml", "plugin.yaml"):
151151
# if (package_path / fname).is_file():
152-
# metadata_path = package_path / fname
152+
# config_path = package_path / fname
153153
if os.path.isfile(os.path.join(package_path, fname)):
154-
metadata_path = os.path.join(package_path, fname)
154+
config_path = os.path.join(package_path, fname)
155155
break
156156
else:
157-
metadata_path = None
157+
config_path = None
158158

159-
if not metadata_path:
159+
if not config_path:
160160
err("this does not appear to be a babelized folder (missing 'babel.toml')")
161161
raise click.Abort()
162162

@@ -166,7 +166,7 @@ def update(
166166
out(f"reading template from {template}")
167167

168168
try:
169-
babel_metadata = BabelMetadata.from_path(metadata_path)
169+
babel_config = BabelConfig.from_path(config_path)
170170
except ValidationError as error:
171171
raise BabelizerAbort(str(error))
172172

@@ -187,7 +187,7 @@ def update(
187187
out(f"re-rendering {package_path}")
188188
with save_files(["CHANGES.rst", "CREDITS.rst"]):
189189
render(
190-
babel_metadata,
190+
babel_config,
191191
os.path.dirname(package_path),
192192
# package_path.parent,
193193
template=template,
@@ -196,7 +196,7 @@ def update(
196196
)
197197

198198
extra_files = _repo_contents(package_path) - _generated_files(
199-
babel_metadata, template=template, version=version
199+
babel_config, template=template, version=version
200200
)
201201

202202
ignore = ["meta*", "notebooks*", "docs*", "**/data"]
@@ -310,11 +310,11 @@ def _repo_contents(base: str) -> set[str]:
310310

311311

312312
def _generated_files(
313-
babel_metadata: BabelMetadata, template: str | None = None, version: str = "0.1"
313+
babel_config: BabelConfig, template: str | None = None, version: str = "0.1"
314314
) -> set[str]:
315315
with tempfile.TemporaryDirectory() as tmpdir:
316316
new_folder = render(
317-
babel_metadata,
317+
babel_config,
318318
tmpdir,
319319
template=template,
320320
version=version,

babelizer/metadata.py renamed to babelizer/config.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Library metadata used by the babelizer to wrap libraries."""
1+
"""Library configuration used by the babelizer to wrap libraries."""
22

33
from __future__ import annotations
44

@@ -27,8 +27,8 @@
2727
from babelizer.errors import ValidationError
2828

2929

30-
class BabelMetadata(Mapping[str, Any]):
31-
"""Library metadata."""
30+
class BabelConfig(Mapping[str, Any]):
31+
"""Babelizer configuration."""
3232

3333
LOADERS: dict[str, Callable[[str], dict[str, Any]]] = {
3434
"yaml": yaml.safe_load,
@@ -44,7 +44,7 @@ def __init__(
4444
plugin: dict[str, Any] | None = None,
4545
ci: dict[str, Any] | None = None,
4646
):
47-
"""Metadata used by the babelizer to wrap a library.
47+
"""Configuration used by the babelizer to wrap a library.
4848
4949
Parameters
5050
----------
@@ -77,9 +77,9 @@ def __init__(
7777
"ci": dict(ci or {}),
7878
}
7979

80-
BabelMetadata.validate(config)
80+
BabelConfig.validate(config)
8181

82-
self._meta = BabelMetadata.norm(config)
82+
self._meta = BabelConfig.norm(config)
8383

8484
def __getitem__(self, key: str) -> dict[str, Any]:
8585
return self._meta[key]
@@ -91,8 +91,8 @@ def __len__(self) -> int:
9191
return len(self._meta)
9292

9393
@classmethod
94-
def from_stream(cls, stream: io.TextIOBase, fmt: str = "toml") -> BabelMetadata:
95-
"""Create an instance of BabelMetadata from a file-like object.
94+
def from_stream(cls, stream: io.TextIOBase, fmt: str = "toml") -> BabelConfig:
95+
"""Create an instance of BabelConfig from a file-like object.
9696
9797
Parameters
9898
----------
@@ -103,28 +103,28 @@ def from_stream(cls, stream: io.TextIOBase, fmt: str = "toml") -> BabelMetadata:
103103
104104
Returns
105105
-------
106-
BabelMetadata
107-
A BabelMetadata instance.
106+
BabelConfig
107+
A BabelConfig instance.
108108
"""
109109
try:
110-
loader = BabelMetadata.LOADERS[fmt]
110+
loader = BabelConfig.LOADERS[fmt]
111111
except KeyError:
112112
raise ValueError(f"unrecognized format ({fmt})")
113113

114114
try:
115115
meta = loader(stream.read())
116116
except yaml.scanner.ScannerError as error:
117-
raise ScanError(f"unable to scan yaml-formatted metadata file:\n{error}")
117+
raise ScanError(f"unable to scan yaml-formatted config file:\n{error}")
118118
except tomllib.TOMLDecodeError as error:
119-
raise ScanError(f"unable to scan toml-formatted metadata file:\n{error}")
119+
raise ScanError(f"unable to scan toml-formatted config file:\n{error}")
120120
else:
121121
if not isinstance(meta, dict):
122-
raise ValidationError("metadata file does not contain a mapping object")
122+
raise ValidationError("config file does not contain a mapping object")
123123
return cls(**meta)
124124

125125
@classmethod
126-
def from_path(cls, filepath: str) -> BabelMetadata:
127-
"""Create an instance of BabelMetadata from a path-like object.
126+
def from_path(cls, filepath: str) -> BabelConfig:
127+
"""Create an instance of BabelConfig from a path-like object.
128128
129129
Parameters
130130
----------
@@ -133,26 +133,26 @@ def from_path(cls, filepath: str) -> BabelMetadata:
133133
134134
Returns
135135
-------
136-
A BabelMetadata instance.
136+
A BabelConfig instance.
137137
"""
138138
path = pathlib.Path(filepath)
139139

140140
with open(filepath) as fp:
141-
return BabelMetadata.from_stream(fp, fmt=path.suffix[1:])
141+
return BabelConfig.from_stream(fp, fmt=path.suffix[1:])
142142

143143
@staticmethod
144144
def validate(config: dict[str, Any]) -> None:
145-
"""Ensure babelizer configuration metadata are valid.
145+
"""Ensure babelizer configuration is valid.
146146
147147
Parameters
148148
----------
149149
config : dict
150-
Metadata to babelize a library.
150+
Configuration to babelize a library.
151151
152152
Raises
153153
------
154154
ValidationError
155-
If metadata are not valid.
155+
If configuration is not valid.
156156
"""
157157
libraries = config["library"]
158158
if "entry_point" in libraries:
@@ -253,29 +253,29 @@ def _handle_old_style_info(info: dict[str, Any]) -> dict[str, Any]:
253253

254254
@staticmethod
255255
def norm(config: dict[str, Any]) -> dict[str, Any]:
256-
"""Ensure current style metadata are used in babelizer configuration.
256+
"""Ensure current style is used in babelizer configuration.
257257
258258
Parameters
259259
----------
260260
config : dict
261-
Metadata to babelize a library.
261+
Configuration to babelize a library.
262262
263263
Return
264264
------
265265
dict
266-
A dict of babelizer configuration metadata.
266+
A dict of babelizer configuration.
267267
"""
268268
build: dict[str, list[str]] = defaultdict(list)
269269
with suppress(KeyError):
270270
build.update(config["build"])
271271

272272
if "entry_point" in config["library"]:
273-
libraries = BabelMetadata._handle_old_style_entry_points(config["library"])
273+
libraries = BabelConfig._handle_old_style_entry_points(config["library"])
274274
else:
275275
libraries = {k: dict(v) for k, v in config["library"].items()}
276276

277277
if "plugin_author" in config["info"]:
278-
info = BabelMetadata._handle_old_style_info(config["info"])
278+
info = BabelConfig._handle_old_style_info(config["info"])
279279
else:
280280
info = config["info"]
281281

@@ -309,7 +309,7 @@ def norm(config: dict[str, Any]) -> dict[str, Any]:
309309
}
310310

311311
def dump(self, fp: io.TextIOBase, fmt: str = "toml") -> None:
312-
"""Write serialized metadata to a file.
312+
"""Write serialized configuration to a file.
313313
314314
Parameters
315315
----------
@@ -321,7 +321,7 @@ def dump(self, fp: io.TextIOBase, fmt: str = "toml") -> None:
321321
print(self.format(fmt=fmt), file=fp, end="")
322322

323323
def format(self, fmt: str = "toml") -> str:
324-
"""Serialize metadata to output format.
324+
"""Serialize configuration to output format.
325325
326326
Parameters
327327
----------
@@ -330,17 +330,17 @@ def format(self, fmt: str = "toml") -> str:
330330
331331
Returns
332332
-------
333-
metadata : str
334-
Serialized metadata.
333+
config : str
334+
Serialized configuration.
335335
"""
336336
return getattr(self, f"format_{fmt}")()
337337

338338
def format_toml(self) -> str:
339-
"""Serialize metadata as TOML.
339+
"""Serialize configuration as TOML.
340340
341341
Returns
342342
-------
343343
str
344-
Serialized metadata as a TOML-formatted string
344+
Serialized configuration as a TOML-formatted string
345345
"""
346346
return tomli_w.dumps(self._meta, multiline_strings=True)

babelizer/render.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
from babelizer._files.init_py import render as render_init
1515
from babelizer._files.lib_init_py import render as render_lib_init
1616
from babelizer._files.license_rst import render as render_license
17+
from babelizer.config import BabelConfig
1718
from babelizer.errors import OutputDirExistsError
18-
from babelizer.metadata import BabelMetadata
1919

2020

2121
def render(
22-
plugin_metadata: BabelMetadata,
22+
babel_config: BabelConfig,
2323
output: str,
2424
template: str | None = None,
2525
clobber: bool = False,
@@ -30,8 +30,8 @@ def render(
3030
3131
Parameters
3232
----------
33-
plugin_metadata : BabelMetadata
34-
The metadata used to babelize the library.
33+
babel_config : BabelConfig
34+
The configuration used to babelize the library.
3535
output : str
3636
Name of the directory that will be the new repository.
3737
template : str, optional
@@ -58,15 +58,15 @@ def render(
5858

5959
context = {
6060
"files": {
61-
"_bmi.py": render_bmi(plugin_metadata),
62-
"__init__.py": render_init(plugin_metadata),
63-
"lib/__init__.py": render_lib_init(plugin_metadata),
64-
".gitignore": render_gitignore(plugin_metadata),
65-
"LICENSE.rst": render_license(plugin_metadata),
61+
"_bmi.py": render_bmi(babel_config),
62+
"__init__.py": render_init(babel_config),
63+
"lib/__init__.py": render_lib_init(babel_config),
64+
".gitignore": render_gitignore(babel_config),
65+
"LICENSE.rst": render_license(babel_config),
6666
},
6767
"now": datetime.datetime.now(),
6868
"package_version": version,
69-
} | {k: plugin_metadata[k] for k in plugin_metadata}
69+
} | {k: babel_config[k] for k in babel_config}
7070

7171
if os.path.exists(output):
7272
raise OutputDirExistsError(output)
@@ -76,7 +76,7 @@ def render(
7676
path = os.path.realpath(output)
7777

7878
with open(os.path.join(path, "babel.toml"), "w") as fp:
79-
plugin_metadata.dump(fp, fmt="toml")
79+
babel_config.dump(fp, fmt="toml")
8080

8181
git.Repo.init(path)
8282

tests/cli_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from click.testing import CliRunner
1111

1212
from babelizer.cli import babelize
13-
from babelizer.metadata import BabelMetadata
13+
from babelizer.config import BabelConfig
1414

1515

1616
def test_help():
@@ -67,7 +67,7 @@ def test_generate_gives_valid_toml():
6767
assert result.exit_code == 0
6868

6969
config = tomllib.loads(result.output)
70-
BabelMetadata.validate(config)
70+
BabelConfig.validate(config)
7171

7272

7373
def test_init_noargs():

0 commit comments

Comments
 (0)