-
Notifications
You must be signed in to change notification settings - Fork 1
Initial addition: python code that parses contributors for each file #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lwasser
wants to merge
6
commits into
pyOpenSci:main
Choose a base branch
from
lwasser:contribs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd6513f
Initial package setup
lwasser 44342dc
Add: initial files to sphinx extension
lwasser d0a39ff
Fix: don't commit version file
lwasser b0e73c1
Fix: name can't have dashes
lwasser c4c9a82
Fix: this is actually working kind of
lwasser 9ae9500
Fix: working via online repo
lwasser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
|
|
||
| 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"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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