Skip to content

Commit

Permalink
Removed deprecated pkg_resources API (#108)
Browse files Browse the repository at this point in the history
This commit replaces the deprecated `pkg_resources` API
with the new `importlib_resources` API
  • Loading branch information
LanderOtto authored May 27, 2024
1 parent bb5297c commit 9df41a3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions streamflow_postgresql/database.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

import json
import os
from typing import Any, MutableMapping, MutableSequence

import asyncpg
import pkg_resources
from importlib_resources import files
from streamflow.core import utils
from streamflow.core.asyncache import cachedmethod
from streamflow.core.context import StreamFlowContext
Expand Down Expand Up @@ -44,13 +43,14 @@ async def __aenter__(self):
timeout=self.timeout,
max_size=self.maxsize,
)
schema_path = pkg_resources.resource_filename(
__name__, os.path.join("schemas", "postgresql.sql")
)
with open(schema_path) as f:
async with self._pool.acquire() as conn:
async with conn.transaction():
await conn.execute(f.read())
async with self._pool.acquire() as conn:
async with conn.transaction():
await conn.execute(
files(__package__)
.joinpath("schemas")
.joinpath("postgresql.sql")
.read_text("utf-8")
)
return self._pool

async def __aexit__(self, exc_type, exc_val, exc_tb):
Expand Down Expand Up @@ -87,9 +87,12 @@ async def close(self):
await self.pool.close()

@classmethod
def get_schema(cls) -> str:
return pkg_resources.resource_filename(
__name__, os.path.join("schemas", "postgresql.json")
def get_schema(cls):
return (
files(__package__)
.joinpath("schemas")
.joinpath("postgresql.json")
.read_text("utf-8")
)

async def add_dependency(
Expand Down

0 comments on commit 9df41a3

Please sign in to comment.