Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ We welcome direct contributions to the sendgrid-python code base. Thank you!

### Development Environment ###

#### Using Docker ####
You can use our Docker image to avoid setting up the development environment yourself. See [USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md).

#### Install and Run Locally ####

##### Prerequisites #####
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-python.svg?branch=master)](https://travis-ci.org/sendgrid/sendgrid-python)
[![Docker Badge](https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg)](https://hub.docker.com/r/sendgrid/sendgrid-python/)
[![Email Notifications Badge](https://dx.sendgrid.com/badge/python)](https://dx.sendgrid.com/newsletter/python)

**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/python) for releases and breaking changes.
**NEW:** Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/python) for releases and breaking changes.
     Quickly get started with [Docker](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md).

**This library allows you to quickly and easily use the SendGrid Web API v3 via Python.**

Expand Down
4 changes: 0 additions & 4 deletions activate.sh

This file was deleted.

42 changes: 42 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM ubuntu:xenial
ENV PYTHON_VERSIONS='python2.6 python2.7 python3.4 python3.5 python3.6' \
OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"

# install testing versions of python, including old versions, from deadsnakes
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends software-properties-common \
&& apt-add-repository -y ppa:fkrull/deadsnakes \
&& apt-get update \
&& apt-get install -y --no-install-recommends $PYTHON_VERSIONS \
git \
curl \
&& apt-get purge -y --auto-remove software-properties-common \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /root

# install Prism
ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh
RUN chmod +x ./install.sh && \
./install.sh && \
rm ./install.sh

# install pip, tox
ADD https://bootstrap.pypa.io/get-pip.py get-pip.py
RUN python2.7 get-pip.py && \
pip install tox && \
rm get-pip.py

# set up default sendgrid env
WORKDIR /root/sources
RUN git clone https://github.com/sendgrid/sendgrid-python.git && \
git clone https://github.com/sendgrid/python-http-client.git
WORKDIR /root
RUN ln -s /root/sources/sendgrid-python/sendgrid && \
ln -s /root/sources/python-http-client/python_http_client

COPY entrypoint.sh entrypoint.sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's copying to the same directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using COPY as an alternative to ADD; apparently it's best-practice. It copies entrypoint.sh from the directory the Dockerfile is in into /root (set with WORKDIR earlier) and runs from there later on. The final directory structure looks like this:

/root
  entrypoint.sh
  sendgrid
  python_http_client
  /sources
    /python-http-client
      README.md
      /python_http_client
      ...
    /sendgrid-python
      README.md
      /sendgrid
      ...

RUN chmod +x entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
CMD ["--mock"]
43 changes: 43 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Supported tags and respective `Dockerfile` links
- `latest` [(Dockerfile)](https://github.com/sendgrid/sendgrid-python/blob/master/docker/Dockerfile)

# Quick reference
- **Where to get help:**
[contact SendGrid Support](https://support.sendgrid.com/hc/en-us)

- **Where to file issues:**
https://github.com/sendgrid/sendgrid-python/issues

- **Where to get more info:**
[USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md)

- **Maintained by:**
[SendGrid Inc.](https://sendgrid.com)

# Usage examples
- Most recent version: `docker run -it sendgrid/sendgrid-python`.
- Old version: `docker run -it sendgrid/sendgrid-python:v4.2.0`
- Old version predating this Docker image:
```sh-session
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
$ realpath sendgrid-python
/path/to/sendgrid-python
$ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
```
- Your own fork:
```sh-session
$ git clone https://github.com/you/cool-sendgrid-python.git
$ realpath cool-sendgrid-python
/path/to/cool-sendgrid-python
$ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
```

For more detailed information, see [USAGE.md](https://github.com/sendgrid/sendgrid-python/docker/USAGE.md).

# About

sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]).

sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc.

![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
84 changes: 84 additions & 0 deletions docker/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
You can use Docker to easily try out or test sendgrid-python.

<a name="Quickstart"></a>
# Quickstart

1. Install Docker on your machine.
2. Run `docker run -it sendgrid/sendgrid-python`.

<a name="Info"></a>
# Info

This Docker image contains
- `sendgrid-python` and `python-http-client`
- Stoplight's Prism, which lets you try out the API without actually sending email
- `tox` and all supported Python versions, set up to test `sendgrid-python` or your own fork

Run it in interactive mode with `-it`.

You can mount repositories in the `/mnt/sendgrid-python` and `/mnt/python-http-client` directories to use them instead of the default SendGrid libraries. Read on for more info.

<a name="Options"></a>
# Options

## Using an old version

The easiest way to use an old version is to use an [old tag](https://github.com/sendgrid/sendgrid-python/releases).

```sh-session
$ docker run -it sendgrid/sendgrid-python:v3.6.1
```

Tags from before this Docker image was created might not exist yet. You may [manually download](#Versions) [old versions](https://github.com/sendgrid/sendgrid-python/releases) in order to use them.

<a name="Versions"></a>
## Specifying specific versions

To use different versions of sendgrid-python or python-http-client - for instance, to replicate your production setup - mount them with the `-v <host_dir>:<container_dir>` option. When you put either repository under `/mnt`, the container will automatically detect it and make the proper symlinks. You can edit these files from the host machine while the container is running.

For instance, to install sendgrid-python 3.6.1 and use the current python-http-client:

```sh-session
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
$ realpath sendgrid-python
/path/to/sendgrid-python
$ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
```

To install sendgrid-python v3.6.1 and use an older version of python-http-client:

```sh-session
$ git clone https://github.com/sendgrid/sendgrid-python.git --branch v3.6.1
$ realpath sendgrid-python
/path/to/sendgrid-python
$ git clone https://github.com/sendgrid/python-http-client.git --branch v1.2.4
$ realpath python-http-client
/path/to/python-http-client
$ docker run -it -v /path/to/sendgrid-python:/mnt/sendgrid-python \
> -v /path/to/python-http-client:/mnt/python-http-client \
> sendgrid/sendgrid-python
```

## Specifying your own fork:

```sh-session
$ git clone https://github.com/you/cool-sendgrid-python.git
$ realpath cool-sendgrid-python
/path/to/cool-sendgrid-python
$ docker run -it -v /path/to/cool-sendgrid-python:/mnt/sendgrid-python sendgrid/sendgrid-python
```

Note that the paths you specify in `-v` must be absolute.

<a name="Testing"></a>
# Testing
Testing is easy! Run the container, `cd sendgrid`, and run `tox`.

<a name="about"></a>
# About

sendgrid-python is guided and supported by the SendGrid [Developer Experience Team](mailto:[email protected]).

sendgrid-python is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-python are trademarks of SendGrid, Inc.

![SendGrid Logo](https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
48 changes: 48 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! /bin/bash
clear

# check for + link mounted libraries:
if [ -d /mnt/sendgrid-python ]
then
rm /root/sendgrid
ln -s /mnt/sendgrid-python/sendgrid
echo "Linked mounted sendgrid-python's code to /root/sendgrid"
fi
if [ -d /mnt/python_http_client ]
then
rm /root/python_http_client
ln -s /mnt/python-http-client/python_http_client
echo "Linked mounted python-http-client's code to /root/python_http_client"
fi

SENDGRID_PYTHON_VERSION=$(python2.7 -c 'import sendgrid; print(sendgrid.__version__)')
echo "Welcome to sendgrid-python docker v${SENDGRID_PYTHON_VERSION}."
echo

if [ "$1" != "--no-mock" ]
then
echo "Starting Prism in mock mode. Calls made to Prism will not actually send emails."
echo "Disable this by running this container with --no-mock."
prism run --mock --spec $OAI_SPEC_URL 2> /dev/null &
else
echo "Starting Prism in live (--no-mock) mode. Calls made to Prism will send emails."
prism run --spec $OAI_SPEC_URL 2> /dev/null &
fi
echo "To use Prism, make API calls to localhost:4010. For example,"
echo " sg = sendgrid.SendGridAPIClient("
echo " host='http://localhost:4010/',"
echo " api_key=os.environ.get('SENDGRID_API_KEY_CAMPAIGNS'))"
echo "To stop Prism, run \"kill $!\" from the shell."

echo
echo "Starting Python. Type \"import sendgrid\" to get started; return to shell with exit()."
echo

python2.7

echo
echo "To get back into Python, run one of the installed versions:"
echo " $PYTHON_VERSIONS"
echo "To test sendgrid-python, \"cd sendgrid\" and run \"tox\"."
echo
exec $SHELL
3 changes: 2 additions & 1 deletion test/test_sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def setUpClass(cls):
"https://raw.githubusercontent.com/stoplightio/"
"prism/master/install.sh"],
stdout=subprocess.PIPE)
subprocess.Popen(
prisminstaller = subprocess.Popen(
["sh"], stdin=p1.stdout, stdout=subprocess.PIPE)
prisminstaller.wait()
except Exception as e:
print(
"Error downloading the prism binary, you can try "
Expand Down
32 changes: 11 additions & 21 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,34 @@
# and then run "tox" from this directory.

[tox]
envlist = py26, py27, py32, py33, py34, py35, py36
envlist = py26, py27, py34, py35, py36

[testenv]
commands = {envbindir}/python -m unittest discover -v []
deps =
{py26,py27,py32,py33,py34,py35,py36}-full: python_http_client
deps = -rrequirements.txt

[testenv:py26]
commands = {envbindir}/unit2 discover -v []
deps = unittest2
{[testenv]deps}
basepython = python2.6

[testenv:py27]
commands = {envbindir}/python -m unittest discover -v []
deps =
commands = {[testenv]commands}
deps = {[testenv]deps}
basepython = python2.7

[testenv:py32]
commands = {envbindir}/python -m unittest discover -v []
deps =
basepython = python3.2

[testenv:py33]
commands = {envbindir}/python -m unittest discover -v []
deps =
basepython = python3.3

[testenv:py34]
commands = {envbindir}/python -m unittest discover -v []
deps =
commands = {[testenv]commands}
deps = {[testenv]deps}
basepython = python3.4

[testenv:py35]
commands = {envbindir}/python -m unittest discover -v []
deps = -rrequirements.txt
commands = {[testenv]commands}
deps = {[testenv]deps}
basepython = python3.5

[testenv:py36]
commands = {envbindir}/python -m unittest discover -v []
deps = -rrequirements.txt
commands = {[testenv]commands}
deps = {[testenv]deps}
basepython = python3.6