From 9eadb1fe4de9018772eae39b4a58473008f922af Mon Sep 17 00:00:00 2001 From: TingPing Date: Mon, 25 May 2015 15:15:28 -0400 Subject: [PATCH] Migrate to autotools The reasoning for this is that this is more a gnome application than a python module and as such autotools is more integrated to that ecosystem which allows for eaiser handling for: - GResource - GSettings - Translations - Appdata/Desktop files - Icons Fixes #61 --- .gitignore | 31 +++++------- MANIFEST.in | 4 -- Makefile.am | 69 +++++++++++++++++++++++++++ autogen.sh | 25 ++++++++++ bin/pithos.in | 16 +++++++ configure.ac | 23 +++++++++ debug.py | 27 ----------- m4/appstream-xml.m4 | 86 ++++++++++++++++++++++++++++++++++ m4/desktop.m4 | 102 ++++++++++++++++++++++++++++++++++++++++ setup.py | 112 -------------------------------------------- 10 files changed, 332 insertions(+), 163 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 Makefile.am create mode 100755 autogen.sh create mode 100644 bin/pithos.in create mode 100644 configure.ac delete mode 100755 debug.py create mode 100644 m4/appstream-xml.m4 create mode 100644 m4/desktop.m4 delete mode 100755 setup.py diff --git a/.gitignore b/.gitignore index bfbd6486..2151a8e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,13 @@ __pycache__/ *.py[cod] -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg -config/ -*.patch -debian/ -build-debian.sh -.project -.pydevproject -.settings/ +bin/pithos +Makefile.in +Makefile +configure +missing +py-compile +m4/ +config.* +autom4te.cache/ +aclocal.m4 +install-sh diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index ef1fa64d..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,4 +0,0 @@ -include README.md -recursive-include data *.svg pithos.desktop *.xml -recursive-include pithos/data/ui *.ui *.xml -recursive-include pithos/data/media *.png *.svg diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..75c41f0a --- /dev/null +++ b/Makefile.am @@ -0,0 +1,69 @@ +ACLOCAL_AMFLAGS = -I m4 + +# ----------- pithos -------------- + +pithosdir = $(pythondir)/pithos/ +pithos_PYTHON = $(wildcard pithos/*.py) + +pandoradir = $(pithosdir)/pandora +pandora_PYTHON = $(wildcard pithos/pandora/*.py) + +pluginsdir = $(pithosdir)/plugins +plugins_PYTHON = $(wildcard pithos/plugins/*.py) + +pithosmediadir = $(pithosdir)/data/media +pithosmedia_DATA = \ + $(wildcard pithos/data/media/*.svg) \ + $(wildcard pithos/data/media/*.png) + +pithosuidir = $(pithosdir)/data/ui +pithosui_DATA = \ + $(wildcard pithos/data/ui/*.xml) \ + $(wildcard pithos/data/ui/*.ui) + +bin_SCRIPTS = bin/pithos +bin/pithos: bin/pithos.in + @$(MKDIR_P) bin + $(AM_V_GEN)sed \ + -e s!\@prefix\@!$(prefix)! \ + -e s!\@datadir\@!$(datadir)! \ + -e s!\@pkgdatadir\@!$(pkgdatadir)! \ + -e s!\@pkglibdir\@!$(pkglibdir)! \ + -e s!\@localedir\@!$(localedir)! \ + -e s!\@pythondir\@!$(pythondir)! \ + -e s!\@pyexecdir\@!$(pyexecdir)! \ + < $< > $@ + @chmod a+x $@ + +# ------------ data ---------------- + +desktop_FILES = data/pithos.desktop +@DESKTOP_FILE_RULES@ + +appstream_XML = data/pithos.appdata.xml +@APPSTREAM_XML_RULES@ + +hicolor_scalabledir = $(datadir)/icons/hicolor/scalable/apps +hicolor_scalable_DATA = $(wildcard data/icons/hicolor/pithos*.svg) + +hicolor_48dir = $(datadir)/icons/hicolor/48x48/apps +hicolor_48_DATA = $(wildcard data/icons/hicolor/pithos*.png) + +ubuntu_lightdir = $(datadir)/icons/ubuntu-mono-light/apps/16 +ubuntu_light_DATA = $(wildcard data/icons/ubuntu-mono-light/pithos*.svg) + +ubuntu_darkdir = $(datadir)/icons/ubuntu-mono-dark/apps/16 +ubuntu_dark_DATA = $(wildcard data/icons/ubuntu-mono-dark/pithos*.svg) + +UPDATE_ICON_CACHE = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor || : + +install-data-hook: + $(UPDATE_ICON_CACHE); + +uninstall-hook: + $(UPDATE_ICON_CACHE); + +CLEANFILES = $(bin_SCRIPTS) +EXTRA_DIST = license README.md autogen.sh requirements-osx.txt bin/pithos.in \ + $(pithosui_DATA) $(pithosmedia_DATA) $(appstream_XML) $(desktop_FILES) \ + $(hicolor_scalable_DATA) $(hicolor_48_DATA) $(ubuntu_light_DATA) $(ubuntu_dark_DATA) diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 00000000..d4ab98ae --- /dev/null +++ b/autogen.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +(test -f $srcdir/configure.ac) || { + echo -n "**Error**: Directory "\`$srcdir\'" does not look like the top-level directory" + exit 1 +} + +aclocal --install -I m4 || exit 1 +autoreconf --force --install -Wno-portability || exit 1 + +if [ "$NOCONFIGURE" = "" ]; then + $srcdir/configure "$@" || exit 1 + + if [ "$1" = "--help" ]; then exit 0 else + echo "Now type \`make\' to compile" || exit 1 + fi +else + echo "Skipping configure process." +fi + +set +x diff --git a/bin/pithos.in b/bin/pithos.in new file mode 100644 index 00000000..f2e69907 --- /dev/null +++ b/bin/pithos.in @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import os +import sys + +sys.path.insert(1, '@pyexecdir@') +sys.path.insert(1, '@pythondir@') + +srcdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +if os.path.exists(os.path.join(srcdir, 'configure.ac')): + print('Running locally...') + sys.path.insert(1, srcdir) + +if __name__ == "__main__": + from pithos import application + application.main() diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..7e37afa8 --- /dev/null +++ b/configure.ac @@ -0,0 +1,23 @@ +AC_PREREQ(2.68) +AC_INIT([pithos], [1.1.1], [https://github.com/pithos/pithos/issues], + [pithos], [https://pithos.github.io]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_SRCDIR([pithos/__main__.py]) + +AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip foreign subdir-objects -Wall -Wno-portability]) +AM_SILENT_RULES([yes]) +AM_PATH_PYTHON([3.3]) + +DESKTOP_FILE +APPSTREAM_XML + +AC_CONFIG_FILES([ + Makefile +]) +AC_OUTPUT + +echo " + $PACKAGE $VERSION + + prefix: ${prefix} +" diff --git a/debug.py b/debug.py deleted file mode 100755 index 9823e2e4..00000000 --- a/debug.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -# None of this works on Windows atm -if sys.platform != 'win32': - - # Store config locally - config_dir = os.path.abspath('./config') - os.environ['XDG_CONFIG_HOME'] = config_dir - - # Migrate old debug_config - old_config_dir = os.path.abspath('./debug_config') - if os.path.exists(old_config_dir): - os.rename(old_config_dir, config_dir) - - if not os.path.exists(config_dir): - os.makedirs(config_dir) - - # Enable verbose logging and test mode - if len(sys.argv) == 1: - sys.argv.append('-tvv') - -from pithos import application - -application.main() diff --git a/m4/appstream-xml.m4 b/m4/appstream-xml.m4 new file mode 100644 index 00000000..1472802b --- /dev/null +++ b/m4/appstream-xml.m4 @@ -0,0 +1,86 @@ +# appstream-xml.m4 +# +# serial 6 + +dnl APPSTREAM_XML +dnl Installs and validates AppData XML files. +dnl +dnl Call APPSTREAM_XML in configure.ac to check for the appstream-util tool. +dnl Add @APPSTREAM_XML_RULES@ to a Makefile.am to substitute the make rules. Add +dnl .appdata.xml files to appstream_XML in Makefile.am and they will be validated +dnl at make check time, if appstream-util is installed, as well as installed +dnl to the correct location automatically. Add --enable-appstream-util to +dnl DISTCHECK_CONFIGURE_FLAGS in Makefile.am to require valid AppData XML when +dnl doing a distcheck. +dnl +dnl Adding files to appstream_XML does not distribute them automatically. + +AC_DEFUN([APPSTREAM_XML], +[ + m4_pattern_allow([AM_V_GEN]) + AC_ARG_ENABLE([appstream-util], + [AS_HELP_STRING([--disable-appstream-util], + [Disable validating AppData XML files during check phase])]) + + AS_IF([test "x$enable_appstream_validate" != "xno"], + [AC_PATH_PROG([APPSTREAM_UTIL], [appstream-util]) + AS_IF([test "x$APPSTREAM_UTIL" = "x"], + [have_appstream_validate=no], + [have_appstream_validate=yes + AC_SUBST([APPSTREAM_UTIL])])], + [have_appstream_validate=no]) + + AS_IF([test "x$have_appstream_validate" != "xno"], + [appstream_validate=yes], + [appstream_validate=no + AS_IF([test "x$enable_appstream_validate" = "xyes"], + [AC_MSG_ERROR([AppData validation was requested but appstream-util was not found])])]) + + AC_SUBST([appstreamxmldir], [${datadir}/appdata]) + + APPSTREAM_XML_RULES=' +.PHONY : uninstall-appstream-xml install-appstream-xml clean-appstream-xml + +mostlyclean-am: clean-appstream-xml + +%.appdata.valid: %.appdata.xml + $(AM_V_GEN) if test -f "$<"; then d=; else d="$(srcdir)/"; fi; \ + if test -n "$(APPSTREAM_UTIL)"; \ + then $(APPSTREAM_UTIL) --nonet validate $${d}$<; fi \ + && touch [$]@ + +check-am: $(appstream_XML:.appdata.xml=.appdata.valid) +uninstall-am: uninstall-appstream-xml +install-data-am: install-appstream-xml + +.SECONDARY: $(appstream_XML) + +install-appstream-xml: $(appstream_XML) + @$(NORMAL_INSTALL) + if test -n "$^"; then \ + test -z "$(appstreamxmldir)" || $(MKDIR_P) "$(DESTDIR)$(appstreamxmldir)"; \ + $(INSTALL_DATA) $^ "$(DESTDIR)$(appstreamxmldir)"; \ + fi + +uninstall-appstream-xml: + @$(NORMAL_UNINSTALL) + @list='\''$(appstream_XML)'\''; test -n "$(appstreamxmldir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e '\''s|^.*/||'\''`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '\''$(DESTDIR)$(appstreamxmldir)'\'' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(appstreamxmldir)" && rm -f $$files + +clean-appstream-xml: + rm -f $(appstream_XML:.appdata.xml=.appdata.valid) +' + _APPSTREAM_XML_SUBST(APPSTREAM_XML_RULES) +]) + +dnl _APPSTREAM_XML_SUBST(VARIABLE) +dnl Abstract macro to do either _AM_SUBST_NOTMAKE or AC_SUBST +AC_DEFUN([_APPSTREAM_XML_SUBST], +[ +AC_SUBST([$1]) +m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([$1])]) +] +) diff --git a/m4/desktop.m4 b/m4/desktop.m4 new file mode 100644 index 00000000..ad8f70ec --- /dev/null +++ b/m4/desktop.m4 @@ -0,0 +1,102 @@ +# desktop.m4 +# +# serial 4 + +dnl DESKTOP_VALIDATE +dnl Validates and installs desktop files. +dnl +dnl To use: +dnl 1. Call DESKTOP_FILE in configure.ac to check for the desktop-file-utils tools. +dnl 2. Add @DESKTOP_FILE_RULES@ to a Makefile.am to substitute the make rules. +dnl 3. Add .desktop files to desktop_FILES in Makefile.am and they will be validated +dnl at make check time and installed on make install. +dnl 4. Add --enable-desktop-validate to DISTCHECK_CONFIGURE_FLAGS +dnl in Makefile.am to require valid desktop file when doing a distcheck. +dnl +dnl On installation desktop-file-install will be used when available which also +dnl rebuilds the mime info cache. After install update-desktop-database is called. +dnl +dnl Author: TingPing +dnl Based upon appdata-xml.m4 + +AC_DEFUN([DESKTOP_FILE], +[ + m4_pattern_allow([AM_V_GEN]) + AC_ARG_ENABLE([desktop-validate], + [AS_HELP_STRING([--disable-desktop-validate], + [Disable validating desktop files during check phase])]) + + AS_IF([test "x$enable_desktop_validate" != "xno"], + [AC_PATH_PROG([DESKTOP_FILE_VALIDATE], [desktop-file-validate]) + AS_IF([test "x$DESKTOP_FILE_VALIDATE" = "x"], + [have_desktop_validate=no], + [have_desktop_validate=yes + AC_SUBST([DESKTOP_FILE_VALIDATE])])], + [have_desktop_validate=no]) + + AC_PATH_PROG([UPDATE_DESKTOP_DATABASE], [update-desktop-database]) + AS_IF([test "x$UPDATE_DESKTOP_DATABASE" != "x"], [AC_SUBST([UPDATE_DESKTOP_DATABASE])]) + + AC_PATH_PROG([DESKTOP_FILE_INSTALL], [desktop-file-install]) + AS_IF([test "x$DESKTOP_FILE_INSTALL" != "x"], [AC_SUBST([DESKTOP_FILE_INSTALL])]) + + AS_IF([test "x$have_desktop_validate" != "xno"], + [desktop_validate=yes], + [desktop_validate=no + AS_IF([test "x$enable_desktop_validate" = "xyes"], + [AC_MSG_ERROR([Desktop validation was requested but desktop-file-validate was not found])])]) + + AC_SUBST([desktopfiledir], [${datadir}/applications]) + + DESKTOP_FILE_RULES=' +.PHONY : uninstall-desktop-file install-desktop-file clean-desktop-file + +mostlyclean-am: clean-desktop-file + +%.desktop.valid: %.desktop + $(AM_V_GEN) if test -f "$<"; then d=; else d="$(srcdir)/"; fi; \ + if test -n "$(DESKTOP_FILE_VALIDATE)"; \ + then $(DESKTOP_FILE_VALIDATE) $${d}$<; fi \ + && touch [$]@ + +check-am: $(desktop_FILES:.desktop=.desktop.valid) +uninstall-am: uninstall-desktop-file +install-data-am: install-desktop-file + +.SECONDARY: $(desktop_FILES) + +install-desktop-file: $(desktop_FILES) + @$(NORMAL_INSTALL) + if test -n "$^"; then \ + test -z "$(desktopfiledir)" || $(MKDIR_P) "$(DESTDIR)$(desktopfiledir)"; \ + if test -n "$(DESKTOP_FILE_INSTALL)"; then \ + $(DESKTOP_FILE_INSTALL) --dir="$(DESTDIR)$(desktopfiledir)" --mode=644 $^; \ + else \ + $(INSTALL_DATA) $^ "$(DESTDIR)$(desktopfiledir)"; \ + fi; \ + #test -z "$(UPDATE_DESKTOP_DATABASE)" || $(UPDATE_DESKTOP_DATABASE) -q "$(DESTDIR)$(desktopfiledir)"; \ + fi + +uninstall-desktop-file: + @$(NORMAL_UNINSTALL) + @list='\''$(desktop_FILES)'\''; test -n "$(desktopfiledir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e '\''s|^.*/||'\''`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '\''$(DESTDIR)$(desktopfiledir)'\'' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(desktopfiledir)" && rm -f $$files; \ + #test -z "$(UPDATE_DESKTOP_DATABASE)" || $(UPDATE_DESKTOP_DATABASE) -q "$(DESTDIR)$(desktopfiledir)" + +clean-desktop-file: + rm -f $(desktop_FILES:.desktop=.desktop.valid) +' + _DESKTOP_FILE_SUBST(DESKTOP_FILE_RULES) +]) + +dnl _DESKTOP_FILE_SUBST(VARIABLE) +dnl Abstract macro to do either _AM_SUBST_NOTMAKE or AC_SUBST +AC_DEFUN([_DESKTOP_FILE_SUBST], +[ +AC_SUBST([$1]) +m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([$1])]) +] +) diff --git a/setup.py b/setup.py deleted file mode 100755 index cf546b52..00000000 --- a/setup.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -### BEGIN LICENSE -# Copyright (C) 2010 Kevin Mehall -#This program is free software: you can redistribute it and/or modify it -#under the terms of the GNU General Public License version 3, as published -#by the Free Software Foundation. -# -#This program is distributed in the hope that it will be useful, but -#WITHOUT ANY WARRANTY; without even the implied warranties of -#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -#PURPOSE. See the GNU General Public License for more details. -# -#You should have received a copy of the GNU General Public License along -#with this program. If not, see . -### END LICENSE - -###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ###################### - -import sys - -if sys.version_info[0] != 3: - sys.exit("Only python 3 is supported!") - -try: - from setuptools import setup, find_packages, Command -except ImportError: - import ez_setup - ez_setup.use_setuptools() - from setuptools import setup, find_packages, Command - -try: - from sphinx.setup_command import BuildDoc -except ImportError: - class BuildDoc(Command): - description = "Build documentation with Sphinx." - user_options = [] - version = None - release = None - - def initialize_options(self): - pass - def finalize_options(self): - pass - def run(self): - print("Error: Sphinx not found!") - -import os -import sys -from pithos.pithosconfig import VERSION - -# Utility function to read the README file. -# Used for the long_description. It's nice, because now 1) we have a top level -# README file and 2) it's easier to type in the README file than to put a raw -# string in below ... -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() - -if sys.platform != 'win32': - data_files = [ - ('/usr/share/icons/hicolor/scalable/apps', ['data/icons/hicolor/pithos.svg']), - ('/usr/share/icons/hicolor/48x48/apps', ['data/icons/hicolor/pithos-tray-icon.png']), - ('/usr/share/icons/ubuntu-mono-dark/apps/16', ['data/icons/ubuntu-mono-dark/pithos-tray-icon.svg']), - ('/usr/share/icons/ubuntu-mono-light/apps/16', ['data/icons/ubuntu-mono-light/pithos-tray-icon.svg']), - ('/usr/share/appdata', ['data/pithos.appdata.xml']), - ('/usr/share/applications', ['data/pithos.desktop']) - ] -else: - data_files = [] - -setup( - name='pithos', - version=VERSION, - ext_modules=[], - license='GPL-3', - author='Kevin Mehall', - author_email='km@kevinmehall.net', - description='Pandora.com client for the GNOME desktop', - long_description=read('README.md'), - url='http://pithos.github.io', - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: End Users/Desktop', - 'Topic :: Media', - 'License :: OSI Approved :: GPL License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3' - ], - cmdclass={ - 'build_doc': BuildDoc - }, - command_options={ - 'build_doc': { - 'version': ('setup.py', VERSION), - 'release': ('setup.py', VERSION) - } - }, - data_files=data_files, - package_data={ - 'pithos': [ - 'data/ui/*.ui', - 'data/ui/*.xml', - 'data/media/*.png', - 'data/media/*.svg' - ] - }, - packages=find_packages(), - include_package_data=True, - entry_points={ - 'gui_scripts': ['pithos = pithos.application:main'] - } -)