diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 257c21a1..7ff821eb 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -17,7 +17,7 @@ RUN useradd -m dev && chown -R dev:dev /workspaces/dfetch USER dev ENV PATH="/home/dev/.local/bin:${PATH}" -ENV PYTHONPATH="/home/dev/.local/lib/python3.12" +ENV PYTHONPATH="/home/dev/.local/lib/python3.13" ENV PYTHONUSERBASE="/home/dev/.local" COPY --chown=dev:dev . . diff --git a/.readthedocs.yml b/.readthedocs.yml index 94f076cb..39519437 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -16,7 +16,7 @@ formats: build: os: ubuntu-22.04 tools: - python: "3.12" + python: "3.13" # Optionally set the version of Python and requirements required to build your docs python: diff --git a/doc/contributing.rst b/doc/contributing.rst index 4c9ce219..bdb601c7 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -10,16 +10,16 @@ After implementing (with tests and documentation) create a PR on Github and let Virtual Environment ------------------- -Create a virtual environment by double-clicking ``create_venv.py`` or by running the following command. -This will install all ``development``, ``test`` and ``doc`` dependencies from ``pyproject.toml``, install +Create a virtual environment by double-clicking ``script/create_venv.py`` or by running the following command. +This will install all ``development``, ``test`` and ``docs`` dependencies from ``pyproject.toml``, install *DFetch* as `editable package `_ and install all runtime dependencies from ``pyproject.toml``. .. code-block:: bash - python create_venv.py + script/create_venv.py -.. important :: *dfetch* is primarily developed with python 3.12 +.. important :: *dfetch* is primarily developed with python 3.13 Running in Github Codespaces ---------------------------- @@ -49,7 +49,7 @@ To avoid any discussion about formatting `black `_ Next to that `isort `_ is used for sorting the imports. And `doc8 `_ is used as rst linter. -Run `check_quality.bat` (or GitHub will run it for you). Alternatively when using VSCode run the `Check Quality` task from the command palette. +Run ``script/check_quality.bat`` (or GitHub will run it for you). Alternatively when using VSCode run the `Check Quality` task from the command palette. Testing ------- @@ -88,7 +88,7 @@ and add run the ``Feature tests (wip)`` debug configuration in VSCode. Creating documentation ---------------------- -Run ``create_docs.bat`` and open ``index.html`` in ``doc/_build/html`` to read it. +Run ``script/create_docs.bat`` and open ``index.html`` in ``doc/_build/html`` to read it. See `This example `_ for documenting the code. Alternatively in VSCode run the ``Create Docs`` task from the command palette. diff --git a/check_quality.bat b/script/check_quality.bat similarity index 67% rename from check_quality.bat rename to script/check_quality.bat index a9de4fb1..47d0369f 100644 --- a/check_quality.bat +++ b/script/check_quality.bat @@ -3,10 +3,10 @@ setlocal enabledelayedexpansion cd %~dp0 -python create_venv.py --extra_requirements "development" +py create_venv.py --extra_requirements "development" if not !ERRORLEVEL! == 0 echo "Something went wrong creating the venv." && exit /b !ERRORLEVEL! -call .\venv\Scripts\activate.bat +call ..\venv\Scripts\activate.bat pre-commit run pause diff --git a/create_docs.bat b/script/create_docs.bat similarity index 59% rename from create_docs.bat rename to script/create_docs.bat index 2094df8e..238468eb 100644 --- a/create_docs.bat +++ b/script/create_docs.bat @@ -3,8 +3,8 @@ setlocal enabledelayedexpansion cd %~dp0 -python create_venv.py --extra_requirements "docs" +py create_venv.py --extra_requirements "docs" if not !ERRORLEVEL! == 0 echo "Something went wrong creating the venv." && exit /b !ERRORLEVEL! -call .\venv\Scripts\activate.bat -.\doc\make.bat html +call ..\venv\Scripts\activate.bat +..\doc\make.bat html diff --git a/create_venv.py b/script/create_venv.py old mode 100644 new mode 100755 similarity index 61% rename from create_venv.py rename to script/create_venv.py index e94d0b41..3169bb6f --- a/create_venv.py +++ b/script/create_venv.py @@ -1,18 +1,23 @@ -#!python3.12 +#!/usr/bin/env python3 """Script to setup a venv.""" import argparse +import pathlib import subprocess # nosec +import sys import venv from typing import Any +PROJECT_ROOT = pathlib.Path(__file__).resolve().parent.parent + +MIN_VERSION = (3, 9) # minimum supported; change if needed +RECOMMENDED_VERSION = (3, 13) # preferred for development + class MyEnvBuilder(venv.EnvBuilder): """Create a virtual environment. - Conditions for use: - + A `requirements.txt` file must exist - By default this is relative to the current run path, but this can be specified programmatically. + Optionally install extra requirements from pyproject.toml. """ def __init__( @@ -34,7 +39,9 @@ def post_setup(self, context: Any) -> None: print("Upgrading pip") self.pip_install(context, "--upgrade", "pip") print("Installing package and any extra requirements") - self.pip_install(context, "--use-pep517", "-e", f".{self.extra_requirements}") + self.pip_install( + context, "--use-pep517", "-e", f"{PROJECT_ROOT!s}{self.extra_requirements}" + ) @staticmethod def pip_install(context: Any, *args: Any) -> None: @@ -54,12 +61,25 @@ def pip_install(context: Any, *args: Any) -> None: if __name__ == "__main__": PARSER = argparse.ArgumentParser() PARSER.add_argument( - "-e", "--extra_requirements", type=str, default="development,test,doc" + "-e", "--extra_requirements", type=str, default="development,test,docs" ) ARGS = PARSER.parse_args() + CURRENT_VERSION = sys.version_info[:2] + + if CURRENT_VERSION < MIN_VERSION: + raise RuntimeError( + f"⚠ Unsupported Python version {sys.version_info.major}.{sys.version_info.minor}. " + f"Please use Python {MIN_VERSION[0]}.{MIN_VERSION[1]} or newer." + ) + if CURRENT_VERSION != RECOMMENDED_VERSION: + print( + f"⚠ Warning: Running with Python {sys.version_info.major}.{sys.version_info.minor}, " + f"dfetch is primarily developed with Python {RECOMMENDED_VERSION[0]}.{RECOMMENDED_VERSION[1]}." + ) + MyEnvBuilder( clear=False, with_pip=True, extra_requirements=ARGS.extra_requirements, - ).create("venv") + ).create(str(PROJECT_ROOT / "venv")) diff --git a/tests/run_tests.bat b/tests/run_tests.bat index 2adce558..bf5afa6d 100644 --- a/tests/run_tests.bat +++ b/tests/run_tests.bat @@ -3,7 +3,7 @@ setlocal enabledelayedexpansion cd %~dp0.. -python create_venv.py --extra_requirements "test" +py script/create_venv.py --extra_requirements "test" if not !ERRORLEVEL! == 0 echo "Something went wrong creating the venv." && exit /b !ERRORLEVEL! call .\venv\Scripts\activate.bat