From b4ab047f61f9a87898e755510d0579c7016da084 Mon Sep 17 00:00:00 2001 From: Martynov Maxim Date: Mon, 16 Aug 2021 12:15:05 +0300 Subject: [PATCH] Fix python2.7 compatibility --- .pre-commit-config.yaml | 1 - pyproject.toml | 24 ++++++++++++++++++++++++ setuptools_git_versioning.py | 18 ++++++------------ 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 504a752..30115f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,6 @@ repos: rev: v2.21.0 hooks: - id: pyupgrade - args: [--py36-plus] - repo: https://github.com/ambv/black rev: 21.6b0 hooks: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..52e0fbc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[tool.isort] +profile = "black" +multi_line_output = 3 + +[tool.black] +line-length = 120 +target-version = ['py27', 'py33', 'py34', 'py35', 'py36', 'py37', 'py38'] +include = '\.pyi?$' +exclude = ''' + +( + /( + \.eggs # exclude a few common directories in the + | \.git # root of the project + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist + )/ +) +''' diff --git a/setuptools_git_versioning.py b/setuptools_git_versioning.py index e1200c6..fb5b5f4 100644 --- a/setuptools_git_versioning.py +++ b/setuptools_git_versioning.py @@ -15,9 +15,7 @@ def _exec(cmd): # type: (str) -> List[str] try: - stdout = subprocess.check_output( - cmd, shell=True, universal_newlines=True # nosec - ) + stdout = subprocess.check_output(cmd, shell=True, universal_newlines=True) # nosec except subprocess.CalledProcessError as e: stdout = e.output lines = stdout.splitlines() @@ -64,14 +62,14 @@ def get_tag(): # type: () -> Optional[str] def get_sha(name="HEAD"): # type: (str) -> Optional[str] - sha = _exec(f'git rev-list -n 1 "{name}"') + sha = _exec('git rev-list -n 1 "{}"'.format(name)) if sha: return sha[0] return None def get_latest_file_commit(path): # type: (str) -> Optional[str] - sha = _exec(f'git log -n 1 --pretty=format:%H -- "{path}"') + sha = _exec('git log -n 1 --pretty=format:%H -- "{}"'.format(path)) if sha: return sha[0] return None @@ -85,7 +83,7 @@ def is_dirty(): # type: () -> bool def count_since(name): # type: (str) -> Optional[int] - res = _exec(f'git rev-list --count HEAD "^{name}"') + res = _exec('git rev-list --count HEAD "^{}"'.format(name)) if res: return int(res[0]) return None @@ -109,9 +107,7 @@ def parse_config(dist, _, value): # type: (Distribution, Any, Any) -> None starting_version = value.get("starting_version", DEFAULT_STARTING_VERSION) version_callback = value.get("version_callback", None) version_file = value.get("version_file", None) - count_commits_from_version_file = value.get( - "count_commits_from_version_file", False - ) + count_commits_from_version_file = value.get("count_commits_from_version_file", False) branch_formatter = value.get("branch_formatter", None) version = version_from_git( @@ -191,9 +187,7 @@ def version_from_git( else: t = template - version = t.format( - sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha - ) + version = t.format(sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha) # Ensure local version label only contains permitted characters public, sep, local = version.partition("+")