8000 FIX: Respect versionfile_source in __init__.py snippet by staticintlucas · Pull Request #241 · python-versioneer/python-versioneer · GitHub
[go: up one dir, main page]

Skip to content

FIX: Respect versionfile_source in __init__.py snippet #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/setupfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ def do_vcs_install(): pass # --STRIP DURING BUILD

"""

INIT_PY_SNIPPET = """
OLD_SNIPPET = """
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
"""

INIT_PY_SNIPPET = """
from . import {0}
__version__ = {0}.get_versions()['version']
"""


def do_setup():
"""Do main VCS-independent setup function for installing Versioneer."""
Expand Down Expand Up @@ -83,10 +88,16 @@ def do_setup():
old = f.read()
except EnvironmentError:
old = ""
if INIT_PY_SNIPPET not in old:
module = os.path.splitext(os.path.basename(cfg.versionfile_source))[0]
snippet = INIT_PY_SNIPPET.format(module)< 8000 /td>
if OLD_SNIPPET in old:
print(" replacing boilerplate in %s" % ipy)
with open(ipy, "w") as f:
f.write(old.replace(OLD_SNIPPET, snippet))
elif snippet not in old:
print(" appending to %s" % ipy)
with open(ipy, "a") as f:
f.write(INIT_PY_SNIPPET)
f.write(snippet)
else:
print(" %s unmodified" % ipy)
else:
Expand Down
5 changes: 2 additions & 3 deletions test/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ def pf(fn):
if not script_only:
with open(self.project_file("src/demo/__init__.py")) as fobj:
i = fobj.read().splitlines()
self.assertEqual(i[-3], "from ._version import get_versions")
self.assertEqual(i[-2], "__version__ = get_versions()['version']")
self.assertEqual(i[-1], "del get_versions")
self.assertEqual(i[-2], "from . import _version")
self.assertEqual(i[-1], "__version__ = _version.get_versions()['version']")
self.git("commit", "-m", "add _version stuff")

# "versioneer.py setup" should be idempotent
Expand Down
0