Repository: EFForg/starttls-policy-cli

Issue:
Publish package in python package index
[PyPI](https://pypi.org/) is a convenient way to deploy python packages using pip and central repo. No matter if code is still alpha or beta - PyPI allows that and has appropriate classifiers for such packages. I think such move almost without efforts allows wider spread of package usage.

Discussion:

Patch:
diff --git a/setup.py b/setup.py
index 1572b2f..6d87cbf 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ install_requires = [
 ]
 
 setup(
-    name='starttls_policy',
+    name='starttls_policy_cli',
     version=version,
     description="Policy API for STARTTLS Preload",
     url='https://github.com/EFForg/starttls-everywhere',
@@ -54,7 +54,7 @@ setup(
     },
     entry_points={
         'console_scripts': [
-            'starttls-policy = starttls_policy.main:main',
+            'starttls-policy-cli = starttls_policy_cli.main:main',
         ],
     }
 )
diff --git a/starttls_policy/__init__.py b/starttls_policy_cli/__init__.py
similarity index 100%
rename from starttls_policy/__init__.py
rename to starttls_policy_cli/__init__.py
diff --git a/starttls_policy/configure.py b/starttls_policy_cli/configure.py
similarity index 97%
rename from starttls_policy/configure.py
rename to starttls_policy_cli/configure.py
index 5aae81d..8ec010d 100644
--- a/starttls_policy/configure.py
+++ b/starttls_policy_cli/configure.py
@@ -6,9 +6,9 @@ import abc
 import os
 import six
 
-from starttls_policy import constants
-from starttls_policy import policy
-from starttls_policy import util
+from starttls_policy_cli import constants
+from starttls_policy_cli import policy
+from starttls_policy_cli import util
 
 class ConfigGenerator(object):
     # pylint: disable=useless-object-inheritance
diff --git a/starttls_policy/constants.py b/starttls_policy_cli/constants.py
similarity index 100%
rename from starttls_policy/constants.py
rename to starttls_policy_cli/constants.py
diff --git a/starttls_policy/main.py b/starttls_policy_cli/main.py
similarity index 96%
rename from starttls_policy/main.py
rename to starttls_policy_cli/main.py
index 60ef916..2963964 100644
--- a/starttls_policy/main.py
+++ b/starttls_policy_cli/main.py
@@ -2,7 +2,7 @@
 import argparse
 import os
 
-from starttls_policy import configure
+from starttls_policy_cli import configure
 
 GENERATORS = {
     "postfix": configure.PostfixGenerator,
diff --git a/starttls_policy/policy.json b/starttls_policy_cli/policy.json
similarity index 100%
rename from starttls_policy/policy.json
rename to starttls_policy_cli/policy.json
diff --git a/starttls_policy/policy.py b/starttls_policy_cli/policy.py
similarity index 99%
rename from starttls_policy/policy.py
rename to starttls_policy_cli/policy.py
index 0252cf5..f011232 100644
--- a/starttls_policy/policy.py
+++ b/starttls_policy_cli/policy.py
@@ -5,8 +5,8 @@ import datetime
 import io
 import json
 import six
-from starttls_policy import util
-from starttls_policy import constants
+from starttls_policy_cli import util
+from starttls_policy_cli import constants
 
 logger = logging.getLogger(__name__)
 logger.addHandler(logging.StreamHandler())
diff --git a/starttls_policy/util.py b/starttls_policy_cli/util.py
similarity index 100%
rename from starttls_policy/util.py
rename to starttls_policy_cli/util.py
diff --git a/tools/release.sh b/tools/release.sh
new file mode 100755
index 0000000..f5e05f4
--- /dev/null
+++ b/tools/release.sh
@@ -0,0 +1,71 @@
+#!/bin/sh -xe
+
+# Note: running this file will require you to enter the PGP card pin. Have it
+# memorized or in the clipboard before running this script.
+# After the release, run:
+#   `twine upload "./dist.$version/*/*"`
+
+DEV_RELEASE_BRANCH="$1"
+PORT=4000
+
+# Release dev packages to PyPI
+version="0.0.0.dev$(date +%Y%m%d)"
+tag="v$version"
+git tag --delete "$tag" || true
+
+# Check out dev branch in fresh repo clone
+root="$(mktemp -d -t starttls-policy-cli.$version.XXX)"
+git clone . $root
+cd $root
+git branch -f "$DEV_RELEASE_BRANCH"
+git checkout "$DEV_RELEASE_BRANCH"
+
+# Update version number
+sed -i "s/^version.*/version = '$version'/" setup.py
+
+# Sign tagged commit
+git add -p
+git -c commit.gpgsign=true commit -m "Release $version"
+git tag --local-user "842AEA40C5BCD6E1" \
+    --sign --message "Release $version" "$tag"
+
+# Build
+python setup.py clean
+rm -rf build dist
+python setup.py sdist
+python setup.py bdist_wheel
+
+# GPG-sign wheels
+for x in dist/*.tar.gz dist/*.whl
+do
+  gpg --detach-sign --armor --sign --local-user "842AEA40C5BCD6E1" $x
+done
+
+cd -
+
+mkdir "dist.$version"
+mv $root/dist "dist.$version/starttls-policy-cli"
+for pkg_dir in $subpkgs_dirs
+do
+  mv $pkg_dir/dist "dist.$version/$pkg_dir/"
+done
+
+echo "Testing packages"
+cd "dist.$version"
+# start local PyPI
+python -m SimpleHTTPServer $PORT &
+# cd .. is NOT done on purpose: we make sure that all subpacakges are
+# installed from local PyPI rather than current directory (repo root)
+virtualenv --no-site-packages ../venv
+. ../venv/bin/activate
+# Now, use our local PyPI. --pre allows installation of pre-release (incl. dev)
+pip install \
+  --pre \
+  --extra-index-url http://localhost:$PORT \
+  starttls-policy-cli
+# stop local PyPI
+kill $!
+
+echo "In order to upload packages run the following command:"
+echo twine upload "$root/dist.$version/*/*"
+


Test patch:
diff --git a/starttls_policy/tests/__init__.py b/starttls_policy_cli/tests/__init__.py
similarity index 100%
rename from starttls_policy/tests/__init__.py
rename to starttls_policy_cli/tests/__init__.py
diff --git a/starttls_policy/tests/configure_test.py b/starttls_policy_cli/tests/configure_test.py
similarity index 96%
rename from starttls_policy/tests/configure_test.py
rename to starttls_policy_cli/tests/configure_test.py
index dc864de..5bd4b2e 100644
--- a/starttls_policy/tests/configure_test.py
+++ b/starttls_policy_cli/tests/configure_test.py
@@ -6,8 +6,8 @@ import os
 
 import mock
 
-from starttls_policy import configure
-from starttls_policy.tests.util import param, parametrize_over
+from starttls_policy_cli import configure
+from starttls_policy_cli.tests.util import param, parametrize_over
 
 class MockGenerator(configure.ConfigGenerator):
     """Mock config generator for testing"""
@@ -44,7 +44,7 @@ class TestConfigGenerator(unittest.TestCase):
     def test_manual_instructions(self):
         with TempPolicyDir(test_json) as testdir:
             generator = MockGenerator(testdir)
-            with mock.patch("starttls_policy.configure.six.print_") as mock_print:
+            with mock.patch("starttls_policy_cli.configure.six.print_") as mock_print:
                 generator.manual_instructions()
                 mock_print.assert_called_once_with("\n"
                     "--------------------------------------------------\n"
diff --git a/starttls_policy/tests/main_test.py b/starttls_policy_cli/tests/main_test.py
similarity index 96%
rename from starttls_policy/tests/main_test.py
rename to starttls_policy_cli/tests/main_test.py
index 4b19c21..7c4a593 100644
--- a/starttls_policy/tests/main_test.py
+++ b/starttls_policy_cli/tests/main_test.py
@@ -3,7 +3,7 @@ import unittest
 import sys
 import mock
 
-from starttls_policy import main
+from starttls_policy_cli import main
 
 class TestArguments(unittest.TestCase):
     """Testing argument parser"""
@@ -52,7 +52,7 @@ class TestPerform(unittest.TestCase):
         parser.error = mock.MagicMock(side_effect=Exception)
         self.assertRaises(Exception, main._perform, parser.parse_args(), parser)
 
-    @mock.patch("starttls_policy.main._ensure_directory")
+    @mock.patch("starttls_policy_cli.main._ensure_directory")
     def test_generate(self, ensure_directory):
         # pylint: disable=protected-access, unused-argument
         main.GENERATORS = {"exists": mock.MagicMock()}
diff --git a/starttls_policy/tests/policy_test.py b/starttls_policy_cli/tests/policy_test.py
similarity index 98%
rename from starttls_policy/tests/policy_test.py
rename to starttls_policy_cli/tests/policy_test.py
index dc913a3..0a8b252 100644
--- a/starttls_policy/tests/policy_test.py
+++ b/starttls_policy_cli/tests/policy_test.py
@@ -5,8 +5,8 @@ import datetime
 import json
 import mock
 
-from starttls_policy import policy
-from starttls_policy import util
+from starttls_policy_cli import policy
+from starttls_policy_cli import util
 
 test_json = '{\
     "author": "Electronic Frontier Foundation",\
@@ -43,7 +43,7 @@ class TestConfig(unittest.TestCase):
         self.conf.policies = {'eff.org': self.sample_policy}
 
     def test_flush(self):
-        with mock.patch("starttls_policy.policy.open", mock.mock_open()) as m:
+        with mock.patch("starttls_policy_cli.policy.open", mock.mock_open()) as m:
             self.conf.flush("lol.txt")
             m.assert_called_with("lol.txt", "w")
             m().write.assert_called_once()
diff --git a/starttls_policy/tests/testdata/bigger_test_config.json b/starttls_policy_cli/tests/testdata/bigger_test_config.json
similarity index 100%
rename from starttls_policy/tests/testdata/bigger_test_config.json
rename to starttls_policy_cli/tests/testdata/bigger_test_config.json
diff --git a/starttls_policy/tests/testdata/config.json b/starttls_policy_cli/tests/testdata/config.json
similarity index 100%
rename from starttls_policy/tests/testdata/config.json
rename to starttls_policy_cli/tests/testdata/config.json
diff --git a/starttls_policy/tests/testdata/utf8.json b/starttls_policy_cli/tests/testdata/utf8.json
similarity index 100%
rename from starttls_policy/tests/testdata/utf8.json
rename to starttls_policy_cli/tests/testdata/utf8.json
diff --git a/starttls_policy/tests/util.py b/starttls_policy_cli/tests/util.py
similarity index 100%
rename from starttls_policy/tests/util.py
rename to starttls_policy_cli/tests/util.py
diff --git a/starttls_policy/tests/util_test.py b/starttls_policy_cli/tests/util_test.py
similarity index 97%
rename from starttls_policy/tests/util_test.py
rename to starttls_policy_cli/tests/util_test.py
index 6d22d8f..5ceb70d 100644
--- a/starttls_policy/tests/util_test.py
+++ b/starttls_policy_cli/tests/util_test.py
@@ -2,7 +2,7 @@
 import unittest
 from functools import partial
 
-from starttls_policy import util
+from starttls_policy_cli import util
 
 class TestEnforceUtil(unittest.TestCase):
     """ Unittests for "enforcer" functions."""