Skip to content
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

Add support for Python 3.12 #90

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false

env:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Skeem changelog

in progress
===========
- Added support for Python 3.12


2023-03-09 0.1.0
Expand Down
3 changes: 3 additions & 0 deletions skeem/frictionless/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .loader_stream import read_byte_stream_create
from .pandas_plugin import create_parser
from .parser_jsonl import read_cell_stream_create
from .parser_xlsx import read_loader
from .resource import ResourcePlus


Expand All @@ -28,6 +29,7 @@ def patch_modules():
- Don't croak when reading streams without `name` attribute.
"""

import frictionless.formats.excel.parsers
import frictionless.formats.json.parsers
import frictionless.formats.pandas.plugin
import frictionless.schemes.aws.loaders.s3
Expand All @@ -37,3 +39,4 @@ def patch_modules():
frictionless.formats.pandas.plugin.PandasPlugin.create_parser = create_parser
frictionless.schemes.aws.loaders.s3.S3Loader.read_byte_stream_create = s3_read_byte_stream_create
frictionless.schemes.stream.loader.StreamLoader.read_byte_stream_create = read_byte_stream_create
frictionless.formats.excel.parsers.XlsxParser.read_loader = read_loader
52 changes: 52 additions & 0 deletions skeem/frictionless/parser_xlsx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import atexit
import os
import shutil
import tempfile

from frictionless.formats.excel.control import ExcelControl
from frictionless.resource.resource import Resource
from frictionless.system import system


def read_loader(self):
"""
Patched for Python 3.12.

https://github.com/frictionlessdata/frictionless-py/issues/1642
https://github.com/frictionlessdata/frictionless-py/pull/1684
"""
control = ExcelControl.from_dialect(self.resource.dialect)
loader = system.create_loader(self.resource)
if not loader.remote:
return loader.open()

# Remote
# Create copy for remote source
# For remote stream we need local copy (will be deleted on close by Python)
# https://docs.python.org/3.5/library/tempfile.html#tempfile.TemporaryFile
if loader.remote:
path = self.resource.normpath

# Cached
if control.workbook_cache is not None and path in control.workbook_cache:
# TODO: rebase on using resource without system?
resource = Resource(path, scheme="file", format="xlsx")
resource.infer(sample=False)
loader = system.create_loader(resource)
return loader.open()

Check warning on line 36 in skeem/frictionless/parser_xlsx.py

View check run for this annotation

Codecov / codecov/patch

skeem/frictionless/parser_xlsx.py#L33-L36

Added lines #L33 - L36 were not covered by tests

with loader as loader:
delete = control.workbook_cache is None
target = tempfile.NamedTemporaryFile(delete=delete)
shutil.copyfileobj(loader.byte_stream, target)
target.seek(0)
if not delete:
control.workbook_cache[path] = target.name # type: ignore
atexit.register(os.remove, target.name)

Check warning on line 45 in skeem/frictionless/parser_xlsx.py

View check run for this annotation

Codecov / codecov/patch

skeem/frictionless/parser_xlsx.py#L44-L45

Added lines #L44 - L45 were not covered by tests
# TODO: rebase on using resource without system?
resource = Resource(target, scheme="stream", format="xlsx")
resource.infer(sample=False)
loader = system.create_loader(resource)
return loader.open()

return None

Check warning on line 52 in skeem/frictionless/parser_xlsx.py

View check run for this annotation

Codecov / codecov/patch

skeem/frictionless/parser_xlsx.py#L52

Added line #L52 was not covered by tests
Loading