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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
exclude_types: [javascript,json]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.22
rev: v0.16.0
hooks:
- id: ruff-check
args: [--fix]
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import date
from datetime import UTC, datetime

project = "git2cpp"
author = "QuantStack"
copyright = f"2025-{date.today().year}"
copyright = f"2025-{datetime.now(UTC).year}"

extensions = [
"myst_parser",
Expand Down
2 changes: 1 addition & 1 deletion docs/create_markdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from pathlib import Path
import re
import subprocess
from pathlib import Path


def get_filename(args):
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.format]
line-ending = "lf"

[tool.ruff.lint]
ignore = [
"PLW1510"
]
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
GIT2CPP_TEST_WASM = os.getenv("GIT2CPP_TEST_WASM") == "1"

if GIT2CPP_TEST_WASM:
from .conftest_wasm import * # noqa: F403
from .conftest_wasm import *


# Fixture to run test in current tmp_path
Expand Down
15 changes: 7 additions & 8 deletions test/conftest_wasm.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Extra fixtures used for wasm testing, including some that override the default pytest fixtures.
from functools import partial
import os
import pathlib
from playwright.sync_api import Page
import pytest
import re
import subprocess
import time
from functools import partial

import pytest
from playwright.sync_api import Page


# Only include particular test files when testing wasm.
Expand Down Expand Up @@ -94,14 +95,13 @@ def read_bytes(self) -> bytes:
def read_text(self) -> str:
p = subprocess.run(["cat", str(self)], capture_output=True, text=True, check=True)
text = p.stdout
if text.endswith("\n"):
text = text[:-1]
text = text.removesuffix("\n")
return text

def write_bytes(self, data: bytes):
# Convert binary data to a string where each element is backslash-escaped so that we can
# write to file in cockle using `echo -e <backslash-escaped data>`.
encoded_string = "".join(map(lambda d: f"\\x{d:02x}", data))
encoded_string = "".join(f"\\x{d:02x}" for d in data)
cmd = ["echo", "-e", encoded_string, ">", str(self)]
subprocess.run(cmd, capture_output=True, text=True, check=True)
return len(data)
Expand All @@ -110,8 +110,7 @@ def write_text(self, data: str):
# Note that in general it is not valid to direct output of a subprocess.run call to a file,
# but we get away with it here as the command arguments are passed straight through to
# cockle without being checked.
if data.endswith("\n"):
data = data[:-1]
data = data.removesuffix("\n")
cmd = ["echo", data, ">", str(self)]
subprocess.run(cmd, capture_output=True, text=True, check=True)
return len(data)
Expand Down
6 changes: 4 additions & 2 deletions test/test_clone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import subprocess

import pytest

from .conftest import GIT2CPP_TEST_WASM

xtl_url = "https://github.com/xtensor-stack/xtl.git"
Expand Down Expand Up @@ -77,7 +79,7 @@ def test_clone_private_repo_fails_then_succeeds(
# Fails with wrong credentials, then succeeds with correct ones.
username = "xyz" # Can be any non-empty string.
password = private_test_repo["token"]
input = "\n".join(["wrong1", "wrong2", username, password]) + "\n"
input = f"wrong1\nwrong2\n{username}\n{password}"
repo_path = tmp_path / private_test_repo["repo_name"]

clone_cmd = [git2cpp_path, "clone", private_test_repo["https_url"]]
Expand Down
1 change: 1 addition & 0 deletions test/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re
import subprocess

from .conftest import GIT2CPP_TEST_WASM


Expand Down
4 changes: 3 additions & 1 deletion test/test_git.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import re
import subprocess

import pytest

from .conftest import GIT2CPP_TEST_WASM


Expand Down
8 changes: 4 additions & 4 deletions test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_init_in_directory(git2cpp_path, tmp_path):
assert p.stdout.startswith("Initialized empty Git repository in ")
assert p.stdout.strip().endswith("/")

assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [
assert sorted(path.name for path in tmp_path.iterdir()) == [
"HEAD",
"config",
"description",
Expand All @@ -36,7 +36,7 @@ def test_init_in_cwd(git2cpp_path, tmp_path, run_in_tmp_path):
assert p.stdout.startswith("Initialized empty Git repository in ")
assert p.stdout.strip().endswith("/")

assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [
assert sorted(path.name for path in tmp_path.iterdir()) == [
"HEAD",
"config",
"description",
Expand All @@ -60,9 +60,9 @@ def test_init_not_bare(git2cpp_path, tmp_path):
assert p.stdout.strip().endswith(".git/")

# Directory contains just .git directory.
assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == [".git"]
assert sorted(path.name for path in tmp_path.iterdir()) == [".git"]
# .git directory is a valid repo.
assert sorted(map(lambda path: path.name, (tmp_path / ".git").iterdir())) == [
assert sorted(path.name for path in (tmp_path / ".git").iterdir()) == [
"HEAD",
"config",
"description",
Expand Down
2 changes: 1 addition & 1 deletion test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_log_commit_without_references(commit_env_config, git2cpp_path, tmp_path

# First commit line should have references
lines = strip_ansi_colours(p_log.stdout).split("\n")
first_commit_line = [line for line in lines if line.startswith("commit")][0]
first_commit_line = next(line for line in lines if line.startswith("commit"))
assert "(" in first_commit_line # Has references

# Second commit (older one) should not have empty parentheses
Expand Down
4 changes: 2 additions & 2 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def repo_with_remote(git2cpp_path, tmp_path, run_in_tmp_path):

def test_fetch_from_remote(git2cpp_path, repo_with_remote):
"""Test fetching from a remote."""
local_path, remote_path = repo_with_remote
local_path, _remote_path = repo_with_remote

# Note: This is a bare repo with no refs, so fetch will fail gracefully
# For now, just test that /stdofetch command runs (it will fail gracefully if no refs)
Expand All @@ -309,7 +309,7 @@ def test_fetch_from_remote(git2cpp_path, repo_with_remote):

def test_fetch_default_origin(git2cpp_path, repo_with_remote):
"""Test fetching with default origin."""
local_path, remote_path = repo_with_remote
local_path, _remote_path = repo_with_remote

cmd = [git2cpp_path, "fetch"]
p = subprocess.run(cmd, capture_output=True, text=True, cwd=local_path)
Expand Down
9 changes: 5 additions & 4 deletions wasm/recipe/modify-recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# This can be called repeatedly and will produce the same output.

import argparse
from pathlib import Path
import shutil
import yaml
import sys
from pathlib import Path

import yaml

parser = argparse.ArgumentParser()
parser.add_argument("input_directory", type=Path)
Expand All @@ -14,11 +15,11 @@

input_dir = args.input_directory
if not input_dir.is_dir():
quit(f"{input_dir} should exist and be a directory")
sys.exit(f"{input_dir} should exist and be a directory")

input_filename = input_dir / "recipe.yaml"
if not input_filename.is_file():
quit(f"{input_filename} should exist and be a file")
sys.exit(f"{input_filename} should exist and be a file")

# If backup does not exist create it.
input_backup = input_dir / "recipe_original.yaml"
Expand Down