title: Automatically increment version when publishing python package to pypi
body: <p>In order to get the version right when I upload a new distribution to PyPi, I have <code>setup.py</code> ask PyPi what the current version is (see function below), increment it, and use it as the <code>version</code> argument of the <code>setuptools.setup</code> call.</p>
  <p>Sure enough, pip installing works, but installing from source doesn't (and anyway, we wouldn't want the installation to have the incorrect version number).</p>
  <p>I could write a deploy script that would do the increment and call <code>setup</code> with the version number (and have <code>setup.py</code> use the current version instead).</p>
  <p>But I'm guessing there's a best-practice tool to do what I'm trying to do already?</p>
  <pre class="lang-py prettyprint-override"><code>def current_pypi_version(package: str) -&gt; str:
      req = urllib.request.Request(f'https://pypi.python.org/pypi/{package}/json')
      r = urllib.request.urlopen(req)
      if r.code == 200:
          t = json.loads(r.read())
          releases = t.get('releases', [])
          if releases:
              return sorted(releases)[-1]
  </code></pre>