[gnome-builder] meson-templates: Add Python CLI Template
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] meson-templates: Add Python CLI Template
- Date: Sun, 27 Feb 2022 21:20:33 +0000 (UTC)
commit 0a6c4c98b226a3a705ac6e97e44e728c9a7086c7
Author: Fries <fries1234 protonmail com>
Date: Sun Feb 27 00:37:58 2022 -0800
meson-templates: Add Python CLI Template
This commit adds a Python Command Line Tool template.
.../meson-templates/meson-templates.gresource.xml | 3 +++
src/plugins/meson-templates/meson_templates.py | 12 +++++++++--
.../meson-templates/resources/src/hello-cli.py.in | 12 +++++++++++
.../meson-templates/resources/src/main-cli.py | 5 +++++
.../resources/src/meson-py-cli.build | 23 ++++++++++++++++++++++
5 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/meson-templates/meson-templates.gresource.xml
b/src/plugins/meson-templates/meson-templates.gresource.xml
index 0a7c526fe..aac749e2e 100644
--- a/src/plugins/meson-templates/meson-templates.gresource.xml
+++ b/src/plugins/meson-templates/meson-templates.gresource.xml
@@ -47,8 +47,10 @@
<file compressed="true">resources/src/main-gtk4.vala</file>
<file compressed="true">resources/src/main-cli.vala</file>
<file compressed="true">resources/src/hello.py.in</file>
+ <file compressed="true">resources/src/hello-cli.py.in</file>
<file compressed="true">resources/src/main.py</file>
<file compressed="true">resources/src/main-gtk4.py</file>
+ <file compressed="true">resources/src/main-cli.py</file>
<file compressed="true">resources/src/main.rs</file>
<file compressed="true">resources/src/main-gtk4.rs</file>
<file compressed="true">resources/src/main-cli.rs</file>
@@ -62,6 +64,7 @@
<file compressed="true">resources/build-aux/cargo.sh</file>
<file compressed="true">resources/meson.build</file>
<file compressed="true">resources/src/meson-cli.build</file>
+ <file compressed="true">resources/src/meson-py-cli.build</file>
<file compressed="true">resources/flatpak-gtksharp.json.tmpl</file>
<file compressed="true">resources/data/meson.build</file>
<file compressed="true">resources/data/hello.gschema.xml</file>
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index da682c74e..68ee0f563 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -174,6 +174,7 @@ class MesonTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
modes = {
'resources/src/hello.js.in': 0o750,
'resources/src/hello.py.in': 0o750,
+ 'resources/src/hello-cli.py.in': 0o750,
'resources/src/application.in': 0o750,
}
@@ -534,12 +535,15 @@ class CLIProjectTemplate(MesonTemplate):
_('Command Line Tool'),
'pattern-cli',
_('Create a new command line project'),
- ['C', 'C++', 'Vala', 'Rust'],
+ ['C', 'C++', 'Vala', 'Rust', 'Python'],
200
)
def prepare_files(self, files):
- files['resources/src/meson-cli.build'] = 'src/meson.build'
+ if self.language == 'python':
+ files['resources/src/meson-py-cli.build'] = 'src/meson.build'
+ else:
+ files['resources/src/meson-cli.build'] = 'src/meson.build'
if self.language == 'c':
files['resources/src/main-cli.c'] = 'src/main.c'
@@ -552,3 +556,7 @@ class CLIProjectTemplate(MesonTemplate):
files['resources/src/Cargo.lock'] = 'Cargo.lock'
files['resources/src/Cargo-cli.toml'] = 'Cargo.toml'
files['resources/build-aux/cargo.sh'] = 'build-aux/cargo.sh'
+ elif self.language == 'python':
+ files['resources/src/hello-cli.py.in'] = 'src/%(name)s.in'
+ files['resources/src/__init__.py'] = 'src/__init__.py'
+ files['resources/src/main-cli.py'] = 'src/main.py'
diff --git a/src/plugins/meson-templates/resources/src/hello-cli.py.in
b/src/plugins/meson-templates/resources/src/hello-cli.py.in
new file mode 100644
index 000000000..f21192744
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/hello-cli.py.in
@@ -0,0 +1,12 @@
+#!@PYTHON@
+
+{{include "license.py"}}
+
+import sys
+
+pkgdatadir = '@pkgdatadir@'
+sys.path.insert(1, pkgdatadir)
+
+if __name__ == '__main__':
+ from {{name_}} import main
+ sys.exit(main.main(sys.argv))
diff --git a/src/plugins/meson-templates/resources/src/main-cli.py
b/src/plugins/meson-templates/resources/src/main-cli.py
new file mode 100644
index 000000000..b0d87777b
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/main-cli.py
@@ -0,0 +1,5 @@
+{{include "license.py"}}
+
+def main(argv):
+ """This statement prints Hello, World to your console"""
+ print("Hello, World")
diff --git a/src/plugins/meson-templates/resources/src/meson-py-cli.build
b/src/plugins/meson-templates/resources/src/meson-py-cli.build
new file mode 100644
index 000000000..cbc888a74
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/meson-py-cli.build
@@ -0,0 +1,23 @@
+pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
+moduledir = join_paths(pkgdatadir, '{{name_}}')
+
+python = import('python')
+
+conf = configuration_data()
+conf.set('PYTHON', python.find_installation('python3').path())
+conf.set('pkgdatadir', pkgdatadir)
+
+configure_file(
+ input: '{{name}}.in',
+ output: '{{name}}',
+ configuration: conf,
+ install: true,
+ install_dir: get_option('bindir')
+)
+
+{{name_}}_sources = [
+ '__init__.py',
+ 'main.py'
+]
+
+install_data({{name_}}_sources, install_dir: moduledir)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]