mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-27 07:18:28 +01:00
Merge pull request #1831 from mroutis/fix-1824
dvc: refactor package versioning logic
This commit is contained in:
@@ -1,5 +1,38 @@
|
||||
from setuptools import setup, find_packages
|
||||
from dvc import VERSION
|
||||
from setuptools.command.build_py import build_py as _build_py
|
||||
import os
|
||||
|
||||
|
||||
# https://packaging.python.org/guides/single-sourcing-package-version/
|
||||
pkg_dir = os.path.dirname(__file__)
|
||||
|
||||
# This will define __version__ implicitly
|
||||
with open(os.path.join(pkg_dir, "dvc", "version.py")) as fobj:
|
||||
exec(fobj.read())
|
||||
|
||||
version = __version__ # noqa: F821
|
||||
|
||||
|
||||
# To achieve consistency between the build version and the one provided
|
||||
# by your package during runtime, you need to **pin** the build version.
|
||||
#
|
||||
# This custom class will replace the version.py module with a **static**
|
||||
# `__version__` that your package can read at runtime, assuring consistancy.
|
||||
#
|
||||
# References:
|
||||
# - https://docs.python.org/3.7/distutils/extending.html
|
||||
# - https://github.com/python/mypy
|
||||
class build_py(_build_py):
|
||||
def pin_version(self):
|
||||
path = os.path.join(self.build_lib, "dvc")
|
||||
self.mkpath(path)
|
||||
with open(os.path.join(path, "version.py"), "w") as fobj:
|
||||
fobj.write("# AUTOGENERATED at build time by setup.py\n")
|
||||
fobj.write('__version__ = "{}"\n'.format(version))
|
||||
|
||||
def run(self):
|
||||
self.execute(self.pin_version, ())
|
||||
_build_py.run(self)
|
||||
|
||||
|
||||
install_requires = [
|
||||
@@ -36,7 +69,7 @@ all_remotes = gs + s3 + azure + ssh
|
||||
|
||||
setup(
|
||||
name="dvc",
|
||||
version=VERSION,
|
||||
version=version,
|
||||
description="Git for data scientists - manage your code and data together",
|
||||
long_description=open("README.rst", "r").read(),
|
||||
author="Dmitry Petrov",
|
||||
@@ -63,5 +96,6 @@ setup(
|
||||
include_package_data=True,
|
||||
url="http://dataversioncontrol.com",
|
||||
entry_points={"console_scripts": ["dvc = dvc.main:main"]},
|
||||
cmdclass={"build_py": build_py},
|
||||
zip_safe=False,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user