Remove the "fix-branch-references" session ...

... and use relative links in the docs from now on.

Forgejo resolves relative links against the branch being viewed.
So, rewriting absolute links per branch is no longer necessary.
This commit is contained in:
Alexander Hess 2026-11-26 16:02:00 +01:00
commit ded4691177
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
4 changed files with 13 additions and 119 deletions

View file

@ -16,16 +16,16 @@ that iteratively build on each other.
### Data Cleaning
The UDP provided its raw data as a PostgreSQL dump.
This [notebook](https://code.webartifex.de/alexander/velofy/src/branch/develop/research/01_clean_data.ipynb)
This [notebook](research/01_clean_data.ipynb)
cleans the data extensively
and maps them onto the [ORM models](https://code.webartifex.de/alexander/velofy/src/branch/develop/src/velofy/db)
and maps them onto the [ORM models](src/velofy/db)
defined in the `velofy` package
that is developed in the [src/](https://code.webartifex.de/alexander/velofy/src/branch/develop/src) folder
that is developed in the [src/](src) folder
and contains all source code to drive the analyses.
Due to a non-disclosure agreement with the UDP,
neither the raw nor the cleaned data are published as of now.
However, previews of the data can be seen throughout the [research/](https://code.webartifex.de/alexander/velofy/src/branch/develop/research) folder.
However, previews of the data can be seen throughout the [research/](research) folder.
### Tactical Demand Forecasting
@ -34,9 +34,9 @@ Before any optimizations of the UDP's operations are done,
a **demand forecasting** system for *tactical* purposes is implemented.
To achieve that, the cities first undergo a **gridification** step
where each *pickup* location is assigned into a pixel on a "checker board"-like grid.
The main part of the source code that implements that is in this [file](https://code.webartifex.de/alexander/velofy/src/branch/develop/src/velofy/db/grids.py#L60).
Visualizations of the various grids can be found in the [visualizations/](https://code.webartifex.de/alexander/velofy/src/branch/develop/research/visualizations) folder
and in this [notebook](https://code.webartifex.de/alexander/velofy/src/branch/develop/research/03_grid_visualizations.ipynb).
The main part of the source code that implements that is in this [file](src/velofy/db/grids.py#L60).
Visualizations of the various grids can be found in the [visualizations/](research/visualizations) folder
and in this [notebook](research/03_grid_visualizations.ipynb).
Then, demand is aggregated on a per-pixel level
and different kinds of order time series are generated.
@ -47,7 +47,7 @@ The details of how this works can be found in the first academic paper
published in the context of this research project
and titled "*Real-time Demand Forecasting for an Urban Delivery Platform*"
(cf., the [repository](https://code.webartifex.de/alexander/velofy-forecasting) with the LaTeX files).
All demand forecasting related code is in the [forecasts/](https://code.webartifex.de/alexander/velofy/src/branch/develop/src/velofy/forecasts) sub-package.
All demand forecasting related code is in the [forecasts/](src/velofy/forecasts) sub-package.
### Predictive Routing
@ -71,11 +71,11 @@ and
`uv sync --extra research`
The `--extra` option is necessary as the non-develop dependencies
are structured in the [pyproject.toml](https://code.webartifex.de/alexander/velofy/src/branch/develop/pyproject.toml) file
are structured in the [pyproject.toml](pyproject.toml) file
into dependencies related to only the `velofy` source code package
and dependencies used to run the [Jupyter](https://jupyter.org/) environment
with the analyses.
Contributions are welcome.
Use the [issues](https://code.webartifex.de/alexander/velofy/issues) tab.
The project is licensed under the [MIT license](https://code.webartifex.de/alexander/velofy/src/branch/develop/LICENSE.txt).
The project is licensed under the [MIT license](LICENSE.txt).

View file

@ -28,15 +28,11 @@ as unified tasks to assure the quality of the source code:
"""
import collections
import contextlib
import glob
import os
import re
import shutil
import subprocess # noqa:S404
import tempfile
from collections.abc import Mapping
from typing import Any, Generator, IO, Tuple
from typing import Any, Generator
import nox
from nox.sessions import Session
@ -86,7 +82,6 @@ def load_supported_python_versions(*, reverse: bool = False) -> list[str]:
return sorted(version_names, key=pkg_version.Version, reverse=reverse)
FORGEJO_REPOSITORY = 'code.webartifex.de/alexander/velofy'
PACKAGE_IMPORT_NAME = 'velofy'
# Docs/sphinx locations.
@ -451,81 +446,6 @@ def create_develop_environment(session: Session) -> None:
)
@nox.session(name='fix-branch-references', python=MAIN_PYTHON, venv_backend='none')
def fix_branch_references(session): # noqa:WPS210
"""Replace branch references with the current branch.
Intended to be run as a pre-commit hook.
Many files in the project (e.g., README.md) contain links to resources
on Forgejo that contain branch labels.
This task rewrites these links such that they contain branch references
that make sense given the context:
- If the branch is only a temporary one that is to be merged into
the 'main' branch, all references are adjusted to 'main' as well.
- If the branch is not named after a default branch in the GitFlow
model, it is interpreted as a feature branch and the references
are adjusted into 'develop'.
This task may be called with one positional argument that is interpreted
as the branch to which all references are changed into.
The format must be "--branch=BRANCH_NAME".
"""
# Adjust this to add/remove glob patterns
# whose links are re-written.
paths = ['*.md', '**/*.md', '**/*.ipynb']
# Get the branch git is currently on.
# This is the branch to which all references are changed into
# if none of the two exceptions below apply.
branch = (
subprocess.check_output( # noqa:S603
('git', 'rev-parse', '--abbrev-ref', 'HEAD'),
)
.decode()
.strip()
)
# If the current branch is only a temporary one that is to be merged
# into 'main', we adjust all branch references to 'main' as well.
if branch.startswith('release') or branch.startswith('research'):
branch = 'main'
# If the current branch appears to be a feature branch, we adjust
# all branch references to 'develop'.
elif branch != 'main':
branch = 'develop'
# If a "--branch=BRANCH_NAME" argument is passed in
# as the only positional argument, we use BRANCH_NAME.
# Note: The --branch is required as session.posargs contains
# the staged files passed in by pre-commit in most cases.
if session.posargs and len(session.posargs) == 1:
match = re.match(
pattern=r'^--branch=([\w\.-]+)$',
string=session.posargs[0].strip(),
)
if match:
branch = match.groups()[0]
rewrites = [
{
'name': 'forgejo',
'pattern': re.compile(
fr'((https://{FORGEJO_REPOSITORY}/src/branch/)([\w\.-]+)/)',
),
'replacement': fr'\2{branch}/',
},
]
for expanded in _expand(*paths):
with _line_by_line_replace(expanded) as (old_file, new_file):
for line in old_file:
for rewrite in rewrites:
line = re.sub(rewrite['pattern'], rewrite['replacement'], line)
new_file.write(line)
def _expand(*patterns: str) -> Generator[str, None, None]:
"""Expand glob patterns into paths.
@ -539,32 +459,6 @@ def _expand(*patterns: str) -> Generator[str, None, None]:
yield from glob.glob(pattern.strip())
@contextlib.contextmanager
def _line_by_line_replace(path: str) -> Generator[Tuple[IO, IO], None, None]:
"""Replace/change the lines in a file one by one.
This generator function yields two file handles, one to the current file
(i.e., `old_file`) and one to its replacement (i.e., `new_file`).
Usage: loop over the lines in `old_file` and write the files to be kept
to `new_file`. Files not written to `new_file` are removed!
Args:
path: the file whose lines are to be replaced
Yields:
old_file, new_file: handles to a file and its replacement
"""
file_handle, new_file_path = tempfile.mkstemp()
with os.fdopen(file_handle, 'w') as new_file:
with open(path) as old_file:
yield old_file, new_file
shutil.copymode(path, new_file_path)
os.remove(path)
shutil.move(new_file_path, path)
@nox.session(name='init-project', python=MAIN_PYTHON, venv_backend='none')
def init_project(session):
"""Install the pre-commit hooks."""

View file

@ -19,7 +19,7 @@
"- numeric columns are checked for plausibility\n",
"- foreign key relationships are strictly enforced\n",
"\n",
"The structure of the data can be viewed at the [ORM layer](https://code.webartifex.de/alexander/velofy/src/branch/develop/src/velofy/db) in the package."
"The structure of the data can be viewed at the [ORM layer](../src/velofy/db) in the package."
]
},
{

View file

@ -621,7 +621,7 @@
"id": "fb6a035d",
"metadata": {},
"source": [
"In the application's code base, the above API calls and the related data are modeled as `Path` objects connecting two `Address` objects (cf. [Path class](https://code.webartifex.de/alexander/velofy/src/branch/develop/src/velofy/db/addresses_addresses.py) in the code).\n",
"In the application's code base, the above API calls and the related data are modeled as `Path` objects connecting two `Address` objects (cf. [Path class](../src/velofy/db/addresses_addresses.py) in the code).\n",
"\n",
"Let's look at two examples addresses, one from a `Restaurant` and one from a `Customer`."
]