Skip to content

Commit

Permalink
importlib-metadata & importlib-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Jablon committed May 10, 2021
1 parent f07fd09 commit 5fb6f1b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion procrastinate/contrib/django/migrations_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
from typing import Iterable, Iterator, Optional, Tuple

import attr
import importlib_resources
from django.db import migrations

# https://github.com/pypa/twine/pull/551
if sys.version_info[:2] <= (3, 9): # coverage: exclude
import importlib_resources
else:
import importlib.resources as importlib_resources

# For a thorough explaination of what this package does, see README.md in the same
# folder

Expand Down
7 changes: 6 additions & 1 deletion procrastinate/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys
from typing import Mapping

import importlib_metadata
# https://github.com/pypa/twine/pull/551
if sys.version_info[:2] <= (3, 8): # coverage: exclude
import importlib_metadata
else:
import importlib.metadata as importlib_metadata


def extract_metadata() -> Mapping[str, str]:
Expand Down
7 changes: 6 additions & 1 deletion procrastinate/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import pathlib
import sys

import importlib_resources
# https://github.com/pypa/twine/pull/551
if sys.version_info[:2] <= (3, 9): # coverage: exclude
import importlib_resources
else:
import importlib.resources as importlib_resources

from procrastinate import connector as connector_module

Expand Down
11 changes: 9 additions & 2 deletions procrastinate/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import re
import sys
from typing import Dict

from importlib_resources import read_text
# https://github.com/pypa/twine/pull/551
if sys.version_info[:2] <= (3, 9): # coverage: exclude
import importlib_resources
else:
import importlib.resources as importlib_resources

QUERIES_REGEX = re.compile(r"(?:\n|^)-- ([a-z0-9_]+) --\n(?:-- .+\n)*", re.MULTILINE)

Expand All @@ -21,7 +26,9 @@ def parse_query_file(query_file: str) -> Dict["str", "str"]:


def get_queries() -> Dict["str", "str"]:
return parse_query_file(read_text("procrastinate.sql", "queries.sql"))
return parse_query_file(
importlib_resources.read_text("procrastinate.sql", "queries.sql")
)


queries = get_queries()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ psycopg2-binary = "*"
python-dateutil = "*"
typing-extensions = "*"
importlib-metadata = {version = "*", python = "<3.8"}
importlib-resources = {version = "*", python = "<3.8"}
importlib-resources = {version = "*", python = "<3.9"}
Django = {version = ">=2.2", extras = ["django"]}

[tool.poetry.dev-dependencies]
Expand Down

0 comments on commit 5fb6f1b

Please sign in to comment.