Skip to content

Commit

Permalink
Allow using python 3.8 (#25)
Browse files Browse the repository at this point in the history
* Allow using python 3.8

* Fix formatting

* Fix adding decorators

* Add python 3.8 to CI

* Remove unused function

* Adjust CHANGELOG
  • Loading branch information
DriesSchaumont authored Jul 29, 2024
1 parent dbba2ae commit 913b7ae
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
11 changes: 8 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
Changelog
*********

0.8.0 (TBD)
===========
0.8.0 (29/07/2024)
==================

New Functionality
-----------------

* Re-enabled support for python 3.8 (#25).

0.7.0 (22/04/2023)
0.7.0 (22/04/2024)
==================

New Functionality
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ classifiers =
License :: OSI Approved :: GNU General Public License v3 (GPLv3)

[options]
python_requires = >=3.9
python_requires = >=3.8
setup_requires =
setuptools-scm
setuptools_scm_git_archive
Expand Down
37 changes: 30 additions & 7 deletions tests/unittests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from textwrap import dedent
from pathlib import Path
import tarfile
from itertools import islice


@pytest.fixture
def makepyfile_and_add_meta(pytester, write_config):

def wrapper(
test_module_contents,
viash_config,
Expand Down Expand Up @@ -50,16 +52,37 @@ def wrapper(
meta["{memory_specifier}"] = {memory_value}
"""
)

new_contents = []
# Parse the contents of the original test module and the meta fields to insert into it
parsed_to_insert = ast.parse(to_insert)
parsed_module_contents = ast.parse(dedent(test_module_contents))
i = 0
for i, elem in enumerate(parsed_module_contents.body):
if isinstance(elem, (ast.Import, ast.ImportFrom)):
test_module_contents_modified = dedent(test_module_contents).strip("\n")
parsed_module_contents = ast.parse(test_module_contents_modified)
# First parse the imports from the test module, and add the meta fields after those
for i, node in enumerate(ast.iter_child_nodes(parsed_module_contents)):
if isinstance(node, (ast.Import, ast.ImportFrom)):
# Keep the imports
new_contents.append(
dedent(ast.get_source_segment(test_module_contents_modified, node))
)
continue
break
parsed_module_contents.body.insert(i, parsed_to_insert)
pytester.makepyfile(ast.unparse(parsed_module_contents))
# Add the meta field
for node in ast.iter_child_nodes(parsed_to_insert):
new_contents.append(ast.get_source_segment(to_insert, node))
# Now add the rest of the original test module
for node in islice(ast.iter_child_nodes(parsed_module_contents), i, None):
try:
decorators = node.decorator_list
except AttributeError:
decorators = []
for decorator in decorators:
new_contents.append(
f"@{ast.get_source_segment(test_module_contents_modified, decorator)}"
)
new_contents.append(
ast.get_source_segment(test_module_contents_modified, node)
)
pytester.makepyfile("\n".join(new_contents))
return config_file

return wrapper
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For more information about tox, see https://tox.readthedocs.io/en/latest/
[tox]
envlist =
py{39}-pytest{62}
py{38,39}-pytest{62}
py{39,310,311,312}-pytest{70,71,72,73,74,80,81}
flake8
isolated_build = True
Expand Down

0 comments on commit 913b7ae

Please sign in to comment.