Skip to content

Commit

Permalink
Merge pull request #5 from vkottler/dev/0.1.3
Browse files Browse the repository at this point in the history
Initial file writing
  • Loading branch information
vkottler authored Aug 11, 2023
2 parents 8fbab2e + 613345e commit 8b50fa8
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=ifgen version=0.1.2
repo=ifgen version=0.1.3
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.3
hash=0cf37843aeaee823cd6a9128ae0b04d7
hash=2f24a731d6db776ce7018fe92edcd875
=====================================
-->

# ifgen ([0.1.2](https://pypi.org/project/ifgen/))
# ifgen ([0.1.3](https://pypi.org/project/ifgen/))

[![python](https://img.shields.io/pypi/pyversions/ifgen.svg)](https://pypi.org/project/ifgen/)
![Build Status](https://github.com/vkottler/ifgen/workflows/Python%20Package/badge.svg)
Expand Down
4 changes: 2 additions & 2 deletions ifgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.3
# hash=855ef60419d3d95b426724fc9c84173a
# hash=f6fabcab1f9396a648d63c6e71143370
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "An interface generator for distributed computing."
PKG_NAME = "ifgen"
VERSION = "0.1.2"
VERSION = "0.1.3"
2 changes: 1 addition & 1 deletion ifgen/commands/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def gen_cmd(args: _Namespace) -> int:
root, normalize(*config.data["output_dir"])
)

generate_structs(output, config)
generate_structs(root, output, config)

return 0

Expand Down
10 changes: 10 additions & 0 deletions ifgen/data/schemas/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ properties:
items:
type: string

command:
type: string
default: "\\"

namespace:
type: array
default: [Coral]
items:
type: string

structs:
type: object
additionalProperties: false
Expand Down
2 changes: 1 addition & 1 deletion ifgen/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
vcorelib
vcorelib>=2.4.6
46 changes: 43 additions & 3 deletions ifgen/struct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
"""

# built-in
from json import dumps
from multiprocessing import Pool
from pathlib import Path
from typing import Any, Dict, NamedTuple

# third-party
from vcorelib.io import IndentedFileWriter

# internal
from ifgen import PKG_NAME, VERSION
from ifgen.config import Config

StructConfig = Dict[str, Any]
Expand All @@ -16,25 +21,60 @@
class GenerateStructTask(NamedTuple):
"""Parameters necessary for struct generation."""

root: Path
path: Path
struct: StructConfig
config: Dict[str, Any]

def command(self, command: str, data: str = "", space: str = " ") -> str:
"""Get a command string."""
return (
str(self.config["command"])
+ command
+ (space if data else "")
+ data
)


def create_struct(task: GenerateStructTask) -> None:
"""Create a header file based on a struct definition."""

print(task)
with IndentedFileWriter.from_path(task.path, per_indent=4) as writer:
# Write file header.
with writer.javadoc():
writer.write(task.command("file"))
writer.write(
task.command("brief", f"Generated by {PKG_NAME} ({VERSION}).")
)
writer.empty()
writer.write(dumps(task.struct, indent=4))

writer.write("#pragma once")
writer.empty()

def generate_structs(output: Path, config: Config) -> None:
# Write namespace.
namespace = "::".join(task.config["namespace"])
writer.write(f"namespace {namespace}")
with writer.scope(suffix=f"; // namespace {namespace}"):
# Write struct definition.
writer.empty()
writer.cpp_comment("Testing.")
writer.empty()


def generate_structs(root: Path, output: Path, config: Config) -> None:
"""Generate struct files."""

output.mkdir(parents=True, exist_ok=True)

pool = Pool() # pylint: disable=consider-using-with
try:
pool.map(
create_struct,
(
GenerateStructTask(output.joinpath(f"{name}.h"), data)
GenerateStructTask(
root, output.joinpath(f"{name}.h"), data, config.data
)
for name, data in config.data["structs"].items()
),
)
Expand Down
2 changes: 1 addition & 1 deletion local/configs/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: An interface generator for distributed computing.
entry: {{entry}}

requirements:
- vcorelib
- vcorelib>=2.4.6

dev_requirements:
- pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 0
minor: 1
patch: 2
patch: 3
entry: ig
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "ifgen"
version = "0.1.2"
version = "0.1.3"
description = "An interface generator for distributed computing."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
1 change: 1 addition & 0 deletions tests/data/valid/scenarios/sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
2 changes: 2 additions & 0 deletions tests/data/valid/scenarios/sample/ifgen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
namespace: [A, B]

structs:
Test1: {}
Test2: {}

0 comments on commit 8b50fa8

Please sign in to comment.