Skip to content

Commit b4ab047

Browse files
committed
Fix python2.7 compatibility
1 parent be88c2a commit b4ab047

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ repos:
4747
rev: v2.21.0
4848
hooks:
4949
- id: pyupgrade
50-
args: [--py36-plus]
5150
- repo: https://github.com/ambv/black
5251
rev: 21.6b0
5352
hooks:

pyproject.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[tool.isort]
2+
profile = "black"
3+
multi_line_output = 3
4+
5+
[tool.black]
6+
line-length = 120
7+
target-version = ['py27', 'py33', 'py34', 'py35', 'py36', 'py37', 'py38']
8+
include = '\.pyi?$'
9+
exclude = '''
10+
11+
(
12+
/(
13+
\.eggs # exclude a few common directories in the
14+
| \.git # root of the project
15+
| \.mypy_cache
16+
| \.tox
17+
| \.venv
18+
| _build
19+
| buck-out
20+
| build
21+
| dist
22+
)/
23+
)
24+
'''

setuptools_git_versioning.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
def _exec(cmd): # type: (str) -> List[str]
1717
try:
18-
stdout = subprocess.check_output(
19-
cmd, shell=True, universal_newlines=True # nosec
20-
)
18+
stdout = subprocess.check_output(cmd, shell=True, universal_newlines=True) # nosec
2119
except subprocess.CalledProcessError as e:
2220
stdout = e.output
2321
lines = stdout.splitlines()
@@ -64,14 +62,14 @@ def get_tag(): # type: () -> Optional[str]
6462

6563

6664
def get_sha(name="HEAD"): # type: (str) -> Optional[str]
67-
sha = _exec(f'git rev-list -n 1 "{name}"')
65+
sha = _exec('git rev-list -n 1 "{}"'.format(name))
6866
if sha:
6967
return sha[0]
7068
return None
7169

7270

7371
def get_latest_file_commit(path): # type: (str) -> Optional[str]
74-
sha = _exec(f'git log -n 1 --pretty=format:%H -- "{path}"')
72+
sha = _exec('git log -n 1 --pretty=format:%H -- "{}"'.format(path))
7573
if sha:
7674
return sha[0]
7775
return None
@@ -85,7 +83,7 @@ def is_dirty(): # type: () -> bool
8583

8684

8785
def count_since(name): # type: (str) -> Optional[int]
88-
res = _exec(f'git rev-list --count HEAD "^{name}"')
86+
res = _exec('git rev-list --count HEAD "^{}"'.format(name))
8987
if res:
9088
return int(res[0])
9189
return None
@@ -109,9 +107,7 @@ def parse_config(dist, _, value): # type: (Distribution, Any, Any) -> None
109107
starting_version = value.get("starting_version", DEFAULT_STARTING_VERSION)
110108
version_callback = value.get("version_callback", None)
111109
version_file = value.get("version_file", None)
112-
count_commits_from_version_file = value.get(
113-
"count_commits_from_version_file", False
114-
)
110+
count_commits_from_version_file = value.get("count_commits_from_version_file", False)
115111
branch_formatter = value.get("branch_formatter", None)
116112

117113
version = version_from_git(
@@ -191,9 +187,7 @@ def version_from_git(
191187
else:
192188
t = template
193189

194-
version = t.format(
195-
sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha
196-
)
190+
version = t.format(sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha)
197191

198192
# Ensure local version label only contains permitted characters
199193
public, sep, local = version.partition("+")

0 commit comments

Comments
 (0)