Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Dec 23, 2024
1 parent 06a28ad commit 0efb1ba
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 136 deletions.
14 changes: 7 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__requires__ = [
'build',
'git-fame',
"build",
"git-fame",
'importlib_resources; python_version < "3.12"',
]

Expand All @@ -18,9 +18,9 @@


__all__ = [
'build_sdist',
'prepare_metadata_for_build_wheel',
'prepare_metadata_for_build_editable',
'build_wheel',
'build_editable',
"build_sdist",
"prepare_metadata_for_build_wheel",
"prepare_metadata_for_build_editable",
"build_wheel",
"build_editable",
]
4 changes: 2 additions & 2 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def run():
logging.basicConfig()
with bootstrap.write_pyproject():
runpy.run_module('build', run_name='__main__')
runpy.run_module("build", run_name="__main__")


__name__ == '__main__' and run()
__name__ == "__main__" and run()
52 changes: 26 additions & 26 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def __call__(self, info):
be omitted. Otherwise, mutate the object to include self.name
as a prefix.
"""
if info.name == '.':
if info.name == ".":
info.name = self.name
return info
ignore_pattern = '|'.join(self.ignored)
if re.match(ignore_pattern, r_fix(info.name).removeprefix('./')):
ignore_pattern = "|".join(self.ignored)
if re.match(ignore_pattern, r_fix(info.name).removeprefix("./")):
return
info.name = self.name + '/' + r_fix(info.name).removeprefix('./')
info.name = self.name + "/" + r_fix(info.name).removeprefix("./")
return info


Expand All @@ -68,17 +68,17 @@ class SDist(Filter):
namespace(name='foo/bar/dist')
"""

ignored = ['dist', r'(.*[/])?__pycache__$', r'(.*[/])?[.]']
ignored = ["dist", r"(.*[/])?__pycache__$", r"(.*[/])?[.]"]


class Wheel(Filter):
ignored = [
'docs',
'tests',
r'README.*',
'PKG-INFO',
re.escape('(meta)'),
re.escape('pyproject.toml'),
"docs",
"tests",
r"README.*",
"PKG-INFO",
re.escape("(meta)"),
re.escape("pyproject.toml"),
]


Expand All @@ -96,7 +96,7 @@ def wheel_walk(filter_: Wheel) -> Iterator[ZipInfo]:
"""
Walk the current directory, applying and honoring the filter for traversal.
"""
for root, dirs, files in os.walk('.'):
for root, dirs, files in os.walk("."):
zi = ZipInfo(path=root)
if not filter_(zi):
dirs[:] = []
Expand All @@ -107,8 +107,8 @@ def wheel_walk(filter_: Wheel) -> Iterator[ZipInfo]:


def make_sdist_metadata(metadata: Message) -> tarfile.TarInfo:
info = tarfile.TarInfo(f'{metadata.id}/PKG-INFO')
file = io.BytesIO(metadata.render().encode('utf-8'))
info = tarfile.TarInfo(f"{metadata.id}/PKG-INFO")
file = io.BytesIO(metadata.render().encode("utf-8"))
info.size = len(file.getbuffer())
info.mtime = time.time()
return info, file
Expand All @@ -117,7 +117,7 @@ def make_sdist_metadata(metadata: Message) -> tarfile.TarInfo:
def prepare_metadata(metadata_directory, config_settings=None):
metadata = Message.load() or Message.discover()

md_root = pathlib.Path(metadata_directory, f'{metadata.id}.dist-info')
md_root = pathlib.Path(metadata_directory, f"{metadata.id}.dist-info")
md_root.mkdir()
for name, contents in metadata.render_wheel():
md_root.joinpath(name).write_text(contents)
Expand All @@ -130,20 +130,20 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
or Message.load()
or Message.discover()
)
root = metadata['Name'].replace('.', '/')
filename = pathlib.Path(wheel_directory) / f'{metadata.id}-py3-none-any.whl'
with WheelFile(filename, 'w') as zf:
root = metadata["Name"].replace(".", "/")
filename = pathlib.Path(wheel_directory) / f"{metadata.id}-py3-none-any.whl"
with WheelFile(filename, "w") as zf:
for info in wheel_walk(Wheel(root)):
zf.write(info.path, arcname=info.name)
for name, contents in metadata.render_wheel():
zf.writestr(f'{metadata.id}.dist-info/{name}', contents)
zf.writestr(f"{metadata.id}.dist-info/{name}", contents)
return str(filename)


def build_sdist(sdist_directory, config_settings=None):
metadata = Message.discover()
filename = pathlib.Path(sdist_directory) / f'{metadata.id}.tar.gz'
with tarfile.open(filename, 'w:gz') as tf:
filename = pathlib.Path(sdist_directory) / f"{metadata.id}.tar.gz"
with tarfile.open(filename, "w:gz") as tf:
tf.add(pathlib.Path(), filter=SDist(metadata.id))
tf.addfile(*make_sdist_metadata(metadata))
return str(filename)
Expand All @@ -155,12 +155,12 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
or Message.load()
or Message.discover()
)
root = metadata['Name'].replace('.', '/')
filename = pathlib.Path(wheel_directory) / f'{metadata.id}-py3-none-any.whl'
with WheelFile(filename, 'w') as zf:
zf.writestr(f'{root}/__init__.py', proxy())
root = metadata["Name"].replace(".", "/")
filename = pathlib.Path(wheel_directory) / f"{metadata.id}-py3-none-any.whl"
with WheelFile(filename, "w") as zf:
zf.writestr(f"{root}/__init__.py", proxy())
for name, contents in metadata.render_wheel():
zf.writestr(f'{metadata.id}.dist-info/{name}', contents)
zf.writestr(f"{metadata.id}.dist-info/{name}", contents)
return str(filename)


Expand Down
4 changes: 2 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

def write_pyproject(target: pathlib.Path = pathlib.Path()) -> ContextManager[None]:
return assured(
target / 'pyproject.toml',
importlib.resources.files().joinpath('system.toml').read_text,
target / "pyproject.toml",
importlib.resources.files().joinpath("system.toml").read_text,
)


Expand Down
Loading

0 comments on commit 0efb1ba

Please sign in to comment.