Skip to content

Commit

Permalink
Replace deprecated function
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 28, 2024
1 parent 8e2af6e commit 92e5e21
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions netkan/netkan/download_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import logging
import re
from pathlib import Path
from importlib.resources import read_text
from string import Template
import urllib.parse
from typing import Dict, Tuple, Any, Optional

import requests

from .utils import repo_file_add_or_changed
from .utils import repo_file_add_or_changed, legacy_read_text
from .repos import CkanMetaRepo
from .metadata import Ckan

Expand All @@ -23,7 +22,7 @@ class GraphQLQuery:
MODULES_PER_GRAPHQL = 20

# The request we send to GitHub, with a parameter for the module specific section
GRAPHQL_TEMPLATE = Template(read_text('netkan', 'downloads_query.graphql'))
GRAPHQL_TEMPLATE = Template(legacy_read_text('netkan', 'downloads_query.graphql'))

# The request string per module, depends on getDownloads fragment existing in
# the main template
Expand Down
4 changes: 2 additions & 2 deletions netkan/netkan/mirrorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
import shutil
from pathlib import Path
from importlib.resources import read_text
from typing import Optional, List, Union, Iterable, BinaryIO, Dict, Any, TYPE_CHECKING
import boto3
import github
Expand All @@ -16,6 +15,7 @@
from .metadata import Ckan
from .repos import CkanMetaRepo
from .common import deletion_msg, download_stream_to_file, USER_AGENT
from .utils import legacy_read_text

if TYPE_CHECKING:
from mypy_boto3_sqs.type_defs import DeleteMessageBatchRequestEntryTypeDef
Expand All @@ -26,7 +26,7 @@
class CkanMirror(Ckan):

DESCRIPTION_TEMPLATE = Template(
read_text('netkan', 'mirror_description_template.jinja2'))
legacy_read_text('netkan', 'mirror_description_template.jinja2'))

BUCKET_EXCLUDE_PATTERN = re.compile(r'^[^a-zA-Z0-9]+|[^a-zA-Z0-9._-]')

Expand Down
6 changes: 3 additions & 3 deletions netkan/netkan/spacedock_adder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import re
import io
from importlib.resources import read_text
from string import Template
from collections import defaultdict, deque
import logging
Expand All @@ -17,6 +16,7 @@
from .mod_analyzer import ModAnalyzer
from .queue_handler import BaseMessageHandler, QueueHandler
from .repos import NetkanRepo
from .utils import legacy_read_text

if TYPE_CHECKING:
from mypy_boto3_sqs.service_resource import Message
Expand All @@ -28,8 +28,8 @@

# https://github.com/KSP-SpaceDock/SpaceDock/blob/master/KerbalStuff/ckan.py
class SpaceDockAdder:
COMMIT_TEMPLATE = Template(read_text('netkan', 'sd_adder_commit_template.md'))
PR_BODY_TEMPLATE = Template(read_text('netkan', 'sd_adder_pr_body_template.md'))
COMMIT_TEMPLATE = Template(legacy_read_text('netkan', 'sd_adder_commit_template.md'))
PR_BODY_TEMPLATE = Template(legacy_read_text('netkan', 'sd_adder_pr_body_template.md'))
USER_TEMPLATE = Template('[$username]($user_url)')
TITLE_TEMPLATE = Template('Add $name from $site_name')
GITHUB_PATH_PATTERN = re.compile(r'^/([^/]+)/([^/]+)')
Expand Down
4 changes: 2 additions & 2 deletions netkan/netkan/ticket_closer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import logging
from datetime import datetime, timedelta, timezone
from importlib.resources import read_text
from collections import defaultdict
from string import Template
import github

from .common import USER_AGENT
from .utils import legacy_read_text


class TicketCloser:

REPO_NAMES = ['CKAN', 'NetKAN']
BODY_TEMPLATE = Template(read_text('netkan', 'ticket_close_template.md'))
BODY_TEMPLATE = Template(legacy_read_text('netkan', 'ticket_close_template.md'))

def __init__(self, token: str, user_name: str) -> None:
self._gh = github.Github(token, user_agent=USER_AGENT)
Expand Down
5 changes: 5 additions & 0 deletions netkan/netkan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Union
from git import Repo
from importlib.resources import files


def init_repo(metadata: str, path: str, deep_clone: bool) -> Repo:
Expand Down Expand Up @@ -42,3 +43,7 @@ def repo_file_add_or_changed(repo: Repo, filename: Union[str, Path]) -> bool:
x.a_path for x in repo.index.diff(None)]:
return True
return False


def legacy_read_text(pkg: str, resource: str) -> str:
return files(pkg).joinpath(resource).read_text()

0 comments on commit 92e5e21

Please sign in to comment.