distributing python software in jar like fashion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alf

    #1

    distributing python software in jar like fashion

    Hi,

    I have a small app which consist of a few .py files. Is there any way to
    distribute it in jar like fashion as a single file I can just run python
    on. I obviously look for platform independent solution.

    Thx in advance, A.
  • ce

    #2
    Re: distributing python software in jar like fashion

    On Mar 15, 10:23 am, alf <ask@mewrote:
    Hi,
    >
    I have a small app which consist of a few .py files. Is there any way to
    distribute it in jar like fashion as a single file I can just run python
    on. I obviously look for platform independent solution.
    >
    Thx in advance, A.
    You can import from zip achieves as PEP 273, but to execute in the
    same mechanism as the jar files, recently there is no way afaik.

    ce (pain n d'ass)

    Comment

    • Ben Finney

      #3
      Re: distributing python software in jar like fashion

      alf <ask@me.xs4all. nlwrites:
      I have a small app which consist of a few .py files. Is there any
      way to distribute it in jar like fashion as a single file I can just
      run python on. I obviously look for platform independent solution.
      Python eggs are the platform-independent distributable single-file
      archive. Given the way Python works, you can't simply execute them
      as-is; you can, however, easily install them.

      <URL:http://peak.telecommun ity.com/DevCenter/EasyInstall>

      --
      \ "I think it would be a good idea." -- Mahatma Gandhi (when |
      `\ asked what he thought of Western civilization) |
      _o__) |
      Ben Finney

      Comment

      • Shane Geiger

        #4
        Re: distributing python software in jar like fashion

        Hi,
        >
        I have a small app which consist of a few .py files. Is there any way to
        distribute it in jar like fashion as a single file I can just run python
        on. I obviously look for platform independent solution.
        >
        Thx in advance, A.
        >
        """
        Author: Shane Geiger <shane.geiger@g mail.com>


        Wed Mar 14 21:55:58 CDT 2007

        Hi,

        I have a small app which consist of a few .py files. Is there any way to
        distribute it in jar like fashion as a single file I can just run python
        on. I obviously look for platform independent solution.

        ------

        Here's an answer to your question.


        To use this script put it in the same directory as your .py files.
        See the glob.glob function below if you want to specify a directory if
        you want to change that.
        (I tried to keep this example simple.)


        Use the 'pack_mode()' and 'unpack_mode()' function calls at the bottom
        of the script to
        control it.

        Note: I have not tested this on Windows.

        """


        import base64
        import string, os
        import zipfile
        import glob

        def readfile(f): return open(f, "r").read()
        def writefile(f, data, perms=750): open(f, "w").write(data ) and
        os.chmod(f, perms)

        zip_file_name = 'python_modules .zip'


        def write_test_modu les():
        ## some test modules
        srgexample="""
        print "This was base64 encoded."
        """
        srgexample2="""
        print "This, too, was base64 encoded, and it was imported from a zip."
        """
        writefile('srge xample.py',srge xample)
        writefile('srge xample2.py',srg example2)

        def test_mode_clean up():
        os.remove('srge xample.py')
        os.remove('srge xample2.py')
        os.remove(zip_f ile_name)


        def pack_mode():
        """
        PACKING MODE:
        (you could automate this procedure if it is important to you)
        Zip the source files into one .zip file for easier handling.
        Base64 encode the zip file to avoid problems of including the file.
        Include the base64 representation of the zip file in a docstring, a
        step that you could automate (but I haven't).
        """

        write_test_modu les()

        # open the zip file for writing, and write stuff to it
        import zipfile
        import glob, os
        # open the zip file for writing, and write stuff to it
        file = zipfile.ZipFile (zip_file_name, "w")

        # for name in glob.glob("*.py "):
        for name in [x for x in glob.glob("*.py ") if x != __file__]: #
        dont' try to zip up this file
        file.write(name , os.path.basenam e(name), zipfile.ZIP_DEF LATED)
        file.close()
        ## Here's how to watch what gets added
        ## open the file again, to see what's in it
        #file = zipfile.ZipFile (zip_file_name, "r")
        #for info in file.infolist() :
        # print info.filename, info.date_time, info.file_size,
        info.compress_s ize

        contents = open(zip_file_n ame, "r").read()
        file_contents_i n_base64 = base64.encodest ring(contents)
        print "Assign the following base64 encoded string to the
        'python_modules _zip_base64' "
        print " variable (after which you can use unpack mode)."

        print file_contents_i n_base64
        # THEN MANUALLY ADD THAT to your main file.
        # You could automatically edit the currently running file like this:

        test_mode_clean up()


        def unpack_mode():
        """
        UNPACKING MODE:
        """
        python_modules_ zip_base64="""
        UEsDBBQAAAAIABq 8bjYpPJvJJgAAAC YAAAANAAAAc3JnZ XhhbXBsZS5weeMq KMrMK1FQCsnILFY o
        TyxWSEosTjUzUUj NS85PSU3RU+JSAA IAUEsDBBQAAAAIA Bq8bjZ5v8x4SAAA AEwAAAAOAAAAc3J n
        ZXhhbXBsZTIucHk dyTEKgDAMBdC9p/h0Dk7iSXqBaCJma FPagODpFd/6Uh/WArlcNgnhTrh5Yu ep
        2wpth4sKgZvA4i+ r3Ueo4BxewXisLz nh8wJQSwECFAMUA AAACAAavG42KTyb ySYAAAAmAAAADQA A
        AAAAAAAAAAAApIE AAAAAc3JnZXhhbX BsZS5weVBLAQIUA xQAAAAIABq8bjZ5 v8x4SAAAAEwAAAA O
        AAAAAAAAAAAAAAC kgVEAAABzcmdleG FtcGxlMi5weVBLB QYAAAAAAgACAHcA AADFAAAAAAA=
        """
        zip_file_conten ts = base64.decodest ring(python_mod ules_zip_base64 )
        def writefile(f, data, perms=750): open(f, "w").write(data ) and
        os.chmod(f, perms)
        writefile(zip_f ile_name,zip_fi le_contents)

        # open the file, to see what's in it
        #file = zipfile.ZipFile ("test.zip", "r")
        #for info in file.infolist() :
        # print info.filename, info.date_time, info.file_size,
        info.compress_s ize

        import sys
        sys.path.insert (0, zip_file_name) # Add .zip file to front of path
        import srgexample
        import srgexample2

        ### you could even remove the file after using it
        os.remove(zip_f ile_name)

        pack_mode()
        #unpack_mode()





        --
        Shane Geiger
        IT Director
        National Council on Economic Education
        sgeiger@ncee.ne t | 402-438-8958 | http://www.ncee.net

        Leading the Campaign for Economic and Financial Literacy


        Comment

        • Gary Duzan

          #5
          Re: distributing python software in jar like fashion

          In article <Vs6dnZOY8sSDM2 XYnZ2dnUVZ_rqhn Z2d@comcast.com >, alf <ask@mewrote:
          >Hi,
          >
          >I have a small app which consist of a few .py files. Is there any way to
          >distribute it in jar like fashion as a single file I can just run python
          >on. I obviously look for platform independent solution.
          >
          >Thx in advance, A.
          There is a new package that has been discussed here recently
          called Squisher that should do what you want by packing things into
          a single pyc file. There are still some minor issues that need to
          be ironed out with running the pyc directly, but it should do
          exactly what you want Real Soon Now.



          Gary Duzan
          Motorola CHS


          Comment

          • John Nagle

            #6
            Re: distributing python software in jar like fashion

            Were Python "eggs" a flop, or what?

            We need to have one packager that everyone agrees on.
            Otherwise, installs become a mess, and then you have to have
            installers that handle multiple packagers.

            John Nagle

            Gary Duzan wrote:
            In article <Vs6dnZOY8sSDM2 XYnZ2dnUVZ_rqhn Z2d@comcast.com >, alf <ask@mewrote:
            >
            >>Hi,
            >>
            >>I have a small app which consist of a few .py files. Is there any way to
            >>distribute it in jar like fashion as a single file I can just run python
            >>on. I obviously look for platform independent solution.
            >>
            >>Thx in advance, A.
            >
            >
            There is a new package that has been discussed here recently
            called Squisher that should do what you want by packing things into
            a single pyc file. There are still some minor issues that need to
            be ironed out with running the pyc directly, but it should do
            exactly what you want Real Soon Now.
            >

            >
            Gary Duzan
            Motorola CHS
            >
            >

            Comment

            • Robert Kern

              #7
              Re: distributing python software in jar like fashion

              John Nagle wrote:
              Were Python "eggs" a flop, or what?
              No.
              We need to have one packager that everyone agrees on.
              Otherwise, installs become a mess, and then you have to have
              installers that handle multiple packagers.
              Eggs and Squisher are complementary tools. Squisher is good for distributing an
              application with all of its dependencies in a single file; it is not a packager
              or installer for libraries. Eggs are good for distributing libraries and plugins
              and their dependencies.

              --
              Robert Kern

              "I have come to believe that the whole world is an enigma, a harmless enigma
              that is made terrible by our own mad attempt to interpret it as though it had
              an underlying truth."
              -- Umberto Eco

              Comment

              • Chris Cioffi

                #8
                Re: distributing python software in jar like fashion

                Hi John,

                I don't think eggs are a flop, however the pain they are trying to
                solve is generally pretty minor in the Python world vs what we often
                see with other languages. We're starting to see some push to move
                more 3rd party libraries and frameworks to eggs (ie: Turbogears) and
                as the developers get used to dealing with eggs we will reach a
                critical mass.

                The 2 main things holding eggs back, imo:
                1. The eggs extensions aren't included in the Python std lib.
                2. The Python std lib is fairly robust and we can accomplish a
                significant amount of work without needing 3rd party code.

                If eggs were included in the std lib, and/or the std lib was packaged
                as eggs we'd see a far more rapid uptake. The key is getting the egg
                extensions into the main distribution.

                Chris

                On 3/16/07, John Nagle <nagle@animats. comwrote:
                Were Python "eggs" a flop, or what?
                >
                We need to have one packager that everyone agrees on.
                Otherwise, installs become a mess, and then you have to have
                installers that handle multiple packagers.
                >
                John Nagle
                >
                Gary Duzan wrote:
                In article <Vs6dnZOY8sSDM2 XYnZ2dnUVZ_rqhn Z2d@comcast.com >, alf <ask@mewrote:
                >Hi,
                >
                >I have a small app which consist of a few .py files. Is there any way to
                >distribute it in jar like fashion as a single file I can just run python
                >on. I obviously look for platform independent solution.
                >
                >Thx in advance, A.

                There is a new package that has been discussed here recently
                called Squisher that should do what you want by packing things into
                a single pyc file. There are still some minor issues that need to
                be ironed out with running the pyc directly, but it should do
                exactly what you want Real Soon Now.



                Gary Duzan
                Motorola CHS
                --

                >

                --
                "A little government and a little luck are necessary in life, but only
                a fool trusts either of them." -- P. J. O'Rourke

                Comment

                • Gary Duzan

                  #9
                  Re: distributing python software in jar like fashion

                  In article <wbzKh.10576$jx 3.1929@newssvr2 5.news.prodigy. net>,
                  John Nagle <nagle@animats. comwrote:
                  Were Python "eggs" a flop, or what?
                  >
                  We need to have one packager that everyone agrees on.
                  >Otherwise, installs become a mess, and then you have to have
                  >installers that handle multiple packagers.
                  I think the point about Squisher is that you don't have to
                  install it. You can either import it or run it directly. I'm mostly
                  interested in it as a way to package a script with a few Python
                  and C modules, dump it in the field, and run "python myscript.pyc"
                  to execute it, with no need for anything but the base Python to be
                  installed on the remote site, and just one file to copy.

                  Gary Duzan
                  Motorola CHS


                  Comment

                  • Colin J. Williams

                    #10
                    Re: distributing python software in jar like fashion

                    ce wrote:
                    On Mar 15, 10:23 am, alf <ask@mewrote:
                    >Hi,
                    >>
                    >I have a small app which consist of a few .py files. Is there any way to
                    >distribute it in jar like fashion as a single file I can just run python
                    >on. I obviously look for platform independent solution.
                    >>
                    >Thx in advance, A.
                    >
                    You can import from zip achieves as PEP 273, but to execute in the
                    same mechanism as the jar files, recently there is no way afaik.
                    You could treat the collection of files as a Python package. You would
                    then add an __init__.py file to your collection and, in that __init__.py
                    arrange to initiate main.py (or whatever you call your initiator program).

                    Colin W.
                    >
                    ce (pain n d'ass)
                    >

                    Comment

                    Working...