From 3f23ddd3cce8dce523fdf89e97b72b055b1954bb Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 30 Jun 2022 13:46:04 -0700 Subject: [PATCH] Support for python3.7 and python3.8 Added tox targets as well --- pseudo_builder.py | 2 ++ release_gitter.py | 11 ++++++++++- release_gitter_test.py | 38 ++++++++++++++++++-------------------- tox.ini | 2 +- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/pseudo_builder.py b/pseudo_builder.py index dc2952a..aab624d 100644 --- a/pseudo_builder.py +++ b/pseudo_builder.py @@ -2,6 +2,8 @@ This builder functions as a pseudo builder that instead downloads and installs a binary file using release-gitter based on a pyproject.toml file. It's a total hack... """ +from __future__ import annotations + from pathlib import Path from shutil import copytree from shutil import move diff --git a/release_gitter.py b/release_gitter.py index 8b5cd6c..075c568 100755 --- a/release_gitter.py +++ b/release_gitter.py @@ -1,4 +1,6 @@ #! /usr/bin/env python3 +from __future__ import annotations + import argparse import platform from collections.abc import Sequence @@ -91,7 +93,14 @@ def parse_git_remote(git_url: Optional[str] = None) -> GitRemoteInfo: f"{path[1:3]} Could not parse owner and repo from URL {git_url}" ) - return GitRemoteInfo(u.hostname, path[1], path[2].removesuffix(".git")) + repo = path[2] + try: + repo = repo.removesuffix(".git") # type: ignore + except AttributeError: + # Py < 3.9 + repo = repo[: -len(".git")] if repo and repo.endswith(".git") else repo + + return GitRemoteInfo(u.hostname, path[1], repo) def parse_cargo_version(p: Path) -> str: diff --git a/release_gitter_test.py b/release_gitter_test.py index 0d04120..4a04eab 100644 --- a/release_gitter_test.py +++ b/release_gitter_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import unittest from pathlib import Path from typing import Any @@ -111,27 +113,23 @@ class TestVersionInfo(unittest.TestCase): version = release_gitter.read_version() self.assertIsNone(version) - def test_cargo_file_has_version(self): - with ( - patch("pathlib.Path.exists", return_value=True), - patch( - "pathlib.Path.open", - mock_open(read_data="\n".join(["[package]", 'version = "1.0.0"'])), - ), - ): - version = release_gitter.read_version() - self.assertEqual(version, "1.0.0") + @patch("pathlib.Path.exists", return_value=True) + @patch( + "pathlib.Path.open", + mock_open(read_data="\n".join(["[package]", 'version = "1.0.0"'])), + ) + def test_cargo_file_has_version(self, *_): + version = release_gitter.read_version() + self.assertEqual(version, "1.0.0") - def test_cargo_file_missing_version(self): - with ( - patch("pathlib.Path.exists", return_value=True), - patch( - "pathlib.Path.open", - mock_open(read_data="\n".join(["[package]"])), - ), - ): - with self.assertRaises(ValueError): - release_gitter.read_version() + @patch("pathlib.Path.exists", return_value=True) + @patch( + "pathlib.Path.open", + mock_open(read_data="\n".join(["[package]"])), + ) + def test_cargo_file_missing_version(self, *_): + with self.assertRaises(ValueError): + release_gitter.read_version() if __name__ == "__main__": diff --git a/tox.ini b/tox.ini index 8e460b7..39f19b2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py3 +envlist = py3,py37,py38,py39 [testenv] deps =