-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Parse and display recent contributors from YAML #23
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
Merged
melissawm
merged 8 commits into
pyOpenSci:main
from
Phinart98:#10-parse-contributor-data
Aug 27, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1cdceed
feat: Parse and display recent contributors from YAML
Phinart98 d592318
docs: Update all docstrings to numpy style format
Phinart98 673b1ec
Merge branch 'pyOpenSci:main' into #10-parse-contributor-data
Phinart98 971df32
Replace PyYAML with ruamel.yaml for active maintenance
Phinart98 41c7f3b
include uv.lock
Phinart98 0a1c78b
Merge branch 'main' into #10-parse-contributor-data
Phinart98 284a64a
Address code review feedback and simplify contributor logic
Phinart98 898bb40
Merge branch '#10-parse-contributor-data' of https://github.com/Phina…
Phinart98 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
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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 |
---|---|---|
@@ -1,3 +1,97 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
from django.db import models | ||
from typing import Optional | ||
|
||
|
||
class Contributor(models.Model): | ||
""" | ||
Django model representing a pyOpenSci contributor. | ||
|
||
This model mirrors the PersonModel from pyosMeta for future database migration. | ||
Currently, contributor data is read directly from YAML files. | ||
""" | ||
|
||
# Basic information | ||
name = models.CharField(max_length=255, null=True, blank=True) | ||
github_username = models.CharField(max_length=100, unique=True) | ||
github_image_id = models.IntegerField(null=True, blank=True) | ||
bio = models.TextField(null=True, blank=True) | ||
organization = models.CharField(max_length=255, null=True, blank=True) | ||
location = models.CharField(max_length=255, null=True, blank=True) | ||
email = models.EmailField(null=True, blank=True) | ||
|
||
# Dates | ||
date_added = models.DateField(null=True, blank=True) | ||
|
||
# Role flags | ||
deia_advisory = models.BooleanField(default=False) | ||
editorial_board = models.BooleanField(default=False) | ||
emeritus_editor = models.BooleanField(default=False) | ||
advisory = models.BooleanField(default=False) | ||
emeritus_advisory = models.BooleanField(default=False) | ||
board = models.BooleanField(default=False) | ||
|
||
# Social media and external links | ||
twitter = models.CharField(max_length=50, null=True, blank=True) | ||
mastodon = models.URLField(null=True, blank=True) | ||
orcidid = models.CharField(max_length=50, null=True, blank=True) | ||
website = models.URLField(null=True, blank=True) | ||
|
||
# JSON fields for lists (SQLite compatible) | ||
title = models.JSONField(default=list, blank=True) | ||
partners = models.JSONField(default=list, blank=True) | ||
contributor_type = models.JSONField(default=list, blank=True) | ||
packages_eic = models.JSONField(default=list, blank=True) | ||
packages_editor = models.JSONField(default=list, blank=True) | ||
packages_submitted = models.JSONField(default=list, blank=True) | ||
packages_reviewed = models.JSONField(default=list, blank=True) | ||
|
||
# Metadata | ||
sort = models.IntegerField(null=True, blank=True) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
ordering = ['-date_added', 'sort', 'name'] | ||
verbose_name = "Contributor" | ||
verbose_name_plural = "Contributors" | ||
|
||
def __str__(self) -> str: | ||
return self.display_name | ||
|
||
@property | ||
def display_name(self) -> str: | ||
""" | ||
Return name if available, otherwise GitHub username. | ||
|
||
Returns | ||
------- | ||
str | ||
The contributor's display name. | ||
""" | ||
return self.name or f"@{self.github_username}" | ||
|
||
@property | ||
def github_avatar_url(self) -> Optional[str]: | ||
""" | ||
Generate GitHub avatar URL from image ID. | ||
|
||
Returns | ||
------- | ||
str or None | ||
GitHub avatar URL if image ID exists, None otherwise. | ||
""" | ||
if self.github_image_id: | ||
return f"https://avatars.githubusercontent.com/u/{self.github_image_id}?s=400&v=4" | ||
return None | ||
|
||
@property | ||
def github_profile_url(self) -> str: | ||
""" | ||
Generate GitHub profile URL. | ||
|
||
Returns | ||
------- | ||
str | ||
GitHub profile URL for the contributor. | ||
""" | ||
return f"https://github.com/{self.github_username}" |
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
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,131 @@ | ||
""" | ||
Utility functions for working with contributor data. | ||
|
||
This module provides functions to fetch and parse contributor data from YAML files, | ||
following the same format used by the Jekyll site and pyosMeta package. | ||
""" | ||
|
||
from ruamel.yaml import YAML, YAMLError | ||
import logging | ||
from typing import List, Dict, Any | ||
from urllib.request import urlopen | ||
from urllib.error import URLError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# Initialize YAML parser with safe loading | ||
yaml = YAML(typ='safe') | ||
|
||
|
||
class ContributorDataError(Exception): | ||
"""Custom exception for contributor data related errors.""" | ||
pass | ||
|
||
|
||
def fetch_contributors_yaml(url: str = None) -> List[Dict[str, Any]]: | ||
""" | ||
Fetch contributor data from YAML source. | ||
|
||
Parameters | ||
---------- | ||
url : str, optional | ||
URL to fetch YAML from. If None, uses the default pyOpenSci GitHub URL. | ||
|
||
Returns | ||
------- | ||
list of dict | ||
List of contributor dictionaries. | ||
|
||
Raises | ||
------ | ||
ContributorDataError | ||
If data cannot be fetched or parsed. | ||
""" | ||
if url is None: | ||
url = "https://raw.githubusercontent.com/pyOpenSci/pyopensci.github.io/main/_data/contributors.yml" | ||
|
||
try: | ||
with urlopen(url) as response: | ||
yaml_content = response.read().decode('utf-8') | ||
contributors = yaml.load(yaml_content) | ||
|
||
if not isinstance(contributors, list): | ||
raise ContributorDataError("YAML data should be a list of contributors") | ||
|
||
logger.info(f"Successfully fetched {len(contributors)} contributors from {url}") | ||
return contributors | ||
|
||
except URLError as e: | ||
logger.error(f"Failed to fetch contributors from {url}: {e}") | ||
raise ContributorDataError(f"Network error: {e}") | ||
except YAMLError as e: | ||
logger.error(f"Failed to parse YAML: {e}") | ||
raise ContributorDataError(f"YAML parsing error: {e}") | ||
except Exception as e: | ||
logger.error(f"Unexpected error fetching contributors: {e}") | ||
raise ContributorDataError(f"Unexpected error: {e}") | ||
|
||
|
||
|
||
def get_recent_contributors(count: int = 4) -> List[Dict[str, Any]]: | ||
""" | ||
Get the most recent contributors. | ||
|
||
Parameters | ||
---------- | ||
count : int, default 4 | ||
Number of recent contributors to return. | ||
|
||
Returns | ||
------- | ||
list of dict | ||
List of recent contributor dictionaries, sorted by date_added descending. | ||
""" | ||
try: | ||
contributors = fetch_contributors_yaml() | ||
|
||
# Return most recent contributors (last items in list) | ||
reversed_contributors = list(reversed(contributors)) | ||
|
||
return reversed_contributors[:count] | ||
|
||
except ContributorDataError as e: | ||
logger.error(f"Failed to get recent contributors: {e}") | ||
return [] | ||
except Exception as e: | ||
logger.error(f"Unexpected error getting recent contributors: {e}") | ||
return [] | ||
|
||
|
||
def generate_github_avatar_url(github_image_id: int) -> str: | ||
""" | ||
Generate GitHub avatar URL from image ID. | ||
|
||
Parameters | ||
---------- | ||
github_image_id : int | ||
GitHub user's image ID. | ||
|
||
Returns | ||
------- | ||
str | ||
GitHub avatar URL. | ||
""" | ||
return f"https://avatars.githubusercontent.com/u/{github_image_id}?s=400&v=4" | ||
|
||
|
||
def generate_github_profile_url(github_username: str) -> str: | ||
melissawm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Generate GitHub profile URL from username. | ||
|
||
Parameters | ||
---------- | ||
github_username : str | ||
GitHub username. | ||
|
||
Returns | ||
------- | ||
str | ||
GitHub profile URL. | ||
""" | ||
return f"https://github.com/{github_username}" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.