Organising a python project

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • baoilleach@gmail.com

    #1

    Organising a python project

    Dear all,

    Can anyone point me to a resource that describes the best way of
    organising a python project? My project (gausssum.sf.ne t) is based
    around a class, and has a GUI that allows 'easy-access' to the methods
    of the class. What is the best or typical directory structure that
    allows the easy creation of binary packages for linux and windows,
    source distributions, etc.

    Rather than make up my own way, I'd prefer to know if there is a
    typical python way...

    Regards,
    baoilleach

  • bruno modulix

    #2
    Re: Organising a python project

    baoilleach@gmai l.com wrote:[color=blue]
    > Dear all,
    >
    > Can anyone point me to a resource that describes the best way of
    > organising a python project? My project (gausssum.sf.ne t) is based
    > around a class, and has a GUI that allows 'easy-access' to the methods
    > of the class.[/color]

    Err... Unless it's a *very* simple project, having the project based on
    a *single* class smells of GodClassAntipat tern (I can't say for sure
    without seeing the source of course, so this is most a a priori than a
    judgement !-).
    [color=blue]
    > What is the best or typical directory structure that
    > allows the easy creation of binary packages[/color]

    'binary packages' ?
    [color=blue]
    > for linux and windows,
    > source distributions, etc.
    >
    > Rather than make up my own way, I'd prefer to know if there is a
    > typical python way...[/color]

    Usually, a program project is made of one or more library modules,
    eventually organized in packages, and a 'main' script that's the entry
    point for the program [1]. Most Python projects being OSS, you can
    examine existing projects.


    [1] Note that this not Python specific. You'll find the same overall
    organisation in C, C++, Java, etc...

    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in 'onurb@xiludom. gro'.split('@')])"

    Comment

    • Scott David Daniels

      #3
      Re: Organising a python project

      bruno modulix wrote:[color=blue]
      > baoilleach@gmai l.com wrote:
      >[color=green]
      >>What is the best or typical directory structure that
      >>allows the easy creation of binary packages[/color][/color]

      somedir:
      test/
      test_product.py # Really do include tests
      product.py
      setup.py

      Look at distutils documentation. Also read up on "Python Eggs."

      You might consider doing it as a package under a you-specific name:

      somedir:
      yourname:
      test/
      test_product.py # See unittest module
      __init__.py # can be empty (and often is), also might have a
      # doc string, author, copyright, and license info
      # and a line like: __version__ = "0.2"
      product.py
      setup.py

      --Scott David Daniels
      Scott.Daniels@A cm.Org

      Comment

      • Ron Adam

        #4
        Re: Organising a python project

        baoilleach@gmai l.com wrote:
        [color=blue]
        > Dear all,
        >
        > Can anyone point me to a resource that describes the best way of
        > organising a python project? My project (gausssum.sf.ne t) is based
        > around a class, and has a GUI that allows 'easy-access' to the methods
        > of the class. What is the best or typical directory structure that
        > allows the easy creation of binary packages for linux and windows,
        > source distributions, etc.
        >
        > Rather than make up my own way, I'd prefer to know if there is a
        > typical python way...
        >
        > Regards,
        > baoilleach[/color]


        Here's what I've settled on for windows. This also keeps my src dir
        clean and separate form all the additional install files needed. I don't
        use automatic version control or CVS yet, but this seems to work well
        enough for me. You could probably just add the neccisary script to
        create linux distribution as well.

        projectname <- main project directory

        projectname1 <- version dir
        dist <- py2exe output dir
        docs <- addition documents, license, etc, dir
        icons <- icons file(s) for exe file dir
        src <- stand alone python source dir
        notes <- addition development notes dir
        Output <- inno setup output dir
        makeexe.py <- py2exe script
        pack.iss <- inno setup script

        projectname2 <- next version...
        ... # copy the previous version to start.
        ...


        Below is my basic py2exe script. You'll need to change it to suite your
        own needs of course. The rmtree is my own module to remove directories
        and contents. The newest version of py2exe I think does a better job of
        cleaning up I think.

        Cheers,
        Ron



        # makeexe.py
        """
        Create a stand alone distribution using py2exe.
        """

        from distutils.core import setup
        import py2exe
        import sys
        import os
        from mytools import rmtree

        sys.path += ['.\\src']

        try: rmtree.rmtree(' dist')
        except OSError: pass

        try: rmtree.rmtree(' build')
        except OSError: pass

        # Avoid having to use the command line.
        # If run without args, build executables, in quiet mode.
        if len(sys.argv) == 1:
        #sys.argv.appen d("-h") # show options
        sys.argv.append ("py2exe")

        opts = {
        "py2exe": {
        "optimize": "2",
        }
        }

        setup(
        options = opts,
        name = 'Aztec',
        windows = [{
        "script": "src\\aztec.py" ,
        "icon_resources ": [(1, "icons\\aztec.i co")],
        }]
        )

        os.rename('dist \\aztec.exe', 'dist\\aztec.sc r')

        try: rmtree.rmtree(' build')
        except OSError: pass





        Comment

        • baoilleach@gmail.com

          #5
          Re: Organising a python project

          Thanks for the info, guys. Noel

          Comment

          • baoilleach@gmail.com

            #6
            Re: Organising a python project

            Thanks for the info, guys. Noel

            Comment

            • beza1e1

              #7
              Re: Organising a python project

              I don't know about a typical python way, but i'd like to know as well
              ;)

              Personally i have a project for my project foo, which has
              foo/__init__.py # with all the other modules
              doc/ # documentation is always a good idea
              script/ # everything executable, which later goes into 'bin'
              directories by installing
              setup.py
              README, INSTALL, ... and other standard stuff

              Of course often there is other stuff floating around in the base
              directory, like some quick test scripts or sketches. And then my
              version control system has an additional directory.

              My tests are mostly within the modules.

              def test():
              return True
              if __name__ == "__main__":
              test()

              My __init__.py tests every module, if executed directly. So far my
              system works. It probably would be good to seperate tests, if they get
              bigger.

              Comment

              Working...