Skip to content

Instantly share code, notes, and snippets.

@jgarte
Forked from simeonf/pex.md
Created January 9, 2024 05:11
Show Gist options
  • Select an option

  • Save jgarte/2fa506cad843cce0544964882d80f58c to your computer and use it in GitHub Desktop.

Select an option

Save jgarte/2fa506cad843cce0544964882d80f58c to your computer and use it in GitHub Desktop.

Revisions

  1. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion pex.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,8 @@ Ok - first to make our script! Call it foo.py:
    req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
    print req.text.split("\n")[0]

    It's a `requests` *hello world* program. To package it we need a minimal setup.py for distributing a script:
    It's a `requests` *hello world* program. To package it we need a minimal `setup.py` for distributing a script. Put it
    in the same directory:

    from distutils.core import setup
    setup(name='foo',
  2. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions pex.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    So you want to create a pex from a single python file with dependencies?
    So you want to create a pex that packages your script and its dependencies?

    Ok - first to make our script! Call it foo.py:

    @@ -8,7 +8,7 @@ Ok - first to make our script! Call it foo.py:
    req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
    print req.text.split("\n")[0]

    To package it we need a minimal setup.py for distributing a script:
    It's a `requests` *hello world* program. To package it we need a minimal setup.py for distributing a script:

    from distutils.core import setup
    setup(name='foo',
    @@ -20,7 +20,7 @@ Now that our script is packageable we can use `pex` to build an executable out o

    $ pex . requests -c foo.py -o foo.pex -f dist

    Briefly - `requests` and `.` are our dependencies. `-c foo.py` tells us what to run. `-o foo.pex` creates the
    Briefly - `requests` and `.` are our dependencies. `-c foo.py` tells pex what to run. And `-o foo.pex` creates the
    output file.

    You should get a `foo.pex` file in the same directory. Run it to see the script execute:
  3. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 4 additions and 9 deletions.
    13 changes: 4 additions & 9 deletions pex.md
    Original file line number Diff line number Diff line change
    @@ -16,17 +16,12 @@ To package it we need a minimal setup.py for distributing a script:
    scripts=['foo.py'],
    )

    Build an sdist with
    Now that our script is packageable we can use `pex` to build an executable out of it:

    $ python setup.py sdist

    This puts a tarball for our package in the `./dist` folder. Use `pex` to package our script
    and dependency into an executable:

    $ pex requests foo -c foo.py -o foo.pex -f dist
    $ pex . requests -c foo.py -o foo.pex -f dist

    Briefly - `requests` and `foo` are our dependencies. `-c foo.py` tells us what to run. `-o foo.pex` creates the
    output file and `-f dist` tells pex it can look in the `dist` directory to satisfy dependencies.
    Briefly - `requests` and `.` are our dependencies. `-c foo.py` tells us what to run. `-o foo.pex` creates the
    output file.

    You should get a `foo.pex` file in the same directory. Run it to see the script execute:

  4. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions pex.md
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,4 @@ You should get a `foo.pex` file in the same directory. Run it to see the script
    And you can unzip the pex to see the contents including the packaged dependencies:

    $ unzip -t foo.pex


    $
    ... much output not shown...
  5. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pex.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ and dependency into an executable:

    $ pex requests foo -c foo.py -o foo.pex -f dist

    Briefly - `requests` and `foo` are our dependencies. `-ck foo.py` tells us what to run. `-o foo.pex` creates the
    Briefly - `requests` and `foo` are our dependencies. `-c foo.py` tells us what to run. `-o foo.pex` creates the
    output file and `-f dist` tells pex it can look in the `dist` directory to satisfy dependencies.

    You should get a `foo.pex` file in the same directory. Run it to see the script execute:
  6. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions pex.md
    Original file line number Diff line number Diff line change
    @@ -10,32 +10,32 @@ Ok - first to make our script! Call it foo.py:

    To package it we need a minimal setup.py for distributing a script:

    from distutils.core import setup
    setup(name='foo',
    from distutils.core import setup
    setup(name='foo',
    version='1.0',
    scripts=['foo.py'],
    )

    Build an sdist with

    $ python setup.py sdist
    $ python setup.py sdist

    This puts a tarball for our package in the `./dist` folder. Use `pex` to package our script
    and dependency into an executable:

    $ pex requests foo -c foo.py -o foo.pex -f dist
    $ pex requests foo -c foo.py -o foo.pex -f dist

    Briefly - `requests` and `foo` are our dependencies. `-ck foo.py` tells us what to run. `-o foo.pex` creates the
    output file and `-f dist` tells pex it can look in the `dist` directory to satisfy dependencies.

    You should get a `foo.pex` file in the same directory. Run it to see the script execute:

    $ ./foo.pex
    PEX
    $ ./foo.pex
    PEX

    And you can unzip the pex to see the contents including the packaged dependencies:

    $ unzip -t foo.pex
    $ unzip -t foo.pex


    $
  7. @simeonf simeonf revised this gist Aug 20, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions pex.md
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@ So you want to create a pex from a single python file with dependencies?

    Ok - first to make our script! Call it foo.py:

    import requests

    if __name__ == '__main__':
    req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
    print req.text.split("\n")[0]
    import requests
    if __name__ == '__main__':
    req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
    print req.text.split("\n")[0]

    To package it we need a minimal setup.py for distributing a script:

  8. @simeonf simeonf renamed this gist Aug 20, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @simeonf simeonf created this gist Aug 20, 2015.
    41 changes: 41 additions & 0 deletions Creating a PEX from a python script.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    So you want to create a pex from a single python file with dependencies?

    Ok - first to make our script! Call it foo.py:

    import requests

    if __name__ == '__main__':
    req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
    print req.text.split("\n")[0]

    To package it we need a minimal setup.py for distributing a script:

    from distutils.core import setup
    setup(name='foo',
    version='1.0',
    scripts=['foo.py'],
    )

    Build an sdist with

    $ python setup.py sdist

    This puts a tarball for our package in the `./dist` folder. Use `pex` to package our script
    and dependency into an executable:

    $ pex requests foo -c foo.py -o foo.pex -f dist

    Briefly - `requests` and `foo` are our dependencies. `-ck foo.py` tells us what to run. `-o foo.pex` creates the
    output file and `-f dist` tells pex it can look in the `dist` directory to satisfy dependencies.

    You should get a `foo.pex` file in the same directory. Run it to see the script execute:

    $ ./foo.pex
    PEX

    And you can unzip the pex to see the contents including the packaged dependencies:

    $ unzip -t foo.pex


    $