From 4c53f150919aca70c4b8b0e1b286a4f8c07734ce Mon Sep 17 00:00:00 2001
From: Kareem Zidane <kzidane@cs50.harvard.edu>
Date: Mon, 27 Feb 2017 12:55:22 +0200
Subject: [PATCH 1/2] tweaks for CI and CD

---
 .gitignore                |  6 +++---
 .travis.yml               | 18 +++++++++++++++++
 Makefile                  | 41 +++++----------------------------------
 README.md                 |  2 ++
 after-install.sh          |  7 -------
 {src => cs50}/__init__.py |  0
 {src => cs50}/cs50.py     |  0
 {src => cs50}/sql.py      |  0
 setup.py                  | 19 ++++++++++++++++++
 9 files changed, 47 insertions(+), 46 deletions(-)
 create mode 100644 .travis.yml
 delete mode 100644 after-install.sh
 rename {src => cs50}/__init__.py (100%)
 rename {src => cs50}/cs50.py (100%)
 rename {src => cs50}/sql.py (100%)
 create mode 100644 setup.py

diff --git a/.gitignore b/.gitignore
index b7fa185..f75ca9b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
 .*
 !.gitignore
-*.pyc
-__pycache__/
-build/
+!.travis.yml
+dist/
+*.egg-info/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..67fdbd4
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+language: python
+
+python: "3.4"
+
+# build sdist
+script: make build
+
+# install twine for uploading to PyPI
+before_deploy: pip install twine
+
+deploy:
+  provider: script
+
+  # upload to PyPI
+  script: twine upload -u $PYPI_USERNAME -p $PYPI_PASSWORD dist/*
+
+  # avoid stashing sdist
+  skip_cleanup: true
diff --git a/Makefile b/Makefile
index dcce1e7..6ff0b4b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,42 +1,11 @@
-BUILD_DIR = build
-DESCRIPTION = CS50 Library for Python
-MAINTAINER = CS50 <sysadmins@cs50.harvard.edu>
-NAME = python-cs50
-OLD_NAME = lib50-python
-VERSION = 1.3.0
-
-.PHONY: bash
-bash:
-	docker run -i --rm -t -v "$(PWD)":/root cs50/cli
-
 .PHONY: build
 build: clean
-	mkdir -p "$(BUILD_DIR)"/usr/lib/python2.7/dist-packages/cs50
-	cp src/* "$(BUILD_DIR)"/usr/lib/python2.7/dist-packages/cs50
-	mkdir -p "$(BUILD_DIR)"/usr/lib/python3/dist-packages/cs50
-	cp src/* "$(BUILD_DIR)"/usr/lib/python3/dist-packages/cs50
+	python setup.py sdist
 
 .PHONY: clean
 clean:
-	rm -rf "$(BUILD_DIR)"
+	rm -rf *.egg-info dist
 
-.PHONY: deb
-deb: build
-	fpm \
-	-C "$(BUILD_DIR)" \
-	-m "$(MAINTAINER)" \
-	-n "$(NAME)" \
-	-p "$(BUILD_DIR)" \
-	-s dir \
-	-t deb \
-	-v "$(VERSION)" \
-	--after-install after-install.sh \
-	--conflicts "$(NAME) (<< $(VERSION)), $(OLD_NAME)" \
-	--deb-no-default-config-files \
-	--depends python \
-	--depends python3 \
-	--description "$(DESCRIPTION)" \
-	--replaces "$(NAME) (<= $(VERSION)), $(OLD_NAME)" \
-	--provides "$(NAME)" \
-	--provides "$(OLD_NAME)" \
-	usr
+.PHONY: install
+install: build
+	pip install dist/cs50*.tar.gz
diff --git a/README.md b/README.md
index 6f943ca..3f51734 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
 # CS50 Library for Python
 
+[![Build Status](https://travis-ci.org/cs50/python-cs50.svg?branch=master)](https://travis-ci.org/cs50/python-cs50)
+
 Supports Python 2 and Python 3.
 
 ## Development
diff --git a/after-install.sh b/after-install.sh
deleted file mode 100644
index 9c78f1c..0000000
--- a/after-install.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-pip2 install SQLAlchemy
-pip3 install SQLAlchemy
-
-chmod -R a+rX /usr/lib/python2.7/dist-packages/cs50
-chmod -R a+rX /usr/lib/python3/dist-packages/cs50
diff --git a/src/__init__.py b/cs50/__init__.py
similarity index 100%
rename from src/__init__.py
rename to cs50/__init__.py
diff --git a/src/cs50.py b/cs50/cs50.py
similarity index 100%
rename from src/cs50.py
rename to cs50/cs50.py
diff --git a/src/sql.py b/cs50/sql.py
similarity index 100%
rename from src/sql.py
rename to cs50/sql.py
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..cee2266
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,19 @@
+from setuptools import setup
+
+setup(
+    author="CS50",
+    author_email="sysadmins@cs50.harvard.edu",
+    classifiers=[
+        "Intended Audience :: Developers",
+        "Programming Language :: Python",
+        "Programming Language :: Python :: 3",
+        "Topic :: Software Development :: Libraries :: Python Modules"
+    ],
+    description="CS50 library for Python",
+    install_requires=["SQLAlchemy"],
+    keywords="cs50",
+    name="cs50",
+    packages=["cs50"],
+    url="https://github.com/cs50/python-cs50",
+    version="1.3.0"
+)

From 308d3a9a653e965c791cc6ac1edb1ae048e60d21 Mon Sep 17 00:00:00 2001
From: Kareem Zidane <kzidane@cs50.harvard.edu>
Date: Sat, 1 Apr 2017 20:26:08 +0200
Subject: [PATCH 2/2] deploys on tags only and creates github releases

---
 .travis.yml | 36 +++++++++++++++++++++++++++++++-----
 Makefile    | 13 ++++++++++++-
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 67fdbd4..af46af4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,10 +9,36 @@ script: make build
 before_deploy: pip install twine
 
 deploy:
-  provider: script
 
-  # upload to PyPI
-  script: twine upload -u $PYPI_USERNAME -p $PYPI_PASSWORD dist/*
+  # create github release
+  - provider: releases
 
-  # avoid stashing sdist
-  skip_cleanup: true
+    # GitHub access token
+    api_key:
+      secure: "Hv2ICkPkC7hiRw8GS9adkEcfoYGeVPbGHRNPQdGxLTeP1Mz9x/2ylUprrb2Ohq+pHGRa1W55nSJAZWHto4L/seWS17vN1JB1o71KYeD8h4Ywm/iJzYJFu4v8cmuT9qMPC89GtSGUkEZml+Vd6lb6d/eBr7HWoAMF7LCobzVvpJftgSBqkN1Z0aaunGNRtPVaqf0D4iQMSU1e0X9HFyIsxjS68sNqVcU/eSqbkHQ32COliOdEZXDqNmoJjIq4NYVH7DCS4kSpfxSd3BkJPn1UH4891MntflMllH7khmSA0lqSuunp+olfzhzchYb0/e0LavqYyFU/cRemyt8RBuE0GD3J3TMudVav/5HLKt6/exZwqfv7bHyorDXkkKGJqYNPUCOD2K4RS4ExpUU5c5en5inJZdgKYVI9gZS15oXmKV3H/8JkJPgx0xRP1Rx8niQKezKdFb0dZxArbMBUuAnolgyoq2EgnsNYhboRWXoJP36FCWFn8U8UNUfmgOkkMcP59mZ6svznxWPIyCMhfGgShY03GTvPp94P6c6OZJpjyjmWyPsvGZJrvnRlJ8VxBaUBcfuQl9rtBorwJ3VI1VWguyBaSINM6OWPtEJ0J2oVM/8Dvjuw2qPNkCdUhflc7wV/AUYB9/6rfpjY+GwTEKtZBBw4epbZX/B0L+vdRONZJ0Q="
+
+    # enable wildcards in filenames
+    file_glob: true
+
+    # upload sdist
+    file: dist/*
+
+    # avoid stashing sdist
+    skip_cleanup: true
+
+    # create releases on tags only
+    on:
+      tags: true
+
+  # deploy to PyPI
+  - provider: script
+
+    # upload sdist to PyPI
+    script: twine upload -u $PYPI_USERNAME -p $PYPI_PASSWORD dist/*
+
+    # avoid stashing sdist
+    skip_cleanup: true
+
+    # deploy on tags only
+    on:
+      tags: true
diff --git a/Makefile b/Makefile
index 6ff0b4b..415b084 100644
--- a/Makefile
+++ b/Makefile
@@ -8,4 +8,15 @@ clean:
 
 .PHONY: install
 install: build
-	pip install dist/cs50*.tar.gz
+	pip install dist/*.tar.gz
+
+.PHONY: push
+push:
+	git push origin "v$$(python setup.py --version)"
+
+.PHONY: release
+release: tag push
+
+.PHONY: tag
+tag:
+	git tag "v$$(python setup.py --version)"