diff --git a/Examples/PythonPackageExample/LICENSE b/Examples/PythonPackage/LICENSE similarity index 99% rename from Examples/PythonPackageExample/LICENSE rename to Examples/PythonPackage/LICENSE index 91aacba82c..221b5b786c 100644 --- a/Examples/PythonPackageExample/LICENSE +++ b/Examples/PythonPackage/LICENSE @@ -1,38 +1,38 @@ ======================================================================= Copyright (c) 2003-2012 German Cancer Research Center, Division of Medical and Biological Informatics All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the German Cancer Research Center, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -======================================================================= \ No newline at end of file +======================================================================= diff --git a/Examples/PythonPackageExample/Makefile b/Examples/PythonPackage/Makefile similarity index 100% rename from Examples/PythonPackageExample/Makefile rename to Examples/PythonPackage/Makefile diff --git a/Examples/PythonPackageExample/README.rst b/Examples/PythonPackage/README.rst similarity index 89% rename from Examples/PythonPackageExample/README.rst rename to Examples/PythonPackage/README.rst index 81fd013040..c258948f08 100644 --- a/Examples/PythonPackageExample/README.rst +++ b/Examples/PythonPackage/README.rst @@ -1,68 +1,74 @@ Sample Module Repository ======================== This simple project is an example repo for Python projects. It is adapted from [this github example](https://github.com/kennethreitz/samplemod/tree/master). [Learn more](). And tries to follow the instructions on [this guide](). The actual code can be found in sample/thinker.py. It implements a toy class which "thinks" random thoughts. The tests for this class are located in sample/tests. Python will automatically discover tests if you name them test_*.py Look at test_advanced.py for a simple unittest example. ## install dependencies either use: ``` pip install -r requirements.txt ``` or ``` make init ``` ## install this package You have two choices: 1. install a development version. This means that if you make changes to the packages code you make will affect the code you write which is based on this package. 2. "normal" install. This will install the current version. After you installed your package, it can be imported in your via import sample where ever you are. ### install development version: either use: ``` python setup.py develop ``` or ``` make install_develop ``` ### "normal" install either use: ``` python setup.py install ``` or ``` make install ``` ## run tests either run: ``` python -m unittest discover ``` or ``` make test ``` ## execute tutorial In your console, navigate to the tutorials subfolder and start ipython notebook. + + +## run scripts +Scripts can be found in subfolder bin. They are declared as entry points +(see setup.py). This means you can call them by calling the entry points +directly in console! \ No newline at end of file diff --git a/Examples/PythonPackageExample/samplepackage/__init__.py b/Examples/PythonPackage/bin/__init__.py similarity index 100% copy from Examples/PythonPackageExample/samplepackage/__init__.py copy to Examples/PythonPackage/bin/__init__.py diff --git a/Examples/PythonPackage/bin/samplepackage_exe.py b/Examples/PythonPackage/bin/samplepackage_exe.py new file mode 100644 index 0000000000..3e52f4634a --- /dev/null +++ b/Examples/PythonPackage/bin/samplepackage_exe.py @@ -0,0 +1,41 @@ +""" +=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +=================================================================== +""" + +import argparse + +from samplepackage.thinker import Thinker + + +def main(): + parser = argparse.ArgumentParser(description="a simple executable to " + + "show how to set up " + + " executable scripts " + + "in python.") + + # add an exemplary argument. The help text will be shown if the program + # is called with -h + # for a more detailed description and more options please see: + # https://docs.python.org/2/library/argparse.html + parser.add_argument('-t', '--thoughts', type=int, required=True, + help='number of thoughts our thinker should produce') + # get all the arguments in a nice dict + args_dict = vars(parser.parse_args()) + + # now we can create the desired functionality: + thinker = Thinker(args_dict["thoughts"]) + thinker.think_out_loud() diff --git a/Examples/PythonPackageExample/doc/pythonpackageexample.dox b/Examples/PythonPackage/doc/pythonpackageexample.dox similarity index 89% rename from Examples/PythonPackageExample/doc/pythonpackageexample.dox rename to Examples/PythonPackage/doc/pythonpackageexample.dox index c674d8a325..26fcc759c6 100644 --- a/Examples/PythonPackageExample/doc/pythonpackageexample.dox +++ b/Examples/PythonPackage/doc/pythonpackageexample.dox @@ -1,73 +1,77 @@ /** \page Python package example. See README.rst for more info. This is text was copied from README.rst (maybe not updated): Sample Module Repository ======================== This simple project is an example repo for Python projects. It is adapted from [this github example](https://github.com/kennethreitz/samplemod/tree/master). [Learn more](). And tries to follow the instructions on [this guide](). The actual code can be found in sample/thinker.py. It implements a toy class which "thinks" random thoughts. The tests for this class are located in sample/tests. Python will automatically discover tests if you name them test_*.py Look at test_advanced.py for a simple unittest example. ## install dependencies either use: ``` pip install -r requirements.txt ``` or ``` make init ``` ## install this package You have two choices: 1. install a development version. This means that if you make changes to the packages code you make will affect the code you write which is based on this package. 2. "normal" install. This will install the current version. After you installed your package, it can be imported in your via import sample where ever you are. ### install development version: either use: ``` python setup.py develop ``` or ``` make install_develop ``` ### "normal" install either use: ``` python setup.py install ``` or ``` make install ``` ## run tests either run: ``` python -m unittest discover ``` or ``` make test ``` +## run scripts +Scripts can be found in subfolder bin. They are declared as entry points +(see setup.py). This means you can call them by calling the entry points +directly in console! */ diff --git a/Examples/PythonPackageExample/requirements.txt b/Examples/PythonPackage/requirements.txt similarity index 100% rename from Examples/PythonPackageExample/requirements.txt rename to Examples/PythonPackage/requirements.txt diff --git a/Examples/PythonPackageExample/samplepackage/tests/__init__.py b/Examples/PythonPackage/samplepackage/__init__.py similarity index 100% rename from Examples/PythonPackageExample/samplepackage/tests/__init__.py rename to Examples/PythonPackage/samplepackage/__init__.py diff --git a/Examples/PythonPackageExample/samplepackage/helpers.py b/Examples/PythonPackage/samplepackage/helpers.py similarity index 100% rename from Examples/PythonPackageExample/samplepackage/helpers.py rename to Examples/PythonPackage/samplepackage/helpers.py diff --git a/Examples/PythonPackageExample/samplepackage/__init__.py b/Examples/PythonPackage/samplepackage/tests/__init__.py similarity index 100% rename from Examples/PythonPackageExample/samplepackage/__init__.py rename to Examples/PythonPackage/samplepackage/tests/__init__.py diff --git a/Examples/PythonPackageExample/samplepackage/tests/test_advanced.py b/Examples/PythonPackage/samplepackage/tests/test_advanced.py similarity index 100% rename from Examples/PythonPackageExample/samplepackage/tests/test_advanced.py rename to Examples/PythonPackage/samplepackage/tests/test_advanced.py diff --git a/Examples/PythonPackageExample/samplepackage/tests/test_basic.py b/Examples/PythonPackage/samplepackage/tests/test_basic.py similarity index 100% rename from Examples/PythonPackageExample/samplepackage/tests/test_basic.py rename to Examples/PythonPackage/samplepackage/tests/test_basic.py diff --git a/Examples/PythonPackageExample/samplepackage/thinker.py b/Examples/PythonPackage/samplepackage/thinker.py similarity index 96% rename from Examples/PythonPackageExample/samplepackage/thinker.py rename to Examples/PythonPackage/samplepackage/thinker.py index 9807f11d8f..6f5d00edf9 100644 --- a/Examples/PythonPackageExample/samplepackage/thinker.py +++ b/Examples/PythonPackage/samplepackage/thinker.py @@ -1,76 +1,76 @@ ''' /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ ''' # -*- coding: utf-8 -*- # packages/modules included in pythons go here import random import logging # installed packages go here # our own modules/packages go here from helpers import thoughts # a free floating function def get_thought(): """Get a random thought.""" return random.choice(thoughts) class Thinker: """ A class which produces thoughts """ def __init__(self, number_of_thoughts): """ This is a constructor. Define variables here. If you do it in the classes namespace instead it will be equivalent to a static variable in C++ :param number_of_thoughts: the number of thoughts we want to produce :return: """ # underscore is standard for members in python: self.number_of_thoughts = number_of_thoughts def think(self): """ Member function which uses the number_of_thoughts to "think :return: a list of thoughts, length depending on your number of thoughts """ thought_list = [] try: thought_list = [get_thought() for _ in range(self.number_of_thoughts)] except IndexError: logging.error("Just showing off the logging module here") return thought_list def think_out_loud(self): """ Think and print these thoughts on the console. :return: """ current_thoughts = self.think() - print "currently I'm thinking of..." + print("currently I'm thinking of...") for thought in current_thoughts: - print thought + print(thought) diff --git a/Examples/PythonPackageExample/setup.py b/Examples/PythonPackage/setup.py similarity index 71% rename from Examples/PythonPackageExample/setup.py rename to Examples/PythonPackage/setup.py index 0061927670..230d94506c 100755 --- a/Examples/PythonPackageExample/setup.py +++ b/Examples/PythonPackage/setup.py @@ -1,30 +1,37 @@ # -*- coding: utf-8 -*- from setuptools import setup, find_packages with open('README.rst') as f: readme = f.read() with open('LICENSE') as f: license = f.read() setup( name='samplepackage', - version='0.0.2', + version='0.0.3', description='Sample package adapted from Python-Guide.org for MITK', long_description=readme, # if you want, put your own name here # (this would likely result in people sending you emails) author='MBI@DKFZ', author_email='mitk-users@lists.sourceforge.net', url='http://mitk.org', license=license, packages=find_packages(exclude=('tests', 'doc', 'tutorials')), # the requirements to install this project. # Since this one is so simple this is empty. - install_requires=[] + install_requires=[], # a more sophisticated project might have something like: #install_requires=['numpy>=1.11.0', 'scipy>=0.17', 'scikit-learn'] + + # after running setup.py, you will be able to call samplepackage_exe + # from the console as if it was a normal binary. It will call the function + # main in bin/samplepackage_exe.py + entry_points={ + 'console_scripts': ['samplepackage_exe=bin.samplepackage_exe:main'], + } ) diff --git a/Examples/PythonPackageExample/tutorials/ThinkerExample.ipynb b/Examples/PythonPackage/tutorials/ThinkerExample.ipynb similarity index 100% rename from Examples/PythonPackageExample/tutorials/ThinkerExample.ipynb rename to Examples/PythonPackage/tutorials/ThinkerExample.ipynb