Skip to content

Commit

Permalink
Fix docs build v2 (#1591)
Browse files Browse the repository at this point in the history
* chore(git): dont track .idea files

* fix(kivymd): use `_version.py` file as the cannonical place

* chore(kivymd): update comment and remove fixme

* feat(kivymd): fix make_release script

* fix(kivymd): add missing comma

* fix(docs): read version file manually
  • Loading branch information
MagneticNeedle authored Jan 21, 2024
1 parent cce0154 commit 5387f2a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ temp

/kivymd/tools/release/*.zip
/kivymd/tools/release/temp
/kivymd/_version.py
.idea/
12 changes: 0 additions & 12 deletions .idea/KivyMD.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

17 changes: 13 additions & 4 deletions docs/sources/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@
# Path setup.
import os
import sys
from pathlib import Path

# Don't allow Kivy to handle args
os.environ["KIVY_NO_ARGS"] = "true"
os.environ["READTHEDOCS"] = "true"

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"
Expand Down
4 changes: 1 addition & 3 deletions kivymd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
5 changes: 5 additions & 0 deletions kivymd/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
release = False
__version__ = "2.0.1.dev0"
__hash__ = "43a2ce216bdf99224356e6db4106253afbe1cecb"
__short_hash__ = "43a2ce2"
__date__ = "2024-01-21"
14 changes: 7 additions & 7 deletions kivymd/tools/release/make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
49 changes: 27 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import subprocess
import sys
from datetime import datetime
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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"]
),
Expand Down

0 comments on commit 5387f2a

Please sign in to comment.