Repository: tox-dev/tox-travis

Issue:
Consider deprecating travis:after in favor of Build Stages
https://blog.travis-ci.com/2017-05-11-introducing-build-stages

I don't have any plans to remove travis:after, but with the announcement of build stages for Travis, I'm watching it closely, and considering whether it will fully cover the use-cases that travis:after does. I suspect that it will end up as the better option, and that we will end up adding a note to the docs declaring that the better fix.

Right now it's still early days, and we need to watch and see. There are still bugs in this beta feature that need to be ironed out, but I'm very glad to see Travis supporting this feature natively.

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=h1) Report
> Merging [#93](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=desc) into [master](https://codecov.io/gh/tox-dev/tox-travis/commit/53867873da9189cc04ed043147cbe1c915fb69d8?src=pr&el=desc) will **increase** coverage by `0.1%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/tox-dev/tox-travis/pull/93/graphs/tree.svg?token=CBMEkiKkWy&src=pr&height=150&width=650)](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master      #93     +/-   ##
=========================================
+ Coverage   88.88%   88.99%   +0.1%     
=========================================
  Files           5        5             
  Lines         207      209      +2     
  Branches       47       48      +1     
=========================================
+ Hits          184      186      +2     
  Misses         19       19             
  Partials        4        4
```


| [Impacted Files](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/tox\_travis/hooks.py](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=tree#diff-c3JjL3RveF90cmF2aXMvaG9va3MucHk=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=footer). Last update [5386787...61c0497](https://codecov.io/gh/tox-dev/tox-travis/pull/93?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

ryanhiebert: Sounds good. The release will be the test of that, though I'm fairly confident it will work from my experimenting on #91.

Patch:
diff --git a/.travis.yml b/.travis.yml
index 5b2f4fe..efd799d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,21 +18,27 @@ install:
  - pip install wheel codecov coverage
  - python setup.py bdist_wheel
  - pip install ./dist/tox_travis-*.whl
-script:
- - tox --installpkg ./dist/tox_travis-*.whl --travis-after
+script: tox --installpkg ./dist/tox_travis-*.whl
 after_success: coverage combine && codecov
 
-branches:
-  only:
-    - master
-    - /^\d+(\.\d+)*$/
-matrix:
+if: tag IS present OR branch = master
+jobs:
   fast_finish: true
   include:
   - python: 3.6
     env: TOXENV=docs
   - python: 3.6
     env: TOXENV=desc
+  - stage: deploy
+    python: 3.6
+    env: TRAVIS_STAGE=deploy
+    install: true
+    script: true
+    after_success: true
+
+stages:
+  - name: deploy
+    if: tag IS present
 
 deploy:
   provider: pypi
@@ -41,6 +47,5 @@ deploy:
     secure: KjQrEjwmfP+jqdHNQ6bJoNjOJHHz0kirrSORat2uJTulXaUs/nuDcZqTu7gxMFaM92z3eJZzTZmxO71cDhJiBt+FQhEtL/q8wd7Fv5d5v5EIlLFNqdEyCaTthSgXQa/HJTtbzjdFIEN8qCofHu+zEWMnb1ZHgUcK7hZHMCrHcVF4kD+k1myNro+1Pp/sGIUMUOkqocz+8OI2FuEQh0txXl0MLf2UEk53EK2noD4D/fm/YDDYJbAWlNPBbCBaU/ZGfzuFivh00bx9lAg7UB6t/A3iIasRUiAJbHdxvrxxGFAeOV/t09TcTtEcwBRyPe8JzSuReCROccyFB2TLOzfkt9h7TkdC2CWrMmXpI6UogTct++r3kavdsJuAZMbSy1jrnxkxtB1CW7DOly4v4JuyewpET7CnTjkhd9zIowESwJFjxwmns63AS2okQdPTCqsbbNp53Jk5fpf6qXwMFdaHT1kU1MpwoQPT0HnwLz3xybvjgfgu3t4KfEBvc0DCp89VMjCM9xkKTlziZkwOhXqaNhu+cVqo1/eUY/HDT/7V7xiL/U6U11UOrqtxkdDofoIl4NuiT7uoVaVctm/Y4kBEkJRZCwcjRsZJ0c06SvMvxhMDBUEM5IiXS6tH6Zp08MDYlclpKFGKdzOrxP2X0rVFIZ99KLyhfRNZuZcu92tDpP8=
   on:
     tags: true
-    python: 3.6
-    condition: $TOXENV != docs && $TOXENV != desc
+    condition: $TRAVIS_STAGE = deploy
   distributions: bdist_wheel
diff --git a/HISTORY.rst b/HISTORY.rst
index fe03e3a..c508bfe 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,6 +1,11 @@
 0.10 (TBD)
 ++++++++++
 
+* Deprecate the After All feature.
+  Travis now has `Build Stages`_, which are a better solution.
+
+.. _`Build Stages`: https://docs.travis-ci.com/user/build-stages
+
 
 0.9 (2017-11-12)
 ++++++++++++++++
diff --git a/docs/after.rst b/docs/after.rst
index 4de27af..da02c95 100644
--- a/docs/after.rst
+++ b/docs/after.rst
@@ -2,6 +2,22 @@
 After All
 =========
 
+.. deprecated:: 0.10
+
+.. warning::
+
+  This feature is deprecated.
+
+  Travis has added `Build Stages`_,
+  which are a better solution to this problem.
+  You will also likely want to check out `Conditions`_,
+  which make it much easier to determine
+  which jobs, stages, and builds will run.
+
+.. _`Build Stages`: https://docs.travis-ci.com/user/build-stages
+.. _`Conditions`: https://docs.travis-ci.com/user/conditional-builds-stages-jobs
+
+
 Inspired by `travis-after-all`_ and `travis_after_all`_,
 this feature allows a job to wait for other jobs to finish
 before it calls itself complete.
@@ -77,7 +93,7 @@ that corresponds to using the above ``travis:after`` section:
 This example deploys when the build is from a tag
 and the build is on Python 3.5
 and the build is using DJANGO="1.8".
-Together ``tox --travis-after`` and Tox's ``on`` conditions
+Together ``tox --travis-after`` and Travis' ``on`` conditions
 make sure that the deploy only happens after all tests pass.
 
 If any configuration item does not match,
diff --git a/src/tox_travis/hooks.py b/src/tox_travis/hooks.py
index 7624593..9b84632 100644
--- a/src/tox_travis/hooks.py
+++ b/src/tox_travis/hooks.py
@@ -51,6 +51,13 @@ def tox_configure(config):
         for envconfig in config.envconfigs.values():
             envconfig.ignore_outcome = False
 
+    # after
+    if config.option.travis_after:
+        print('The after all feature has been deprecated. Check out Travis\' '
+              'build stages, which are a better solution. '
+              'See https://tox-travis.readthedocs.io/en/stable/after.html '
+              'for more details.', file=sys.stderr)
+
 
 def tox_subcommand_test_post(config):
     """Wait for this job if the configuration matches."""
diff --git a/tox.ini b/tox.ini
index d1bb173..898e673 100644
--- a/tox.ini
+++ b/tox.ini
@@ -28,9 +28,6 @@ deps =
 commands =
     python setup.py check --restructuredtext --strict
 
-[travis:after]
-toxenv = py36
-
 [flake8]
 ignore = D203
 


Test patch:
diff --git a/tests/test_after.py b/tests/test_after.py
index b48316b..7d934d4 100644
--- a/tests/test_after.py
+++ b/tests/test_after.py
@@ -1,15 +1,65 @@
 """Tests of the --travis-after flag."""
 import pytest
 import py
+import subprocess
+from contextlib import contextmanager
 from tox_travis.after import (
     travis_after,
     after_config_matches,
 )
 
 
+ini = b"""
+[tox]
+envlist = py35, py36
+"""
+
+coverage_config = b"""
+[run]
+branch = True
+parallel = True
+source = tox_travis
+
+[paths]
+source =
+    src
+    */site-packages
+"""
+
+
 class TestAfter:
     """Test the logic of waiting for other jobs to finish."""
 
+    def call(self, command):
+        """Return the raw output of the given command."""
+        proc = subprocess.Popen(
+            command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = proc.communicate()
+        return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
+
+    @contextmanager
+    def configure(self, tmpdir, monkeypatch, tox_ini, version):
+        """Configure the environment for a test."""
+        origdir = tmpdir.chdir()
+        tmpdir.join('tox.ini').write(tox_ini)
+        tmpdir.join('.coveragerc').write(coverage_config)
+        monkeypatch.setenv('TRAVIS', 'true')
+        monkeypatch.setenv('TRAVIS_PYTHON_VERSION', version)
+
+        yield
+
+        # Change back to the original directory
+        # Copy .coverage.* report files
+        origdir.chdir()
+        for f in tmpdir.listdir(lambda f: f.basename.startswith('.coverage.')):
+            f.copy(origdir)
+
+    def test_after_deprecated(self, tmpdir, monkeypatch):
+        """Show deprecation message when using --travis-after."""
+        with self.configure(tmpdir, monkeypatch, ini, '3.6'):
+            _, _, stderr = self.call(['tox', '-l', '--travis-after'])
+            assert 'The after all feature has been deprecated.' in stderr
+
     def test_pull_request(self, mocker, monkeypatch, capsys):
         """Pull requests should not run after-all."""
         mocker.patch('tox_travis.after.after_config_matches',
diff --git a/tests/test_envlist.py b/tests/test_envlist.py
index 91daef9..72890a3 100644
--- a/tests/test_envlist.py
+++ b/tests/test_envlist.py
@@ -210,7 +210,7 @@ class TestToxEnv:
             assert self.tox_envs() == expected
 
     def test_travis_config_filename(self, tmpdir, monkeypatch):
-        """Give the correct env for CPython 2.7."""
+        """Give the correct env for manual filename."""
         with self.configure(tmpdir, monkeypatch, tox_ini, 'CPython', 3, 6,
                             ini_filename='spam.ini'):
             assert self.tox_envs(ini_filename='spam.ini') == ['py36']