Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode/*
Empty file added development.md
Empty file.
21 changes: 21 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Sphinx docs config

project = "sphinx-contribs"
copyright = "2024, pyOpenSci Community"
author = "pyOpenSci Community"
release = "0.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["sphinx-contribs"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, even if i install this extension, sphinx can't "see" or find it when you run sphinx-build


templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "pydata-sphinx-theme"
html_static_path = ["_static"]
20 changes: 20 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. sphinx-contribs documentation master file, created by
sphinx-quickstart on Sat Apr 27 15:34:11 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to sphinx-contribs's documentation!
===========================================

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "sphinx-contribs"
dynamic = ["version"]
description = 'A package that gets contributors via commits to each page'
readme = "README.md"
requires-python = ">=3.10"
license = "MIT"
keywords = []
authors = [
{ name = "Leah Wasser", email = "leah@pyopensci.org" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["sphinx>=3.0", "pygithub"]

[project.urls]
Documentation = "https://github.com/unknown/sphinx-contribs#readme"
Issues = "https://github.com/unknown/sphinx-contribs/issues"
Source = "https://github.com/unknown/sphinx-contribs"

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/sphinx-contribs/_version.py"

# Setup the extension as a hook
# [tool.hatch.metadata.hooks]
# sphinx-contribs = "sphinx_contribs.contribs:setup"
Empty file added src/sphinx-contribs/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions src/sphinx-contribs/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple, Union
VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
VERSION_TUPLE = object

version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '0.1.dev2+gfd6513f.d20240427'
__version_tuple__ = version_tuple = (0, 1, 'dev2', 'gfd6513f.d20240427')
91 changes: 91 additions & 0 deletions src/sphinx-contribs/contribs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""Currently using mamba envt: contributors for pygithub

This is the mkdocs plugin
https://github.com/byrnereese/mkdocs-git-committers-plugin/blob/master/mkdocs_git_committers_plugin/plugin.py

# Install extension
pip install -e .
# Build docs
sphinx-build -b html . _build/html

https://www.sphinx-doc.org/en/master/development/tutorials/helloworld.html

For this to work, setup your GITHUB token in your zsh, bashprofile envt

Right now this is slow as it will process all commits for each file.
Instead we probably want to create some sort of cache that has a history of
what has been processed. so it them only processes the most recent commits
and files.

we also want to allow it to ignore some files (which could be a sphinx conf.py
setting)
"""

import os

from github import Github
from sphinx.application import Sphinx

GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
REPO_NAME = "pyopensci/python-package-guide"

github = Github(GITHUB_TOKEN)
repo = github.get_repo(REPO_NAME)


def list_markdown_files(repo):
"""
List all Markdown files in the repository.
NOTE: this will also return readme and other files that we may not want
to consider.
"""
markdown_files = []
contents = repo.get_contents("") # Start at the root directory
while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(
repo.get_contents(file_content.path)
) # Add directory contents to list
elif file_content.path.endswith(".md"):
markdown_files.append(file_content.path)
return markdown_files


def get_unique_committers(github_token, repo_name, file_path):
# Here this will be getting a repo online. but generally this
# will be run as the docs are built in CI or locally. so
# this approach doesnt make sense to me.

commits = repo.get_commits(path=file_path)
unique_committers = set()

for commit in commits:
if commit.author:
unique_committers.add(commit.author.login)

committers_info = []
for login in unique_committers:
user = github.get_user(login)
committers_info.append(
{
"login": user.login,
"name": user.name,
"avatar_url": user.avatar_url,
"profile_url": f"https://github.com/{login}",
}
)

return committers_info


md_files = list_markdown_files(repo)

people = {}
for gh_file in md_files:
print("Processing: ", gh_file)
people[gh_file] = get_unique_committers(GITHUB_TOKEN, REPO_NAME, gh_file)


def setup(app: Sphinx):
app.connect("source-read", get_unique_committers)