Skip to content
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 .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ formats:
build:
os: ubuntu-22.04
tools:
python: "3.12"
python: "3.13"
Comment thread
spoorcc marked this conversation as resolved.

# Optionally set the version of Python and requirements required to build your docs
python:
Expand Down
12 changes: 6 additions & 6 deletions doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pip.pypa.io/en/stable/cli/pip_wheel/?highlight=editable#cmdoption-e>`_
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
----------------------------
Expand Down Expand Up @@ -49,7 +49,7 @@ To avoid any discussion about formatting `black <https://github.com/psf/black>`_
Next to that `isort <https://github.com/PyCQA/isort>`_ is used for sorting the imports.
And `doc8 <https://github.com/pycqa/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
-------
Expand Down Expand Up @@ -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 <https://pythonhosted.org/an_example_pypi_project/sphinx.html>`_ for documenting the code.
Alternatively in VSCode run the ``Create Docs`` task from the command palette.

Expand Down
4 changes: 2 additions & 2 deletions check_quality.bat → script/check_quality.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions create_docs.bat → script/create_docs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 27 additions & 7 deletions create_venv.py → script/create_venv.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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__(
Expand All @@ -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:
Expand All @@ -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"))
2 changes: 1 addition & 1 deletion tests/run_tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading