[gnome-builder/wip/tingping/python-template] autotools-templates: Add Python Gnome project
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/tingping/python-template] autotools-templates: Add Python Gnome project
- Date: Fri, 19 Aug 2016 01:17:05 +0000 (UTC)
commit fa22bc45bd146ea3850b91aeff9fb9a466c96727
Author: Patrick Griffis <tingping tingping se>
Date: Thu Aug 18 21:15:49 2016 -0400
autotools-templates: Add Python Gnome project
plugins/autotools-templates/Makefile.am | 4 +++
.../autotools_templates/__init__.py | 23 +++++++++++++----
.../autotools_templates/resources/Makefile.am | 2 +-
.../resources/bin/Makefile.gnome-app | 15 ++++++++++++
.../autotools_templates/resources/bin/wrapper.py | 19 +++++++++++++++
.../autotools_templates/resources/configure.ac | 21 ++++++++++++++++
.../resources/src/Makefile.gnome-app-python | 4 +++
.../autotools_templates/resources/src/__main__.py | 25 ++++++++++++++++++++
8 files changed, 106 insertions(+), 7 deletions(-)
---
diff --git a/plugins/autotools-templates/Makefile.am b/plugins/autotools-templates/Makefile.am
index 6ffed25..22dbc8d 100644
--- a/plugins/autotools-templates/Makefile.am
+++ b/plugins/autotools-templates/Makefile.am
@@ -18,6 +18,8 @@ nobase_resource_DATA = \
autotools_templates/resources/data/Makefile.am \
autotools_templates/resources/data/package.pc.in \
autotools_templates/resources/git.mk \
+ autotools_templates/resources/bin/Makefile.gnome-app \
+ autotools_templates/resources/bin/wrapper.py \
autotools_templates/resources/m4/Makefile.am \
autotools_templates/resources/m4/appstream-xml.m4 \
autotools_templates/resources/m4/ax_append_compile_flags.m4 \
@@ -39,11 +41,13 @@ nobase_resource_DATA = \
autotools_templates/resources/po/LINGUAS \
autotools_templates/resources/po/Makevars \
autotools_templates/resources/po/POTFILES.in \
+ autotools_templates/resources/src/__main__.py \
autotools_templates/resources/src/main.c \
autotools_templates/resources/src/main.cpp \
autotools_templates/resources/src/main.vala \
autotools_templates/resources/src/Makefile.empty \
autotools_templates/resources/src/Makefile.gnome-app \
+ autotools_templates/resources/src/Makefile.gnome-app-python \
autotools_templates/resources/src/Makefile.shared-library-c \
autotools_templates/resources/src/Makefile.shared-library-vala \
autotools_templates/resources/src/package-version.h.in \
diff --git a/plugins/autotools-templates/autotools_templates/__init__.py
b/plugins/autotools-templates/autotools_templates/__init__.py
index 2c2bbfa..fcfbf38 100644
--- a/plugins/autotools-templates/autotools_templates/__init__.py
+++ b/plugins/autotools-templates/autotools_templates/__init__.py
@@ -110,7 +110,7 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
if 'language' in params:
self.language = params['language'].get_string().lower()
- if self.language not in ('c', 'c++', 'vala'):
+ if self.language not in ('c', 'c++', 'vala', 'python'):
task.return_error(GLib.Error("Language %s not supported" %
self.language))
return
@@ -135,8 +135,10 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
prefix_ = prefix.lower().replace('-','_')
PreFix = ''.join([word.capitalize() for word in prefix.lower().split('-')])
+ name_ = name.lower().replace('-','_')
+
scope.get('name').assign_string(name)
- scope.get('name_').assign_string(name.lower().replace('-','_'))
+ scope.get('name_').assign_string(name_)
scope.get('NAME').assign_string(name.upper().replace('-','_'))
scope.get('prefix').assign_string(prefix)
@@ -150,11 +152,12 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
scope.get('major_version').assign_string('0')
scope.get('minor_version').assign_string('1')
scope.get('micro_version').assign_string('0')
- scope.get('enable_c').assign_boolean(True)
+ scope.get('enable_c').assign_boolean(self.language in ('c', 'vala', 'c++'))
+ scope.get('enable_python').assign_boolean(self.language == 'python')
scope.get('enable_cplusplus').assign_boolean(self.language == 'c++')
scope.get('enable_i18n').assign_boolean(True)
scope.get('enable_gtk_doc').assign_boolean(False)
- scope.get('enable_gobject_introspection').assign_boolean(True)
+ scope.get('enable_gobject_introspection').assign_boolean(self.language in ('c', 'vala', 'c++'))
scope.get('enable_vapi').assign_boolean(self.language == 'c')
scope.get('enable_vala').assign_boolean(self.language == 'vala')
scope.get('translation_copyright').assign_string('Translation copyright holder')
@@ -166,6 +169,7 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
expands = {
'name': name,
+ 'name_': name_,
'prefix': prefix,
'PreFix': PreFix,
}
@@ -304,7 +308,7 @@ class GnomeProjectTemplate(AutotoolsTemplate):
_("GNOME Application"),
'pattern-gnome',
_("Create a new flatpak-ready GNOME application"),
- ['C', 'C++', 'Vala']
+ ['C', 'C++', 'Vala', 'Python']
)
def get_packages(self):
@@ -316,7 +320,11 @@ class GnomeProjectTemplate(AutotoolsTemplate):
return ""
def prepare_files(self, files):
- files['resources/src/Makefile.gnome-app'] = 'src/Makefile.am'
+ if self.language in ('c', 'c++', 'vala'):
+ files['resources/src/Makefile.gnome-app'] = 'src/Makefile.am'
+ elif self.language == 'python':
+ files['resources/bin/Makefile.gnome-app'] = 'bin/Makefile.am'
+ files['resources/src/Makefile.gnome-app-python'] = '%(name_)s/Makefile.am'
if self.versioning == 'git':
files['resources/ManifestTemplate.flatpak.json'] = 'org.gnome.%(PreFix)s.flatpak.json'
@@ -327,4 +335,7 @@ class GnomeProjectTemplate(AutotoolsTemplate):
files['resources/src/main.cpp'] = 'src/main.cpp'
elif self.language == 'vala':
files['resources/src/main.vala'] = 'src/main.vala'
+ elif self.language == 'python':
+ files['resources/src/__main__.py'] = '%(name_)s/__main__.py'
+ files['resources/bin/wrapper.py'] = 'bin/%(name)s.in'
diff --git a/plugins/autotools-templates/autotools_templates/resources/Makefile.am
b/plugins/autotools-templates/autotools_templates/resources/Makefile.am
index 2be5da8..3b48713 100644
--- a/plugins/autotools-templates/autotools_templates/resources/Makefile.am
+++ b/plugins/autotools-templates/autotools_templates/resources/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = data src{{if enable_i18n}} po{{end}}
+SUBDIRS = data{{if enable_c}} src{{end}}{{if enable_python}} {{name_}} bin{{end}}{{if enable_i18n}} po{{end}}
EXTRA_DIST = AUTHORS
diff --git a/plugins/autotools-templates/autotools_templates/resources/bin/Makefile.gnome-app
b/plugins/autotools-templates/autotools_templates/resources/bin/Makefile.gnome-app
new file mode 100644
index 0000000..4958309
--- /dev/null
+++ b/plugins/autotools-templates/autotools_templates/resources/bin/Makefile.gnome-app
@@ -0,0 +1,15 @@
+bin_SCRIPTS = {{name}}
+
+{{name}}: {{name}}.in
+ @$(MKDIR_P) bin
+ $(AM_V_GEN)$(SED) \
+{{if enable_i18n}} -e s!\@localedir\@!$(localedir)! \ {{end}}
+ -e s!\@pythondir\@!$(pythondir)! \
+ -e s!\@PYTHON\@!$(PYTHON)! \
+ < $< > $@
+ @chmod a+x $@
+
+BUILD_SOURCES = $(bin_SCRIPTS)
+EXTRA_DIST = {{name}}.in
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/autotools-templates/autotools_templates/resources/bin/wrapper.py
b/plugins/autotools-templates/autotools_templates/resources/bin/wrapper.py
new file mode 100644
index 0000000..a5bc14d
--- /dev/null
+++ b/plugins/autotools-templates/autotools_templates/resources/bin/wrapper.py
@@ -0,0 +1,19 @@
+#!@PYTHON@
+
+import sys
+{{if enable_i18n}}
+import locale
+import gettext
+
+localedir = '@localedir@'
+
+locale.bindtextdomain('{{name}}', localedir)
+locale.textdomain('{{name}}')
+gettext.bindtextdomain('{{name}}', localedir)
+gettext.textdomain('{{name}}')
+{{end}}
+
+if __name__ == "__main__":
+ sys.path.insert(1, '@pythondir@')
+ from {{name_}} import __main__
+ __main__.main()
diff --git a/plugins/autotools-templates/autotools_templates/resources/configure.ac
b/plugins/autotools-templates/autotools_templates/resources/configure.ac
index af75957..6372bff 100644
--- a/plugins/autotools-templates/autotools_templates/resources/configure.ac
+++ b/plugins/autotools-templates/autotools_templates/resources/configure.ac
@@ -70,11 +70,14 @@ AM_GNU_GETTEXT([external])
dnl ***********************************************************************
dnl Check for required programs
dnl ***********************************************************************
+{{if enable_c}}
AC_PROG_CC
+{{end}}
{{if enable_cplusplus}}
AC_PROG_CXX
{{end}}
AC_PROG_INSTALL
+AC_PROG_SED
AC_PATH_PROG([GLIB_GENMARSHAL],[glib-genmarshal])
AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
AC_PATH_PROG([GLIB_COMPILE_RESOURCES],[glib-compile-resources])
@@ -89,9 +92,11 @@ AM_PROG_VALAC([0.32])
{{if enable_vapi}}
VAPIGEN_CHECK
{{end}}
+{{if enable_c}}
AX_COMPILER_FLAGS
+{{end}}
{{if enable_c}}
@@ -112,6 +117,15 @@ AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
{{end}}
+{{if enable_python}}
+dnl ***********************************************************************
+dnl Check for required Python
+dnl ***********************************************************************
+AM_PATH_PYTHON([3.3])
+
+
+{{end}}
+{{if enable_c}}
dnl ***********************************************************************
dnl Check for required packages
dnl ***********************************************************************
@@ -125,13 +139,20 @@ LT_PREREQ([2.2])
LT_INIT
+{{end}}
dnl ***********************************************************************
dnl Process .in Files
dnl ***********************************************************************
AC_CONFIG_FILES([
Makefile
+{{if enable_c}}
src/Makefile
+{{end}}
+{{if enable_python}}
+ bin/Makefile
+ {{name_}}/Makefile
+{{end}}
{{if template == "shared-library"}}
{{if language != "vala"}}
src/{{prefix}}-version.h
diff --git a/plugins/autotools-templates/autotools_templates/resources/src/Makefile.gnome-app-python
b/plugins/autotools-templates/autotools_templates/resources/src/Makefile.gnome-app-python
new file mode 100644
index 0000000..75f0d38
--- /dev/null
+++ b/plugins/autotools-templates/autotools_templates/resources/src/Makefile.gnome-app-python
@@ -0,0 +1,4 @@
+moduledir = $(pythondir)/{{name_}}
+module_PYTHON = __main__.py
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/autotools-templates/autotools_templates/resources/src/__main__.py
b/plugins/autotools-templates/autotools_templates/resources/src/__main__.py
new file mode 100644
index 0000000..51a6916
--- /dev/null
+++ b/plugins/autotools-templates/autotools_templates/resources/src/__main__.py
@@ -0,0 +1,25 @@
+{{include "license.py"}}
+
+import sys
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+
+class Application(Gtk.Application):
+ def __init__(self, **kwargs):
+ super().__init__(application_id='org.gnome.{{PreFix}}',
+ **kwargs)
+
+ def do_activate(self):
+ window = Gtk.ApplicationWindow.new(self)
+ window.set_default_size(200, 200)
+ window.set_title('{{name}}')
+ window.present()
+
+
+def main():
+ application = Application()
+ sys.exit(application.run(sys.argv))
+
+if __name__ == '__main__':
+ main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]