Skip to content

Commit

Permalink
Make copyright year in Flower docs dynamic (#2699)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Steiner authored Dec 15, 2023
1 parent 6f67e7b commit 346b595
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check copyright line
run: ./dev/test-copyright.sh
- name: Bootstrap
uses: ./.github/actions/bootstrap
- name: Install pandoc
Expand Down
3 changes: 2 additions & 1 deletion baselines/doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# ==============================================================================


import datetime
import os
import sys
from sphinx.application import ConfigError
Expand All @@ -32,7 +33,7 @@
# -- Project information -----------------------------------------------------

project = "Flower"
copyright = "2022 Flower Labs GmbH"
copyright = f"{datetime.date.today().year} Flower Labs GmbH"
author = "The Flower Authors"

# The full version, including alpha/beta/rc tags
Expand Down
13 changes: 8 additions & 5 deletions datasets/doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# ==============================================================================


import datetime
import os
import sys
from sphinx.application import ConfigError
Expand All @@ -33,7 +34,7 @@
# -- Project information -----------------------------------------------------

project = "Flower Datasets"
copyright = "2023 Flower Labs GmbH"
copyright = f"{datetime.date.today().year} Flower Labs GmbH"
author = "The Flower Authors"

# The full version, including alpha/beta/rc tags
Expand Down Expand Up @@ -74,25 +75,27 @@
# The full name is still at the top of the page
add_module_names = False


def find_test_modules(package_path):
"""Go through the python files and exclude every *_test.py file."""
full_path_modules = []
for root, dirs, files in os.walk(package_path):
for file in files:
if file.endswith('_test.py'):
if file.endswith("_test.py"):
# Construct the module path relative to the package directory
full_path = os.path.join(root, file)
relative_path = os.path.relpath(full_path, package_path)
# Convert file path to dotted module path
module_path = os.path.splitext(relative_path)[0].replace(os.sep, '.')
module_path = os.path.splitext(relative_path)[0].replace(os.sep, ".")
full_path_modules.append(module_path)
modules = []
for full_path_module in full_path_modules:
parts = full_path_module.split('.')
parts = full_path_module.split(".")
for i in range(len(parts)):
modules.append('.'.join(parts[i:]))
modules.append(".".join(parts[i:]))
return modules


# Stop from documenting the *_test.py files.
# That's the only way to do that in autosummary (make the modules as mock_imports).
autodoc_mock_imports = find_test_modules(os.path.abspath("../../"))
Expand Down
15 changes: 15 additions & 0 deletions dev/test-copyright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -e

cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../

EXIT_CODE=0

while IFS= read -r -d '' file; do
COPYRIGHT=$(grep -h -r "copyright = " "$file")
if [ "$COPYRIGHT" != "copyright = f\"{datetime.date.today().year} Flower Labs GmbH\"" ]; then
echo "::error file=$file::Wrong copyright line. Expected: copyright = f\"{datetime.date.today().year} Flower Labs GmbH\""
EXIT_CODE=1
fi
done < <(find . -path "*/doc/source/conf.py" -print0)

exit $EXIT_CODE
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# ==============================================================================


import datetime
import os
import sys
from git import Repo
Expand Down Expand Up @@ -81,7 +82,7 @@
# -- Project information -----------------------------------------------------

project = "Flower"
copyright = "2022 Flower Labs GmbH"
copyright = f"{datetime.date.today().year} Flower Labs GmbH"
author = "The Flower Authors"

# The full version, including alpha/beta/rc tags
Expand Down
5 changes: 4 additions & 1 deletion examples/doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

# -- Project information -----------------------------------------------------

import datetime


project = "Flower"
copyright = "2022 Flower Labs GmbH"
copyright = f"{datetime.date.today().year} Flower Labs GmbH"
author = "The Flower Authors"

# The full version, including alpha/beta/rc tags
Expand Down

0 comments on commit 346b595

Please sign in to comment.