Skip to content

Commit

Permalink
Fix: cleanup unused code and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lwasser committed Aug 20, 2023
1 parent 4fcb559 commit 2a19227
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 211 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ license = { text = "MIT" }
# for a user to run directly from the package.
[project.scripts] # Optional
update-contributors = "pyosmeta.cli.update_contributors:main"
process-reviews = "pyosmeta.cli.process_reviews:main"
update-reviews = "pyosmeta.cli.process_reviews:main"
update-review-teams = "pyosmeta.cli.update_review_teams:main"


Expand Down
2 changes: 2 additions & 0 deletions src/pyosmeta/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .contributors import PersonModel, ProcessContributors
from .parse_issues import ProcessIssues, ReviewModel

# Trick suggested by flake8 maintainer to ensure the imports above don't
# get flagged as being "unused"
__all__ = (
"ProcessIssues",
"ReviewModel",
Expand Down
51 changes: 1 addition & 50 deletions src/pyosmeta/cli/process_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,82 +17,33 @@
# ideally this could be passed as a CLI argument with the label we want to
# search for


# import argparse
import pickle

from pydantic import ValidationError

from pyosmeta import ProcessIssues, ReviewModel

# from pyosmeta.file_io import load_website_yml


# TODO: change the template to ask for date accepted format year-month-day


def main():
# update_all = False
# parser = argparse.ArgumentParser(
# description="A CLI script to update pyOpenSci reviews"
# )
# parser.add_argument(
# "--update",
# type=str,
# help="Will force update review info from GitHub for every review",
# )
# args = parser.parse_args()

# if args:
# update_all = True
# web_reviews_path = (
# "https://raw.githubusercontent.com/pyOpenSci/"
# "pyopensci.github.io/main/_data/packages.yml"
# )

process_review = ProcessIssues(
org="pyopensci",
repo_name="software-submission",
label_name="6/pyOS-approved 🚀🚀🚀",
)

# Open web yaml & return dict with package name as key
# web_reviews = load_website_yml(key="package_name", url=web_reviews_path)

# Get all issues for approved packages - load as dict
issues = process_review.return_response()
accepted_reviews = process_review.parse_issue_header(issues, 45)

# TODO: clean out extra fields from accepted reviews??

# Parse through reviews, identify new ones, fix case
# TODO - right now i've reverted back to always updating all reviews.
# Is there a use-case to only update a new package vs updating everything?
# if update_all:
# all_reviews = {}
# for key, meta in accepted_reviews.items():
# try:
# all_reviews[key.lower()] = ReviewModel(**meta)
# except ValidationError as ve:
# print(ve)

# else:
# for key, meta in accepted_reviews.items():
# if key.lower() not in all_reviews.keys():
# print("Yay - pyOS has a new package:", key)
# all_reviews[key.lower()] = ReviewModel(**meta)

# Update gh metrics via api for all packages
# TODO: this is working but above i made everything a model object
# do i want to do that above or just do it all at once below?
repo_endpoints = process_review.get_repo_endpoints(accepted_reviews)
all_reviews = process_review.get_gh_metrics(
repo_endpoints, accepted_reviews
)

# Finally populate model objects with review data + metrics
# TODO: this is really close - it's erroring when populating date
# i suspect in the github metadata
# Populate model objects with review data + metrics
final_reviews = {}
for key, review in all_reviews.items():
# First add gh meta to each dict
Expand Down
2 changes: 1 addition & 1 deletion src/pyosmeta/cli/update_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main():
# Populate all existing contribs into model objects
all_contribs = {}
for a_contrib in web_contribs:
print(a_contrib)
print(a_contrib["github_username"])
try:
all_contribs[a_contrib["github_username"].lower()] = PersonModel(
**a_contrib
Expand Down
12 changes: 0 additions & 12 deletions src/pyosmeta/cli/update_review_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@
# TODO: package-wide feature: create no update flag for entries
# TODO: make sure we can add a 3rd or 4th reviewer - crowsetta has this as
# will biocypher
# TODO: make sure to add a current editor boolean to the current editors and
# emeritus ones.
"""

# TODO - Case sensitivity is an issue with my validation using set
# - jointly
# - Jointly
# - devicely
# - Devicely
# - sevivi
import os

from pydantic import ValidationError
Expand All @@ -45,8 +36,6 @@ def get_clean_user(username: str) -> str:


def main():
# TODO: move refresh contribs and contribs dict attr to
# processContribs and remove this module altogether
process_contribs = ProcessContributors([])

# Two pickle files are outputs of the two other scripts
Expand Down Expand Up @@ -129,7 +118,6 @@ def main():

# Export to yaml
contribs_ls = [model.model_dump() for model in contribs.values()]
# Getting error dumping packages
pkgs_ls = [model.model_dump() for model in packages.values()]

clean_export_yml(contribs_ls, os.path.join("_data", "contributors.yml"))
Expand Down
150 changes: 3 additions & 147 deletions src/pyosmeta/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
field_serializer,
field_validator,
)
from typing import Dict, List, Optional, Set, Tuple, Union
from typing import List, Optional, Set, Tuple, Union


class UrlValidatorMixin:
# Check fields is false because this is being inherited by two diff classes
# Check fields is false given mixin is used by two diff classes
@field_validator(
"website", "documentation", mode="before", check_fields=False
)
Expand Down Expand Up @@ -69,7 +69,6 @@ def _check_url(url: str) -> bool:


class PersonModel(BaseModel, UrlValidatorMixin):
# Make sure model populates both aliases and original attr name
model_config = ConfigDict(
populate_by_name=True,
str_strip_whitespace=True,
Expand Down Expand Up @@ -158,7 +157,6 @@ def clean_strings(cls, string: str) -> str:
"""
if isinstance(string, str):
# Remove "\r\n" from the string value
string = re.sub(r"[\r\n]", "", string)
return string

Expand Down Expand Up @@ -220,47 +218,6 @@ def get_token(self) -> str:
load_dotenv()
return os.environ["GITHUB_TOKEN"]

# TODO - This utility is used across all scripts.
def clean_list(self, a_list: Union[str, List[str]]) -> List[str]:
"""Helper function that takes an input object as a list or string.
If it is a list containing none, it returns an empty list
if it is a string is returns the string as a list
removes 'None' if that is in the list. and returns
either an empty clean list of the list as is."""

if isinstance(a_list, str):
a_list = [a_list]
elif not a_list:
a_list = []
# Remove None from list
a_list = list(filter(lambda x: x, a_list))
return a_list

# TODO - There is likely a better way to do this. If it returns an
# empty list then we know there are no new vals... so it likely can
# return a single thing
def unique_new_vals(
self, a_list: List[str], a_item: List[str]
) -> Tuple[bool, Optional[List[str]]]:
"""Checks two objects either a list and string or two lists
and evaluates whether there are differences between them.
Returns
-------
Tuple
Containing a boolean representing whether there are difference
or not and a list containing new value if there are differences.
"""

default = (False, None)
list_lower = [al.lower() for al in a_list]
item_lower = [ai.lower() for ai in a_item]
diff = list(set(item_lower) - set(list_lower))
if len(diff) > 0:
default = (True, diff)
return default

def check_contrib_type(self, json_file: str):
"""
Determine the type of contribution the person
Expand Down Expand Up @@ -323,6 +280,7 @@ def load_json(self, json_path: str) -> dict:
print(ae)
return json.loads(response.text)

# TODO: check is i'm using the contrib type part of this method ?
def process_json_file(self, json_file: str) -> Tuple[str, List]:
"""Deserialize a JSON file from a URL and cleanup data
Expand Down Expand Up @@ -497,105 +455,3 @@ def combine_users(self, repoDict: dict, webDict: dict) -> dict:
print("New user found. Adding: ", gh_user)
webDict[gh_user] = repoDict[gh_user]
return webDict

# # TODO: i think i can remove this method
# def add_new_user(self, gh_user: str) -> dict:
# """Add a new user to the contrib file using gh username

# This method does a few things.
# 1. Adds a new template entry for the user w no values populated
# 2. Gets user metadata from the user's github profile
# 3. Updates their contrib entry with the gh data

# Parameters
# ----------
# gh_user : str
# String representing the GitHub username

# Returns
# -------
# Dict
# Username is the key and the updated github profile info is
# contained in the dict.

# """

# new = {}
# # Rather than this template i can use the person_model
# new[gh_user] = self.create_contrib_template()
# gh_data = self.get_gh_data([gh_user])
# # Update their metadata in the dict and return
# updated_data = self.update_contrib_data(new, gh_data)
# return updated_data

def get_gh_data(
self, contribs: Union[Dict[str, str], List]
) -> dict[str, str]:
"""Parses through each GitHub username and hits the GitHub
API to grab user information.
Parameters
----------
contribs : dict
Dict containing all current contrib info
Returns
-------
Dict
A dict of updated user data via a list of github usernames
"""
all_user_info = {}
for gh_user in contribs:
print("Getting github data for: ", gh_user)
# If the user already has a name in the dict, don't update
# Important to allow us to update names to ensure correct spelling,
# etc on website
if isinstance(contribs, list):
aname = None
else:
aname = contribs[gh_user]["name"]

all_user_info[gh_user] = self.get_user_info(gh_user, aname)
return all_user_info

# Shouldn't need this anymore with pydantic
# def update_contrib_data(self, contrib_data: dict, gh_data: dict):
# """Update contributor data from the GH API return.

# Use the GitHub API to grab user profile data such as twitter handle,
# mastodon, website, email and location and update contributor
# information. GitHub profile data is the source of truth source for
# contributor metadata.

# Parameters
# ----------
# contrib_data : dict
# A dict containing contributor data to be updated
# gh_data : dict
# Updated contributor data pulled from github API

# Returns
# -------
# dict
# Dictionary containing updated contributor data.
# """

# for i, gh_name in enumerate(contrib_data.keys()):
# print(i, gh_name)
# # Update the key:value pairs for data pulled from GitHub
# for akey in self.update_keys:
# if akey == "website":
# url = gh_data[gh_name][gh_name][akey]
# # Fix the url format and check to see if it works online
# url = self.format_url(url)
# # It url is valid, add to dict
# if self._check_url(url):
# contrib_data[gh_name][akey] = url
# else:
# contrib_data[gh_name][akey] = ""
# else:
# contrib_data[gh_name][akey] = gh_data[gh_name][gh_name][
# akey
# ]

# return contrib_data

0 comments on commit 2a19227

Please sign in to comment.