Skip to content

Commit cce344a

Browse files
authored
Enable python 3.12 (#30)
* enable python 3.12 * fix pre-commit * update changelog
1 parent b9af7b2 commit cce344a

11 files changed

Lines changed: 88 additions & 114 deletions

File tree

.github/workflows/actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
strategy:
3939
matrix:
4040
os: ["ubuntu-latest"]
41-
version: ["3.9", "3.10", "3.11"]
41+
version: ["3.9", "3.10", "3.11", "3.12"]
4242
steps:
4343
- name: Checkout 🔖
4444
uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: python3
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
5+
rev: v4.6.0
66
hooks:
77
- id: check-added-large-files
88
- id: check-ast
@@ -12,29 +12,19 @@ repos:
1212
- id: check-json
1313
- id: check-toml
1414
- id: check-yaml
15-
exclude: mkdocs.yml
16-
- repo: https://github.com/psf/black
17-
rev: 23.1.0
18-
hooks:
19-
- id: black
20-
exclude: test/data/schema/wrong_syntax.py
2115
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v1.0.0
16+
rev: v1.15.0
2317
hooks:
2418
- id: mypy
2519
exclude: test/data/schema/wrong_syntax.py
2620
- repo: https://github.com/dosisod/refurb
27-
rev: v1.11.1
21+
rev: v2.0.0
2822
hooks:
2923
- id: refurb
3024
exclude: test/data/schema/wrong_syntax.py
31-
- repo: https://github.com/charliermarsh/ruff-pre-commit
32-
rev: 'v0.0.247'
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
rev: v0.11.4
3327
hooks:
3428
- id: ruff
3529
args: [--fix, --exit-non-zero-on-fix]
36-
- repo: https://github.com/tcort/markdown-link-check
37-
rev: 'v3.11.2'
38-
hooks:
39-
- id: markdown-link-check
40-
args: [-q]
30+
exclude: test/data/schema/wrong_syntax.py

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ While in this phase, we will denote breaking changes with a minor increase.
1212

1313
## 0.4.3
1414

15-
### Fixed
15+
### Added
16+
17+
* Added support for python `3.12`
18+
19+
### Changed
1620

1721
* Bump all dependencies to the latest version and introduce necessary adaptation in the source code (affecting only `dac info`):
1822
- `build~=0.9` -> `build==1.2.2`
1923
- `toml~=0.10` -> `toml==0.10.2`
2024
- `typer[all]~=0.7` -> `typer[all]==0.15.2`
2125
- `wheel~=0.38` -> `wheel==0.45.1`
22-
* Prevent installation with python > `3.11`
26+
* Prevent installation with python > `3.12`
2327

2428
## 0.4.2
2529

mkdocs.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "dac"
33
dynamic = ["version"]
44
description = "Tool to distribute data as code"
55
readme = "README.md"
6-
requires-python = ">=3.9,<3.12"
6+
requires-python = ">=3.9,<3.13"
77
license = { text = "MIT" }
88
authors = [
99
{ name = "Francesco Calcavecchia", email = "francesco.calcavecchia@gmail.com" },

requirements-docs.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/dac/_input/pyproject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def generate_pyproject_toml(self) -> str:
3131
def _get_list_of_project_dependencies(self) -> List[str]:
3232
splitted_by_newline = self.project_dependencies.splitlines()
3333
splitted_by_newline_or_comma = [s for ss in splitted_by_newline for s in ss.split(";")]
34-
return sorted(map(lambda x: x.strip(), splitted_by_newline_or_comma))
34+
return sorted(map(str.strip, splitted_by_newline_or_comma))

src/dac/_version_management.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,60 @@
1+
import tempfile
12
import re
23
import subprocess
34
from typing import Optional
5+
from pathlib import Path
46

57

68
def find_latest_version(pkg_name: str, major: Optional[int] = None) -> str:
7-
output = subprocess.check_output(
8-
[
9-
"pip",
10-
"install",
11-
"--no-deps",
12-
"--ignore-installed",
13-
"--no-cache-dir",
14-
"--dry-run",
15-
f"{pkg_name}{f'=={major}.*' if major is not None else ''}",
16-
],
17-
stderr=subprocess.DEVNULL,
9+
pip_log = _pretend_pip_install(pkg_name=pkg_name, major=major)
10+
would_install_line = _extract_would_install_line(pip_log=pip_log)
11+
package_with_version = _extract_package_with_version(
12+
pip_log_would_install_line=would_install_line, pkg_name=pkg_name, major=major
1813
)
19-
output_lines = output.decode("utf-8").splitlines()
20-
would_install_line = [line for line in output_lines if "Would install" in line][0]
21-
regex_rule = f"{pkg_name.replace('_', '-')}-{major if major is not None else ''}.[^ ]+"
22-
match = re.search(regex_rule, would_install_line.replace("_", "-"))
23-
assert match is not None
24-
return match[0][len(f"{pkg_name}-") :]
14+
return package_with_version[len(f"{pkg_name}-") :]
2515

2616

2717
def increase_minor(version: str) -> str:
2818
major, minor, patch = version.split(".")
2919
assert major.isdigit() and minor.isdigit()
3020
return f"{major}.{int(minor) + 1}.0"
21+
22+
23+
def _pretend_pip_install(pkg_name: str, major: Optional[int]) -> str:
24+
with tempfile.NamedTemporaryFile() as log_file:
25+
result = subprocess.run(
26+
[
27+
"pip",
28+
"install",
29+
"--no-deps",
30+
"--ignore-installed",
31+
"--dry-run",
32+
f"--log={log_file.name}",
33+
f"{pkg_name}{f'=={major}.*' if major is not None else ''}",
34+
],
35+
stdout=subprocess.PIPE,
36+
stderr=subprocess.PIPE,
37+
text=True,
38+
)
39+
if result.returncode != 0:
40+
raise subprocess.SubprocessError(
41+
f"Something went wrong while using pip to find the version of {pkg_name}{f'(major version {major})' if major else ''}.\n\nSTDOUT: {result.stdout}\n\nSTDERR: {result.stderr}"
42+
)
43+
return Path(log_file.name).read_text()
44+
45+
46+
def _extract_would_install_line(pip_log: str) -> str:
47+
would_install_lines = [line for line in pip_log.splitlines() if "Would install" in line]
48+
assert (
49+
len(would_install_lines) == 1
50+
), f"Expected exactly one line containing 'Would install' in the pip log generated by pip installing the requested package, but found {len(would_install_lines)} lines."
51+
return would_install_lines[0]
52+
53+
54+
def _extract_package_with_version(pip_log_would_install_line: str, pkg_name: str, major: Optional[int]) -> str:
55+
regex_rule = f"{pkg_name.replace('_', '-')}-{major if major is not None else ''}.[^ ]+"
56+
match = re.search(regex_rule, pip_log_would_install_line.replace("_", "-"))
57+
assert (
58+
match is not None and match[0] != ""
59+
), f"It was not possible to determine the version, because we could not find a match to the regex {regex_rule} in {pip_log_would_install_line.replace('_', '-')}"
60+
return match[0]

test/integration_test/version_management_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_if_find_latest_version_is_called_then_return_latest_version():
99

1010

1111
def test_if_find_latest_version_is_called_with_major_constraint_then_return_latest_major_version():
12-
assert "0.25.3" == find_latest_version(pkg_name="pandas", major=0)
12+
assert "1.5.3" == find_latest_version(pkg_name="pandas", major=1)
1313

1414

1515
def test_if_pkg_does_not_exist_then_find_package_raises_exception():
@@ -23,5 +23,5 @@ def test_if_next_version_without_major_spec_then_return_latest_version_with_mino
2323

2424

2525
def test_if_next_version_with_major_spec_then_return_minor_upgrade_for_that_major():
26-
result = invoke_dac_next_version(pkg_name="pandas", major=0)
27-
assert result.stdout == "0.26.0\n"
26+
result = invoke_dac_next_version(pkg_name="pandas", major=1)
27+
assert result.stdout == "1.6.0\n"

test/unit_test/_packing/data_as_code_project_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_if_project_init_is_inspected_then_load_and_schema_is_found():
3232
def test_if_project_load_is_inspected_then_has_same_content_as_original():
3333
with input_with_self_contained_data() as config:
3434
with data_as_code_project(config=config) as proj_dir:
35-
project_load_path = proj_dir / "src" / config.pyproject.project_name / f"{DaCProjectFactory.load_file_name}"
35+
project_load_path = proj_dir / "src" / config.pyproject.project_name / str(DaCProjectFactory.load_file_name)
3636
assert project_load_path.exists()
3737
assert filecmp.cmp(config.load_path, project_load_path)
3838

@@ -41,7 +41,7 @@ def test_if_project_schema_is_inspected_then_has_same_content_as_original():
4141
with input_with_self_contained_data() as config:
4242
with data_as_code_project(config=config) as proj_dir:
4343
project_schema_path = (
44-
proj_dir / "src" / config.pyproject.project_name / f"{DaCProjectFactory.schema_file_name}"
44+
proj_dir / "src" / config.pyproject.project_name / str(DaCProjectFactory.schema_file_name)
4545
)
4646
assert project_schema_path.exists()
4747
assert filecmp.cmp(config.schema_path, project_schema_path)

0 commit comments

Comments
 (0)