Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
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/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ______________________________________________________________________
#### Is your feature request related to a problem?

Provide a description of what the problem is, e.g. "I wish I could use
pytask-environment to do \[...\]".
pytask-environment to do [...]".

#### Describe the solution you'd like

Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']

steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-tinytex@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: conda-forge
conda-remove-defaults: true

- name: Install core dependencies.
shell: bash -l {0}
Expand All @@ -42,6 +45,6 @@ jobs:
run: tox -e pytest -- tests -m end_to_end --cov=./ --cov-report=xml

- name: Upload coverage reports of end-to-end tests.
if: runner.os == 'Linux' && matrix.python-version == '3.9'
if: runner.os == 'Linux' && matrix.python-version == '3.11'
shell: bash -l {0}
run: bash <(curl -s https://codecov.io/bash) -F end_to_end -c
31 changes: 13 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=100']
Expand All @@ -25,35 +25,30 @@ repos:
- id: python-no-log-warn
- id: python-use-type-annotations
- id: text-unicode-replacement-char
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: reorder-python-imports
args: [--py37-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.1.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.244
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.2
hooks:
- id: ruff
- repo: https://github.com/dosisod/refurb
rev: v1.12.0
rev: v2.3.0
hooks:
- id: refurb
args: [--ignore, FURB126]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.2.0
rev: v3.2.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/econchick/interrogate
rev: 1.5.0
rev: 1.7.0
hooks:
- id: interrogate
args: [-v, --fail-under=40, src, tests]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 1.0.0
hooks:
- id: mdformat
additional_dependencies: [
Expand All @@ -62,13 +57,13 @@ repos:
]
args: [--wrap, "88"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.4.1
hooks:
- id: codespell
args: [-L als, -L unparseable]
additional_dependencies: ["tomli"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.0.0'
rev: 'v1.19.1'
hooks:
- id: mypy
args: [
Expand All @@ -82,11 +77,11 @@ repos:
]
pass_filenames: false
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
rev: "0.51"
hooks:
- id: check-manifest
args: [--no-build-isolation]
additional_dependencies: [setuptools-scm, toml]
additional_dependencies: [setuptools-scm, toml, wheel]
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ url = https://github.com/pytask-dev/pytask-environment
author = Tobias Raabe
author_email = raabe@posteo.de
license = MIT
license_file = LICENSE
license_files = LICENSE
platforms = any
classifiers =
Development Status :: 4 - Beta
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Expand All @@ -24,10 +23,10 @@ project_urls =
[options]
packages = find:
install_requires =
click
click<8.2
pony
pytask>=0.2
python_requires = >=3.7
pytask>=0.3,<0.4
python_requires = >=3.10
include_package_data = True
package_dir = =src
zip_safe = False
Expand Down
1 change: 1 addition & 0 deletions src/pytask_environment/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains everything related to the configuration."""

from __future__ import annotations

from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion src/pytask_environment/database.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""This module contains everything related to the database."""

from __future__ import annotations

from pony import orm


# Can be removed with pytask v0.4.
try:
from pytask import db
Expand Down
2 changes: 1 addition & 1 deletion src/pytask_environment/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains everything related to logging."""

from __future__ import annotations

import sys
Expand All @@ -9,7 +10,6 @@
from pytask import Session
from pytask_environment.database import Environment


_ERROR_MSG = """\
Aborted execution due to a bad state of the environment. Either switch to the correct \
environment or update the information on the environment using the --update-environment\
Expand Down
1 change: 1 addition & 0 deletions src/pytask_environment/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Entry-point for the plugin."""

from __future__ import annotations

from pluggy import PluginManager
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from click.testing import CliRunner


@pytest.fixture()
@pytest.fixture
def runner():
return CliRunner()
46 changes: 22 additions & 24 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
from _pytask.database_utils import db


@pytest.mark.end_to_end()
def _clear_database() -> None:
"""Delete records without using generator decompilation in Pony ORM."""
for entity in db.entities.values():
for record in entity.select():
record.delete()


_FAKE_CPYTHON_VERSION = "2.7.18 (main, Jul 31 2020, 01:53:57) [Clang 14.0.0]"


@pytest.mark.end_to_end
def test_existence_of_python_executable_in_db(tmp_path, runner):
"""Test that the Python executable is stored in the database."""
task_path = tmp_path.joinpath("task_dummy.py")
Expand All @@ -34,11 +44,10 @@ def test_existence_of_python_executable_in_db(tmp_path, runner):
assert python.path == sys.executable

orm.rollback()
for entity in db.entities.values():
orm.delete(e for e in entity)
_clear_database()


@pytest.mark.end_to_end()
@pytest.mark.end_to_end
def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
"""Test the whole use-case.

Expand All @@ -51,10 +60,6 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
"""
real_python_version = sys.version
real_python_executable = sys.executable
fake_version = (
"2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) "
"[MSC v.1916 64 bit (AMD64)]"
)

tmp_path.joinpath("pyproject.toml").write_text("[tool.pytask.ini_options]")
source = "def task_dummy(): pass"
Expand All @@ -67,7 +72,7 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
assert "Updating the information" in result.output

# Run with a fake version and not updating the environment.
monkeypatch.setattr("pytask_environment.logging.sys.version", fake_version)
monkeypatch.setattr("pytask_environment.logging.sys.version", _FAKE_CPYTHON_VERSION)

result = runner.invoke(cli)
assert result.exit_code == ExitCode.FAILED
Expand All @@ -79,7 +84,7 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
assert python.path == real_python_executable

# Run with a fake version and updating the environment.
monkeypatch.setattr("pytask_environment.logging.sys.version", fake_version)
monkeypatch.setattr("pytask_environment.logging.sys.version", _FAKE_CPYTHON_VERSION)
monkeypatch.setattr("pytask_environment.logging.sys.executable", "new_path")

result = runner.invoke(cli, ["--update-environment", tmp_path.as_posix()])
Expand All @@ -88,25 +93,20 @@ def test_flow_when_python_version_has_changed(monkeypatch, tmp_path, runner):
with orm.db_session:
python = Environment["python"]

assert python.version == fake_version
assert python.version == _FAKE_CPYTHON_VERSION
assert python.path == "new_path"

orm.rollback()
for entity in db.entities.values():
orm.delete(e for e in entity)
_clear_database()


@pytest.mark.end_to_end()
@pytest.mark.end_to_end
@pytest.mark.parametrize(
("check_python_version", "expected"), [("true", 1), ("false", 0)]
)
def test_python_version_changed(
monkeypatch, tmp_path, runner, check_python_version, expected
):
fake_version = (
"2.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) "
"[MSC v.1916 64 bit (AMD64)]"
)
tmp_path.joinpath("pyproject.toml").write_text(
f"[tool.pytask.ini_options]\ncheck_python_version = {check_python_version}"
)
Expand All @@ -120,18 +120,17 @@ def test_python_version_changed(
assert "Updating the information" in result.output

# Run with a fake version and not updating the environment.
monkeypatch.setattr("pytask_environment.logging.sys.version", fake_version)
monkeypatch.setattr("pytask_environment.logging.sys.version", _FAKE_CPYTHON_VERSION)

result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == expected

with orm.db_session:
orm.rollback()
for entity in db.entities.values():
orm.delete(e for e in entity)
_clear_database()


@pytest.mark.end_to_end()
@pytest.mark.end_to_end
@pytest.mark.parametrize(
("check_python_version", "expected"), [("true", 1), ("false", 0)]
)
Expand All @@ -158,5 +157,4 @@ def test_environment_changed(

with orm.db_session:
orm.rollback()
for entity in db.entities.values():
orm.delete(e for e in entity)
_clear_database()
Loading