Browse Source

Merge pull request #34 from Holzhaus/ci-improvements

CI improvements
Jan Holthuis 4 years ago
parent
commit
cc23360e98
2 changed files with 70 additions and 36 deletions
  1. 40 30
      .pre-commit/version_check.py
  2. 30 6
      .travis.yml

+ 40 - 30
.pre-commit/version_check.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 import importlib.util
 import os
 import pkgutil
@@ -12,6 +12,8 @@ import docutils.parsers.rst
 import docutils.utils
 import docutils.frontend
 
+CHANGELOG_PATTERN = re.compile(r"^Version (\S+)((?: \(unreleased\)))?$")
+
 
 def parse_rst(text: str) -> docutils.nodes.document:
     parser = docutils.parsers.rst.Parser()
@@ -51,14 +53,12 @@ def get_sphinxchangelog_version(rootdir):
     assert len(visitor.sectiontitles_found) == len(unique_sectiontitles)
     assert visitor.sectiontitles_found[0] == "Changelog"
 
-    changelog_pattern = re.compile(r"^Version (\S+)((?: \(unreleased\)))?$")
-
-    matchobj = changelog_pattern(visitor.sectiontitles_found[1])
+    matchobj = CHANGELOG_PATTERN.match(visitor.sectiontitles_found[1])
     assert matchobj
     version = matchobj.group(1)
     version_unreleased = matchobj.group(2)
 
-    matchobj = changelog_pattern(visitor.sectiontitles_found[2])
+    matchobj = CHANGELOG_PATTERN.match(visitor.sectiontitles_found[2])
     assert matchobj
     release = matchobj.group(1)
     release_unreleased = matchobj.group(2)
@@ -83,7 +83,7 @@ def get_setuppy_version(rootdir):
     """Get version from setup.py."""
     setupfile = os.path.join(rootdir, "setup.py")
     cmd = (sys.executable, setupfile, "--version")
-    release = subprocess.check_output(cmd, text=True).rstrip("\n")
+    release = subprocess.check_output(cmd).decode().rstrip(os.linesep)
     version = release.rpartition(".")[0]
     return version, release
 
@@ -112,43 +112,53 @@ def main():
 
     setuppy_version, setuppy_release = get_setuppy_version(rootdir)
     package_version, package_release = get_package_version(rootdir)
-    confpy_version, confpy_release = get_setuppy_version(rootdir)
-    changelog_version, changelog_release = get_setuppy_version(rootdir)
+    confpy_version, confpy_release = get_sphinxconfpy_version(rootdir)
+    changelog_version, changelog_release = get_sphinxchangelog_version(rootdir)
 
     version_head = "Version"
     version_width = max(
-        [
-            len(version_head),
-            len(setuppy_version),
-            len(package_version),
-            len(confpy_version),
-            len(changelog_version),
-        ]
+        (
+            len(repr(x))
+            for x in (
+                version_head,
+                setuppy_version,
+                package_version,
+                confpy_version,
+                changelog_version,
+            )
+        )
     )
 
     release_head = "Release"
     release_width = max(
-        [
-            len(release_head),
-            len(setuppy_release),
-            len(package_release),
-            len(confpy_release),
-            len(changelog_release),
-        ]
+        (
+            len(repr(x))
+            for x in (
+                release_head,
+                setuppy_release,
+                package_release,
+                confpy_release,
+                changelog_release,
+            )
+        )
     )
 
     print(
         f"File                            {version_head} {release_head}\n"
         f"------------------------------- {'-' * version_width}"
         f" {'-' * release_width}\n"
-        f"setup.py                        {setuppy_version:>{version_width}}"
-        f" {setuppy_release:>{release_width}}\n"
-        f"sphinx_multiversion/__init__.py {package_version:>{version_width}}"
-        f" {package_release:>{release_width}}\n"
-        f"docs/conf.py                    {confpy_version:>{version_width}}"
-        f" {confpy_release:>{release_width}}\n"
-        f"docs/changelog.rst              {changelog_version:>{version_width}}"
-        f" {changelog_release:>{release_width}}\n"
+        f"setup.py                       "
+        f" {setuppy_version!r:>{version_width}}"
+        f" {setuppy_release!r:>{release_width}}\n"
+        f"sphinx_multiversion/__init__.py"
+        f" {package_version!r:>{version_width}}"
+        f" {package_release!r:>{release_width}}\n"
+        f"docs/conf.py                   "
+        f" {confpy_version!r:>{version_width}}"
+        f" {confpy_release!r:>{release_width}}\n"
+        f"docs/changelog.rst             "
+        f" {changelog_version!r:>{version_width}}"
+        f" {changelog_release!r:>{release_width}}\n"
     )
 
     assert setuppy_version == confpy_version

+ 30 - 6
.travis.yml

@@ -1,9 +1,30 @@
-language: python
-python:
-- 3.6
-- 3.7
 os: linux
 dist: xenial
+language: python
+
+jobs:
+  include:
+    - name: "Ubuntu / Python 3.6"
+      python: 3.6
+    - name: "Ubuntu / Python 3.7"
+      python: 3.7
+    - name: "Windows / Python 3.6"
+      os: windows
+      language: shell
+      before_install:
+      - choco install python --version 3.6.8
+      env:
+      - PATH=/c/Python36:/c/Python36/Scripts:$PATH
+      - SKIP=check-executables-have-shebangs
+    - name: "Windows / Python 3.7"
+      os: windows
+      language: shell
+      before_install:
+      - choco install python --version 3.7.8
+      env:
+      - PATH=/c/Python37:/c/Python37/Scripts:$PATH
+      - SKIP=check-executables-have-shebangs
+
 cache:
   pip: true
 
@@ -22,8 +43,8 @@ script:
 
 # Deployment
 before_deploy:
-  - touch html/.nojekyll
-  - cp assets/gh-pages-redirect.html html/index.html
+- touch html/.nojekyll
+- cp assets/gh-pages-redirect.html html/index.html
 deploy:
   # Deploy documentation
 - provider: pages
@@ -35,6 +56,7 @@ deploy:
     branch: master
     repo: Holzhaus/sphinx-multiversion
     python: 3.7
+    os: linux
 
   # Deploy to PyPI
 - deploy:
@@ -48,6 +70,7 @@ deploy:
     branch: master
     repo: Holzhaus/sphinx-multiversion
     tags: true
+    os: linux
 
   # Deploy to Github Releases
 - provider: releases
@@ -65,3 +88,4 @@ deploy:
     repo: Holzhaus/sphinx-multiversion
     tags: true
     python: 3.7
+    os: linux