432 datetime.datetime
433 A datetime object representing the last updated date of the repository
434 """
435 logging.debug(f"[ezcv get_repo_last_updated()] Getting last updated date for https://github.com{user_name}/{repo_name}")436 response = requests.get(f'https://api.github.com/repos/{user_name}/{repo_name}/branches/master')
437 date_changed = datetime.datetime.strptime(response.json()["commit"]["commit"]["author"]["date"], "%Y-%m-%dT%H:%M:%SZ")
438 return date_changed
408 logging.debug(f"[ezcv generate_theme_metadata()] Generating metadata for gallery section: {section=}")
409 data["sections"]["gallery"] = {"type": "gallery"}
410 else:
411 logging.debug(f"[ezcv generate_theme_metadata()] Generating metadata for markdown section: {section=}")412 if os.path.isdir(os.path.join("content", section.replace(".jinja", ""))):
413 data["sections"][section.replace(".jinja", "")] = {"type": "markdown", "fields": _generate_fields(os.path.join("content", section.replace(".jinja", "")))}
414 else:
405 data["sections"][section]["feed"] = False
406
407 elif section == "gallery.jinja":
408 logging.debug(f"[ezcv generate_theme_metadata()] Generating metadata for gallery section: {section=}")409 data["sections"]["gallery"] = {"type": "gallery"}
410 else:
411 logging.debug(f"[ezcv generate_theme_metadata()] Generating metadata for markdown section: {section=}")
383 data["sections"] = {}
384 for section in os.listdir(os.path.join(theme_folder, "sections")):
385 if os.path.isdir(os.path.join(theme_folder,"sections", section)):
386 logging.debug(f"[ezcv generate_theme_metadata()] Generating metadata for blog-like section: {section=}")387 data["sections"][section] = {"type": "blog"}
388 if os.path.isdir(os.path.join("content", section)):
389 data["sections"][section]["fields"] = _generate_fields(os.path.join("content", section))
364 yaml.dump(dict(data_2), metadata_file)
365 ```
366 """
367 logging.debug(f"[ezcv generate_theme_metadata()] Generating metadata for {theme_folder=}")368 if not os.path.exists(theme_folder):
369 raise ValueError(f"Theme folder {theme_folder} does not exist")
370 elif not os.path.exists(os.path.join(theme_folder, "index.jinja")):
Formatting the message manually before passing it to a logging
call does unnecessary work if logging is disabled. Consider using the logging
module's built-in formatting features to avoid that.
If your logging level is set to "WARNING"
, but the logging call is:
logging.debug("Data: %s", data)
In the above example, there will be no logging as the level debug
is below warning
. The conversion of the data
object to a string will be skipped by the logging module resulting in improved performance.
logging.debug(f"Data: {data}")
In the code shown above, the conversion of the data
object to a string will happen regardless of whether the message is logged or not (which is based on the log level).
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug(f"Entered function {inspect.stack[0][3]}"))
import logging
import inspect
logging.basicConfig(level=logging.INFO)
logging.debug("Entered function %s", inspect.stack[0][3])