From 6a69a91303f7834f86978306c9c4c93ee23ae0d4 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 2 Oct 2022 00:15:42 +0200 Subject: Implemented utility to quickly make namespaces in vis --- .gitignore | 2 ++ namespace.py | 36 ++++++++++++++++++++++++++++++++++++ pyproject.toml | 20 ++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100755 namespace.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b99f777 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +*.egg-info/ diff --git a/namespace.py b/namespace.py new file mode 100755 index 0000000..d7d3165 --- /dev/null +++ b/namespace.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +""" +Wraps standard input with C++ namespaces and writes it to standard output. Rather niche tool unless you rely too much +on pipes in your code editor. +""" + +import argparse +import sys + + +def split(path): + """Splits namespace path into parts.""" + return path.replace("::", "/").replace(":", "/").split("/") + + +def wrap(in_, out, namespaces): + """Wraps input with C++ namespaces and writes it to output handle.""" + for ns in namespaces: + out.write("namespace {}\n{}\n".format(ns, "{")) + out.write("\n\n") + for x in in_: + out.write(x) + out.write("\n\n") + for ns in reversed(namespaces): + out.write("{} // namespace {}\n".format("}", ns)) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("namespaces") + args = parser.parse_args() + wrap(sys.stdin, sys.stdout, split(args.namespaces)) + + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e8a98ff --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,20 @@ +[project] +name="namespace" +dynamic=["version"] + + +[project.scripts] +namespace="namespace:main" + + +[tool.setuptools_scm] +fallback_version="0" +version_scheme="post-release" + + +[build-system] +build-backend="setuptools.build_meta" +requires=[ + "setuptools>=45", + "setuptools_scm[toml]>=6.2", +] -- cgit v1.1