Anthony Tuininga avatar Anthony Tuininga committed ea9db15 Merge

Merged in JonasGroeger/cx_freeze (pull request #19)

Made samples PEP8 compatible and consistent.

Comments (0)

Files changed (30)

samples/PyQt4/PyQt4app.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 import sys
-from PyQt4.QtCore import *
-from PyQt4.QtGui import *
+from PyQt4.QtGui import QApplication, QDialog
 
 app = QApplication(sys.argv)
 form = QDialog()
 form.show()
 app.exec_()
-

samples/PyQt4/setup.py

+# -*- coding: utf-8 -*-
+
 # A simple setup script to create an executable using PyQt4. This also
 # demonstrates the method for creating a Windows executable that does not have
 # an associated console.
 # subdirectory that contains the files needed to run the application
 
 import sys
-
 from cx_Freeze import setup, Executable
 
 base = None
-if sys.platform == "win32":
-    base = "Win32GUI"
+if sys.platform == 'win32':
+    base = 'Win32GUI'
 
-setup(
-        name = "simple_PyQt4",
-        version = "0.1",
-        description = "Sample cx_Freeze PyQt4 script",
-        options = {"build_exe" : {"includes" : "atexit" }},
-        executables = [Executable("PyQt4app.py", base = base)])
+options = {
+    'build_exe': {
+        'includes': 'atexit'
+    }
+}
 
+executables = [
+    Executable('PyQt4app.py', base=base)
+]
+
+setup(name='simple_PyQt4',
+      version='0.1',
+      description='Sample cx_Freeze PyQt4 script',
+      options=options,
+      executables=executables
+      )

samples/Tkinter/SimpleTkApp.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 try:
-    from tkinter import *
+    from tkinter import Tk, Label, Button, BOTTOM
 except ImportError:
-    from Tkinter import *
+    from Tkinter import Tk, Label, Button, BOTTOM
 
 root = Tk()
 root.title('Button')
 Label(text='I am a button').pack(pady=15)
-Button( text='Button') .pack(side=BOTTOM)
+Button(text='Button').pack(side=BOTTOM)
 root.mainloop()
-

samples/Tkinter/setup.py

+# -*- coding: utf-8 -*-
+
 # A simple setup script to create an executable using Tkinter. This also
 # demonstrates the method for creating a Windows executable that does not have
 # an associated console.
 # subdirectory that contains the files needed to run the application
 
 import sys
-
 from cx_Freeze import setup, Executable
 
 base = None
-if sys.platform == "win32":
-    base = "Win32GUI"
+if sys.platform == 'win32':
+    base = 'Win32GUI'
 
-setup(
-        name = "simple_Tkinter",
-        version = "0.1",
-        description = "Sample cx_Freeze Tkinter script",
-        executables = [Executable("SimpleTkApp.py", base = base)])
+executables = [
+    Executable('SimpleTkApp.py', base=base)
+]
 
+setup(name='simple_Tkinter',
+      version='0.1',
+      description='Sample cx_Freeze Tkinter script',
+      executables=executables
+      )

samples/advanced/advanced_1.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("Hello from cx_Freeze Advanced #1\n\n")
+sys.stdout.write('Hello from cx_Freeze Advanced #1\n\n')
 
-module = __import__("testfreeze_1")
-
+module = __import__('testfreeze_1')

samples/advanced/advanced_2.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("Hello from cx_Freeze Advanced #2\n\n")
+sys.stdout.write('Hello from cx_Freeze Advanced #2\n\n')
 
-module = __import__("testfreeze_2")
-
+module = __import__('testfreeze_2')

samples/advanced/modules/testfreeze_1.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("Test freeze module #1\n")
-
+sys.stdout.write('Test freeze module #1\n')

samples/advanced/modules/testfreeze_2.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("Test freeze module #2\n")
-
+sys.stdout.write('Test freeze module #2\n')

samples/advanced/setup.py

+# -*- coding: utf-8 -*-
+
 # An advanced setup script to create multiple executables and demonstrate a few
 # of the features available to setup scripts
 #
-# hello.py is a very simple "Hello, world" type script which also displays the
+# hello.py is a very simple 'Hello, world' type script which also displays the
 # environment in which the script runs
 #
 # Run the build process by running the command 'python setup.py build'
 import sys
 from cx_Freeze import setup, Executable
 
+options = {
+    'build_exe': {
+        'compressed': True,
+        'includes': [
+            'testfreeze_1',
+            'testfreeze_2'
+        ],
+        'path': sys.path + ['modules']
+    }
+}
+
 executables = [
-        Executable("advanced_1.py"),
-        Executable("advanced_2.py")
+    Executable('advanced_1.py'),
+    Executable('advanced_2.py')
 ]
 
-buildOptions = dict(
-        compressed = True,
-        includes = ["testfreeze_1", "testfreeze_2"],
-        path = sys.path + ["modules"])
-
-setup(
-        name = "advanced_cx_Freeze_sample",
-        version = "0.1",
-        description = "Advanced sample cx_Freeze script",
-        options = dict(build_exe = buildOptions),
-        executables = executables)
-
+setup(name='advanced_cx_Freeze_sample',
+      version='0.1',
+      description='Advanced sample cx_Freeze script',
+      options=options,
+      executables=executables
+      )

samples/matplotlib/setup.py

+# -*- coding: utf-8 -*-
+
 # A simple setup script to create an executable using matplotlib.
 #
 # test_matplotlib.py is a very simple matplotlib application that demonstrates
 # If everything works well you should find a subdirectory in the build
 # subdirectory that contains the files needed to run the application
 
-import cx_Freeze
 import sys
+from cx_Freeze import setup, Executable
 
 base = None
-if sys.platform == "win32":
-    base = "Win32GUI"
+if sys.platform == 'win32':
+    base = 'Win32GUI'
 
-buildOptions = dict(
-        excludes = ["Tkinter"])
+options = {
+    'build_exe': {
+        'excludes': ['Tkinter']  # Sometimes a little finetuning is needed
+    }
+}
 
 executables = [
-        cx_Freeze.Executable("test_matplotlib.py", base = base)
+    Executable('test_matplotlib.py', base=base)
 ]
 
-cx_Freeze.setup(
-        name = "test_matplotlib",
-        version = "0.1",
-        description = "Sample matplotlib script",
-        executables = executables,
-        options = dict(build_exe = buildOptions))
-
+setup(name='test_matplotlib',
+      version='0.1',
+      description='Sample matplotlib script',
+      executables=executables,
+      options=options
+      )

samples/matplotlib/test_matplotlib.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 from numpy import arange, sin, pi
 import matplotlib
 matplotlib.use('WXAgg')
 from matplotlib.figure import Figure
 import wx
 
+
 class CanvasFrame(wx.Frame):
-   def __init__(self):
-       wx.Frame.__init__(self,None,-1, 'CanvasFrame',size=(550,350))
-       self.SetBackgroundColour(wx.NamedColor("WHITE"))
-       self.figure = Figure()
-       self.axes = self.figure.add_subplot(111)
-       t = arange(0.0,3.0,0.01)
-       s = sin(2*pi*t)
-       self.axes.plot(t,s)
-       self.canvas = FigureCanvas(self, -1, self.figure)
-       self.sizer = wx.BoxSizer(wx.VERTICAL)
-       self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
-       self.SetSizerAndFit(self.sizer)
-       self.add_toolbar()
+    def __init__(self):
+        wx.Frame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350))
+        self.SetBackgroundColour(wx.NamedColor('WHITE'))
+        self.figure = Figure()
+        self.axes = self.figure.add_subplot(111)
+        t = arange(0.0, 3.0, 0.01)
+        s = sin(2 * pi * t)
+        self.axes.plot(t, s)
+        self.canvas = FigureCanvas(self, -1, self.figure)
+        self.sizer = wx.BoxSizer(wx.VERTICAL)
+        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
+        self.SetSizerAndFit(self.sizer)
+        self.add_toolbar()
 
-   def add_toolbar(self):
-       self.toolbar = NavigationToolbar2Wx(self.canvas)
-       self.toolbar.Realize()
-       if wx.Platform == '__WXMAC__':
-           self.SetToolBar(self.toolbar)
-       else:
-           tw, th = self.toolbar.GetSizeTuple()
-           fw, fh = self.canvas.GetSizeTuple()
-           self.toolbar.SetSize(wx.Size(fw, th))
-           self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
-       self.toolbar.update()
+    def add_toolbar(self):
+        self.toolbar = NavigationToolbar2Wx(self.canvas)
+        self.toolbar.Realize()
+        if wx.Platform == '__WXMAC__':
+            self.SetToolBar(self.toolbar)
+        else:
+            tw, th = self.toolbar.GetSizeTuple()
+            fw, fh = self.canvas.GetSizeTuple()
+            self.toolbar.SetSize(wx.Size(fw, th))
+            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
+        self.toolbar.update()
 
-   def OnPaint(self, event):
-       self.canvas.draw()
+    def OnPaint(self, event):
+        self.canvas.draw()
+
 
 class App(wx.App):
-   def OnInit(self):
-       'Create the main window and insert the custom frame'
-       frame = CanvasFrame()
-       frame.Show(True)
-       return True
+    def OnInit(self):
+        '''Create the main window and insert the custom frame'''
+        frame = CanvasFrame()
+        frame.Show(True)
+        return True
 
 app = App(0)
 app.MainLoop()
-

samples/relimport/pkg1/__init__.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1\n")
+sys.stdout.write('importing pkg1\n')
 
 from . import sub1
 from . import pkg2

samples/relimport/pkg1/pkg2/__init__.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.pkg2\n")
+sys.stdout.write('importing pkg1.pkg2\n')
 
 from . import sub3
 from .. import sub4

samples/relimport/pkg1/pkg2/sub3.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.pkg2.sub3\n")
+sys.stdout.write('importing pkg1.pkg2.sub3\n')
 
 from . import sub5
 from .. import sub6

samples/relimport/pkg1/pkg2/sub5.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.pkg2.sub5\n")
-
+sys.stdout.write('importing pkg1.pkg2.sub5\n')

samples/relimport/pkg1/sub1.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.sub1\n")
+sys.stdout.write('importing pkg1.sub1\n')
 
 from . import sub2

samples/relimport/pkg1/sub2.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.sub2\n")
-
+sys.stdout.write('importing pkg1.sub2\n')

samples/relimport/pkg1/sub4.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.sub4\n")
-
+sys.stdout.write('importing pkg1.sub4\n')

samples/relimport/pkg1/sub6.py

+# -*- coding: utf-8 -*-
+
 import sys
 
-sys.stdout.write("importing pkg1.sub6\n")
-
+sys.stdout.write('importing pkg1.sub6\n')

samples/relimport/relimport.py

+# -*- coding: utf-8 -*-
+
 import pkg1

samples/relimport/setup.py

+# -*- coding: utf-8 -*-
+
 # relimport.py is a very simple script that tests importing using relative
 # imports (available in Python 2.5 and up)
 #
 
 from cx_Freeze import setup, Executable
 
-setup(
-        name = "relimport",
-        version = "0.1",
-        description = "Sample cx_Freeze script for relative imports",
-        executables = [Executable("relimport.py")])
+executables = [
+    Executable('relimport.py')
+]
 
+setup(name='relimport',
+      version='0.1',
+      description='Sample cx_Freeze script for relative imports',
+      executables=executables
+      )

samples/service/Config.py

+# -*- coding: utf-8 -*-
+
 #------------------------------------------------------------------------------
 # Config.py
 #   This file defines information about the service. The first four
 #   CLASS_NAME
 #       the name of the class within the module implementing the service. This
 #       class should accept no parameters in the constructor. It should have a
-#       method called "Initialize" which will accept the configuration file
-#       name. It should also have a method called "Run" which will be called
+#       method called 'Initialize' which will accept the configuration file
+#       name. It should also have a method called 'Run' which will be called
 #       with no parameters when the service is started. It should also have a
-#       method called "Stop" which will be called with no parameters when the
+#       method called 'Stop' which will be called with no parameters when the
 #       service is stopped using the service control GUI.
 #
 #   DESCRIPTION
 #
 #   SESSION_CHANGES
 #       whether the service should monitor session changes (optional). If
-#       True, session changes will call the method "SessionChanged" with the
+#       True, session changes will call the method 'SessionChanged' with the
 #       parameters sessionId and eventTypeId.
 #------------------------------------------------------------------------------
 
-NAME = "cx_FreezeSampleService%s"
-DISPLAY_NAME = "cx_Freeze Sample Service - %s"
-MODULE_NAME = "ServiceHandler"
-CLASS_NAME = "Handler"
-DESCRIPTION = "Sample service description"
+NAME = 'cx_FreezeSampleService%s'
+DISPLAY_NAME = 'cx_Freeze Sample Service - %s'
+MODULE_NAME = 'ServiceHandler'
+CLASS_NAME = 'Handler'
+DESCRIPTION = 'Sample service description'
 AUTO_START = False
 SESSION_CHANGES = False
-

samples/service/ServiceHandler.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 """
 Implements a simple service using cx_Freeze.
 
 import cx_Threads
 import sys
 
+
 class Handler(object):
 
     # no parameters are permitted; all configuration should be placed in the
     # configuration file and handled in the Initialize() method
     def __init__(self):
-        cx_Logging.Info("creating handler instance")
+        cx_Logging.Info('creating handler instance')
         self.stopEvent = cx_Threads.Event()
 
     # called when the service is starting
     def Initialize(self, configFileName):
-        cx_Logging.Info("initializing: config file name is %r", configFileName)
+        cx_Logging.Info('initializing: config file name is %r', configFileName)
 
     # called when the service is starting immediately after Initialize()
     # use this to perform the work of the service; don't forget to set or check
     # for the stop event or the service GUI will not respond to requests to
     # stop the service
     def Run(self):
-        cx_Logging.Info("running service....")
+        cx_Logging.Info('running service....')
         self.stopEvent.Wait()
 
     # called when the service is being stopped by the service manager GUI
     def Stop(self):
-        cx_Logging.Info("stopping service...")
+        cx_Logging.Info('stopping service...')
         self.stopEvent.Set()
-

samples/service/setup.py

+# -*- coding: utf-8 -*-
+
 # A simple setup script for creating a Windows service. See the comments in the
 # Config.py and ServiceHandler.py files for more information on how to set this
 # up.
 
 from cx_Freeze import setup, Executable
 
-buildOptions = dict(includes = ["ServiceHandler"])
-executable = Executable("Config.py", base = "Win32Service",
-        targetName = "cx_FreezeSampleService.exe")
+options = {
+    'build_exe': {
+        'includes': ['ServiceHandler']
+    }
+}
 
-setup(
-        name = "cx_FreezeSampleService",
-        version = "0.1",
-        description = "Sample cx_Freeze Windows serice",
-        executables = [executable],
-        options = dict(build_exe = buildOptions))
+executables = [
+    Executable('Config.py', base='Win32Service',
+               targetName='cx_FreezeSampleService.exe')
+]
 
+setup(name='cx_FreezeSampleService',
+      version='0.1',
+      description='Sample cx_Freeze Windows serice',
+      executables=executables,
+      options=options
+      )

samples/simple/hello.py

-import datetime
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from datetime import datetime
 import sys
+from sys import stdout
 
-sys.stdout.write("Hello from cx_Freeze\n")
-sys.stdout.write("The current date is %s\n\n" % \
-        datetime.datetime.today().strftime("%B %d, %Y %H:%M:%S"))
+stdout.write('Hello from cx_Freeze\n')
+stdout.write('The current date is %s\n\n' %
+             datetime.today().strftime('%B %d, %Y %H:%M:%S'))
 
-sys.stdout.write("Executable: %r\n" % sys.executable)
-sys.stdout.write("Prefix: %r\n" % sys.prefix)
-sys.stdout.write("File system encoding: %r\n\n" % sys.getfilesystemencoding())
+stdout.write('Executable: %r\n' % sys.executable)
+stdout.write('Prefix: %r\n' % sys.prefix)
+stdout.write('File system encoding: %r\n\n' % sys.getfilesystemencoding())
 
-sys.stdout.write("ARGUMENTS:\n")
+stdout.write('ARGUMENTS:\n')
 for a in sys.argv:
-    sys.stdout.write("%s\n" % a)
-sys.stdout.write("\n")
+    stdout.write('%s\n' % a)
+stdout.write('\n')
 
-sys.stdout.write("PATH:\n")
+stdout.write('PATH:\n')
 for p in sys.path:
-    sys.stdout.write("%s\n" % p)
-sys.stdout.write("\n")
-
+    stdout.write('%s\n' % p)
+stdout.write('\n')

samples/simple/setup.py

+# -*- coding: utf-8 -*-
+
 # A very simple setup script to create a single executable
 #
-# hello.py is a very simple "Hello, world" type script which also displays the
+# hello.py is a very simple 'Hello, world' type script which also displays the
 # environment in which the script runs
 #
 # Run the build process by running the command 'python setup.py build'
 
 from cx_Freeze import setup, Executable
 
-setup(
-        name = "hello",
-        version = "0.1",
-        description = "Sample cx_Freeze script",
-        executables = [Executable("hello.py")])
+executables = [
+    Executable('hello.py')
+]
 
+setup(name='hello',
+      version='0.1',
+      description='Sample cx_Freeze script',
+      executables=executables
+      )

samples/wx/setup.py

+# -*- coding: utf-8 -*-
+
 # A simple setup script to create an executable running wxPython. This also
 # demonstrates the method for creating a Windows executable that does not have
 # an associated console.
 #
-# wxapp.py is a very simple "Hello, world" type wxPython application
+# wxapp.py is a very simple 'Hello, world' type wxPython application
 #
 # Run the build process by running the command 'python setup.py build'
 #
 # subdirectory that contains the files needed to run the application
 
 import sys
-
 from cx_Freeze import setup, Executable
 
 base = None
-if sys.platform == "win32":
-    base = "Win32GUI"
+if sys.platform == 'win32':
+    base = 'Win32GUI'
 
-setup(
-        name = "hello",
-        version = "0.1",
-        description = "Sample cx_Freeze wxPython script",
-        executables = [Executable("wxapp.py", base = base)])
+executables = [
+    Executable('wxapp.py', base=base)
+]
 
+setup(name='hello',
+      version='0.1',
+      description='Sample cx_Freeze wxPython script',
+      executables=executables
+      )

samples/wx/wxapp.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 import wx
 
+
 class Frame(wx.Frame):
-
     def __init__(self):
-        wx.Frame.__init__(self, parent = None, title = "Hello from cx_Freeze")
+        wx.Frame.__init__(self, parent=None, title='Hello from cx_Freeze')
         panel = wx.Panel(self)
-        closeMeButton = wx.Button(panel, -1, "Close Me")
+        closeMeButton = wx.Button(panel, -1, 'Close Me')
         wx.EVT_BUTTON(self, closeMeButton.GetId(), self.OnCloseMe)
         wx.EVT_CLOSE(self, self.OnCloseWindow)
-        pushMeButton = wx.Button(panel, -1, "Push Me")
+        pushMeButton = wx.Button(panel, -1, 'Push Me')
         wx.EVT_BUTTON(self, pushMeButton.GetId(), self.OnPushMe)
         sizer = wx.BoxSizer(wx.HORIZONTAL)
-        sizer.Add(closeMeButton, flag = wx.ALL, border = 20)
-        sizer.Add(pushMeButton, flag = wx.ALL, border = 20)
+        sizer.Add(closeMeButton, flag=wx.ALL, border=20)
+        sizer.Add(pushMeButton, flag=wx.ALL, border=20)
         panel.SetSizer(sizer)
         topSizer = wx.BoxSizer(wx.VERTICAL)
-        topSizer.Add(panel, flag = wx.ALL | wx.EXPAND)
+        topSizer.Add(panel, flag=wx.ALL | wx.EXPAND)
         topSizer.Fit(self)
 
     def OnCloseMe(self, event):
         self.Close(True)
 
     def OnPushMe(self, event):
-        wx.MessageBox("I was pushed!", "Informational message")
+        wx.MessageBox('I was pushed!', 'Informational message')
 
     def OnCloseWindow(self, event):
         self.Destroy()
 
 
 class App(wx.App):
-
     def OnInit(self):
         frame = Frame()
         frame.Show(True)
 
 app = App(1)
 app.MainLoop()
-

samples/zope/qotd.py

-#!/usr/bin/env /usr/bin/python
-"""A simple Quote of the Day server"""
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+A simple Quote of the Day server
+"""
+
 from twisted.internet.protocol import Protocol, Factory
 from twisted.internet import reactor
 
+
 class QOTD(Protocol):
-
     def connectionMade(self):
-        self.transport.write("An apple a day keeps the doctor away\r\n") 
+        self.transport.write('An apple a day keeps the doctor away\r\n')
         self.transport.loseConnection()
 
 # Next lines are magic:

samples/zope/setup.py

+# -*- coding: utf-8 -*-
+
 # A simple setup script to create an executable using Zope which demonstrates
 # the use of namespace packages.
 #
 # subdirectory that contains the files needed to run the application
 
 import sys
-
 from cx_Freeze import setup, Executable
 
-buildOptions = dict(
-        namespace_packages = ['zope'])
+options = {
+    'build_exe': {
+        'namespace_packages': ['zope']
+    }
+}
 
-setup(
-        name = "QOTD sample",
-        version = "1.0",
-        description = "QOTD sample for demonstrating use of namespace packages",
-        options = dict(build_exe = buildOptions),
-        executables = [Executable("qotd.py")])
+executables = [
+    Executable('qotd.py')
+]
 
+setup(name='QOTD sample',
+      version='1.0',
+      description='QOTD sample for demonstrating use of namespace packages',
+      options=options,
+      executables=executables
+      )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.