From cf2f5215c84b112ee75fe4552c9d48fc844686de Mon Sep 17 00:00:00 2001 From: James Westman Date: Sun, 17 Oct 2021 23:45:24 -0500 Subject: [PATCH] Add setup.py --- .gitignore | 3 ++ gtk-blueprint-tool.pc | 3 ++ gtk-blueprint-tool.pc.in | 3 ++ gtk-blueprint-tool.py | 4 +-- gtkblueprinttool/__init__.py | 0 gtkblueprinttool/main.py | 7 +++++ setup.py | 61 ++++++++++++++++++++++++++++++++++++ 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 gtk-blueprint-tool.pc create mode 100644 gtk-blueprint-tool.pc.in create mode 100644 gtkblueprinttool/__init__.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index bee8a64..f4fe942 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ __pycache__ +/build +/dist +*.egg-info diff --git a/gtk-blueprint-tool.pc b/gtk-blueprint-tool.pc new file mode 100644 index 0000000..8d2888a --- /dev/null +++ b/gtk-blueprint-tool.pc @@ -0,0 +1,3 @@ +Name: gtk-blueprint-tool +Description: Markup compiler for GTK user interface definitions +Version: 2021.1 \ No newline at end of file diff --git a/gtk-blueprint-tool.pc.in b/gtk-blueprint-tool.pc.in new file mode 100644 index 0000000..3e2bc4f --- /dev/null +++ b/gtk-blueprint-tool.pc.in @@ -0,0 +1,3 @@ +Name: gtk-blueprint-tool +Description: Markup compiler for GTK user interface definitions +Version: @VERSION@ diff --git a/gtk-blueprint-tool.py b/gtk-blueprint-tool.py index e7aed77..093c988 100755 --- a/gtk-blueprint-tool.py +++ b/gtk-blueprint-tool.py @@ -19,7 +19,7 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -from gtkblueprinttool.main import BlueprintApp +from gtkblueprinttool import main if __name__ == "__main__": - BlueprintApp().main() + main() diff --git a/gtkblueprinttool/__init__.py b/gtkblueprinttool/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gtkblueprinttool/main.py b/gtkblueprinttool/main.py index 66eb857..59227b7 100644 --- a/gtkblueprinttool/main.py +++ b/gtkblueprinttool/main.py @@ -25,6 +25,9 @@ from .pipeline import Pipeline from . import parser, tokenizer +VERSION = "0.1.0" + + class BlueprintApp: def main(self): self.parser = argparse.ArgumentParser() @@ -66,3 +69,7 @@ class BlueprintApp: except PrintableError as e: e.pretty_print(opts.input.name, data) sys.exit(1) + + +def main(): + BlueprintApp().main() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6f91520 --- /dev/null +++ b/setup.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2021 GNOME Foundation +# SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later + +# Adapted from the gi-docgen source code by James Westman + +import sys + +from gtkblueprinttool import main + +from distutils.command.build_py import build_py as _build_py +from setuptools import setup + + +class BuildCommand(_build_py): + + def generate_pkgconfig_file(self): + lines = [] + with open('gtk-blueprint-tool.pc.in', 'r') as f: + for line in f.readlines(): + new_line = line.strip().replace('@VERSION@', main.VERSION) + lines.append(new_line) + with open('gtk-blueprint-tool.pc', 'w') as f: + f.write('\n'.join(lines)) + + def run(self): + self.generate_pkgconfig_file() + return super().run() + + +def readme_md(): + '''Return the contents of the README.md file''' + return open('README.md').read() + + +entries = { + 'console_scripts': ['gtk-blueprint-tool=gtkblueprinttool.main:main'], +} + +packages = [ + 'gtkblueprinttool', +] + +data_files = [ + ('share/pkgconfig', ['gtk-blueprint-tool.pc']), +] + +if __name__ == '__main__': + setup( + cmdclass={ + 'build_py': BuildCommand, + }, + name='gtk-blueprint-tool', + version=main.VERSION, + license='GPL-3.0-or-later', + long_description=readme_md(), + long_description_content_type='text/markdown', + include_package_data=True, + packages=packages, + entry_points=entries, + data_files=data_files, + )