diff --git a/.gitignore b/.gitignore index 7364fbee7..4bb3a3ad7 100644 --- a/.gitignore +++ b/.gitignore @@ -67,4 +67,4 @@ temp /kivymd/tools/release/*.zip /kivymd/tools/release/temp -/kivymd/_version.py +.idea/ diff --git a/.idea/KivyMD.iml b/.idea/KivyMD.iml deleted file mode 100644 index 8ca0067de..000000000 --- a/.idea/KivyMD.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6a988e520..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfb..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/docs/sources/conf.py b/docs/sources/conf.py index 41dead60a..a60321c9d 100644 --- a/docs/sources/conf.py +++ b/docs/sources/conf.py @@ -4,6 +4,7 @@ # Path setup. import os import sys +from pathlib import Path # Don't allow Kivy to handle args os.environ["KIVY_NO_ARGS"] = "true" @@ -11,17 +12,25 @@ sys.path.insert(0, os.path.abspath("_extensions")) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(".")))) +try: + kivymd_path = Path(__file__).parent.parent.parent / "kivymd" + # this is a hack for now, will implement a better solution later + # __version__ is defined in _version.py, imported by exec() below + # this is just so linter doesn't complain + __version__ = "" + with open(kivymd_path / "_version.py", encoding="utf-8") as f: + exec(f.read()) +except FileNotFoundError: + raise import autoapi_kivymd # NOQA. from _extensions -import kivymd # NOQA - # Project information. project = "KivyMD" copyright = "2022, Andrés Rodríguez, Ivanov Yuri, Artem Bulgakov and KivyMD contributors" author = "Andrés Rodríguez, Ivanov Yuri, Artem Bulgakov and KivyMD contributors" -version = kivymd.__version__ -release = kivymd.__version__ +version = __version__ +release = __version__ # General configuration. master_doc = "index" diff --git a/kivymd/__init__.py b/kivymd/__init__.py index 0b03e4e14..52f969ccc 100644 --- a/kivymd/__init__.py +++ b/kivymd/__init__.py @@ -26,10 +26,8 @@ import kivy from kivy.logger import Logger -__version__ = "2.0.1.dev0" -"""KivyMD version.""" +from kivymd._version import __version__, release -release = False if "READTHEDOCS" not in os.environ: kivy.require("2.3.0") diff --git a/kivymd/_version.py b/kivymd/_version.py new file mode 100644 index 000000000..d503c8e5c --- /dev/null +++ b/kivymd/_version.py @@ -0,0 +1,5 @@ +release = False +__version__ = "2.0.1.dev0" +__hash__ = "43a2ce216bdf99224356e6db4106253afbe1cecb" +__short_hash__ = "43a2ce2" +__date__ = "2024-01-21" diff --git a/kivymd/tools/release/make_release.py b/kivymd/tools/release/make_release.py index f321a2de5..c7af2a2b5 100644 --- a/kivymd/tools/release/make_release.py +++ b/kivymd/tools/release/make_release.py @@ -59,21 +59,21 @@ def replace_in_file(pattern, repl, file): return not file_content == new_file_content -def update_init_py(version, is_release, test: bool = False): - """Change version in `kivymd/__init__.py`.""" +def update_version_py(version, is_release, test: bool = False): + """Change version in `kivymd/_version.py`.""" - init_file = os.path.abspath("kivymd/__init__.py") + init_file = os.path.abspath("kivymd/_version.py") init_version_regex = r"(?<=^__version__ = ['\"])[^'\"]+(?=['\"]$)" success = replace_in_file(init_version_regex, version, init_file) if test and not success: - print("Couldn't update __init__.py file.", file=sys.stderr) + print("Couldn't update _version.py file.", file=sys.stderr) init_version_regex = r"(?<=^release = )(True|False)(?=$)" success = replace_in_file(init_version_regex, str(is_release), init_file) if test and not success: - print("Couldn't update __init__.py file.", file=sys.stderr) + print("Couldn't update _version.py file.", file=sys.stderr) def update_readme(previous_version, version, test: bool = False): @@ -264,7 +264,7 @@ def main(): git_push([], ask=ask, push=push) return - update_init_py(version, is_release=True, test=test) + update_version_py(version, is_release=True, test=test) update_readme(previous_version, version, test=test) changelog_index_file = os.path.join( @@ -303,7 +303,7 @@ def main(): version, test=test, ) - update_init_py(next_version, is_release=False, test=test) + update_version_py(next_version, is_release=False, test=test) git_commit(f"KivyMD {next_version}") git_push(branches_to_push, ask=ask, push=push) diff --git a/setup.py b/setup.py index 155e6582a..dd85d8052 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ import os -import re import subprocess import sys from datetime import datetime @@ -10,27 +9,29 @@ assert sys.version_info >= (3, 7, 0), "KivyMD requires Python 3.7+" +try: + # __version__ is defined in _version.py, imported by exec() below + # this is just so linter doesn't complain + __version__ = "" + with open( + Path(__file__).parent / "kivymd" / "_version.py", encoding="utf-8" + ) as f: + exec(f.read()) +except FileNotFoundError: + raise + def get_version() -> str: - """Get __version__ from __init__.py file.""" + """Return version string.""" - version_file = os.path.join( - os.path.dirname(__file__), "kivymd", "__init__.py" - ) - version_file_data = open(version_file, "rt", encoding="utf-8").read() - version_regex = r"(?<=^__version__ = ['\"])[^'\"]+(?=['\"]$)" - try: - version = re.findall(version_regex, version_file_data, re.M)[0] - return version - except IndexError: - raise ValueError(f"Unable to find version string in {version_file}.") + # keeping this for compatibility with previous versions of KivyMD + return __version__ -def write_version_info(): +def update_version_info(): """Create _version.py file with git revision and date.""" filename = os.path.join(os.path.dirname(__file__), "kivymd", "_version.py") - version = get_version() epoch = int(os.environ.get("SOURCE_DATE_EPOCH", time())) date = datetime.utcfromtimestamp(epoch).strftime("%Y-%m-%d") try: @@ -52,11 +53,16 @@ def write_version_info(): git_revision = "Unknown" version_info = ( - f"# THIS FILE IS GENERATED FROM KIVYMD SETUP.PY\n" - f"__version__ = '{version}'\n" - f"__hash__ = '{git_revision}'\n" - f"__short_hash__ = '{git_revision[:7]}'\n" - f"__date__ = '{date}'\n" + "\n".join( + [ + "release = False", + f'__version__ = "{__version__}"', + f'__hash__ = "{git_revision}"', + f'__short_hash__ = "{git_revision[:7]}"', + f'__date__ = "{date}"', + ] + ) + + "\n" ) open(filename, "wt", encoding="utf-8").write(version_info) @@ -71,7 +77,6 @@ def glob_paths(pattern): if file.endswith(pattern): filepath = os.path.join(str(Path(*Path(root).parts[1:])), file) - # FIXME: https://github.com/kivymd/KivyMD/issues/1305 try: out_files.append(filepath.split(f"kivymd{os.sep}")[1]) except IndexError: @@ -82,9 +87,9 @@ def glob_paths(pattern): if __name__ == "__main__": # Static strings are in setup.cfg - write_version_info() + update_version_info() setup( - version=get_version(), + version=__version__, packages=find_packages( include=["kivymd", "kivymd.*"], exclude=["kivymd.tools.release"] ),