Skip to content

Commit

Permalink
Fix python2.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Aug 16, 2021
1 parent be88c2a commit b4ab047
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
)/
)
'''
18 changes: 6 additions & 12 deletions setuptools_git_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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("+")
Expand Down

0 comments on commit b4ab047

Please sign in to comment.