Skip to content

Commit

Permalink
Support src/ dir (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Apr 27, 2021
1 parent cc3e2a7 commit 6b42ca3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ dist: xenial
language: python
cache: pip
python:
- '3.6'
- '3.7'
- '3.9'
branches:
only:
- master # All other branches should become (draft) PRs and be build that way

install:
- pip install future-fstrings flit coveralls
- pip install flit coveralls
- flit install --deps develop
script:
- PYTHONPATH=. pytest --cov=get_version --black
Expand Down
2 changes: 2 additions & 0 deletions get_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def get_version(package: Union[Path, str]) -> str:
else:
name = path.with_suffix("").name
parent = path.parent
if parent.name == "src":
parent = parent.parent

return str(
get_version_from_dirname(name, parent)
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ['flit>=1.3']
build-backend = 'flit.buildapi'
requires = ['flit-core>=2,<4']
build-backend = 'flit_core.buildapi'

[tool.flit.metadata]
module = 'get_version'
Expand All @@ -13,7 +13,7 @@ classifiers = [
'Topic :: Software Development :: Libraries :: Python Modules',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
]
requires-python = '>=3.6'
requires-python = '>=3.7'
requires = ['setuptools']
description-file = 'README.rst'

Expand All @@ -27,5 +27,4 @@ test = [
]

[tool.black]
py36 = true
include = '\.pyi?$'
25 changes: 19 additions & 6 deletions tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,39 @@
"""


def test_git(temp_tree: TempTreeCB):
spec = {".git": {}, "git_mod.py": "print('hello')\n"}
@pytest.fixture(params=[True, False], ids=["src", "plain"])
def has_src(request) -> bool:
return request.param


def test_git(temp_tree: TempTreeCB, has_src):
content = {"git_mod.py": "print('hello')\n"}
if has_src:
content = dict(src=content)
spec = {".git": {}, **content}
with temp_tree(spec) as package, MockCommand(
"git", mock_git_describe.format(package)
):
v = get_version.get_version_from_git(package)
assert get_version.Version("0.1.2", "3", ["fefe123", "dirty"]) == v

v = get_version.get_version(package / "git_mod.py")
parent = (package / "src") if has_src else package
v = get_version.get_version(parent / "git_mod.py")
assert "0.1.2.dev3+fefe123.dirty" == v


def test_dir(temp_tree: TempTreeCB):
def test_dir(temp_tree: TempTreeCB, has_src):
dirname = "dir_mod-0.1.3+dirty"
spec = {dirname: {"dir_mod.py": "print('hi!')\n"}}
content = {"dir_mod.py": "print('hi!')\n"}
if has_src:
content = dict(src=content)
spec = {dirname: content}
with temp_tree(spec) as package:
v = get_version.get_version_from_dirname("dir_mod", package / dirname)
assert get_version.Version("0.1.3", None, ["dirty"]) == v

v = get_version.get_version(package / dirname / "dir_mod.py")
parent = (package / dirname / "src") if has_src else (package / dirname)
v = get_version.get_version(parent / "dir_mod.py")
assert "0.1.3+dirty" == v


Expand Down

0 comments on commit 6b42ca3

Please sign in to comment.