Skip to content

Commit

Permalink
Get set up for an incremental Zig port since python is dog (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline authored May 12, 2024
1 parent 24f045e commit 8ca61ba
Show file tree
Hide file tree
Showing 65 changed files with 318 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
run: nix develop --command make lintcheck
- name: Build
if: success() || failure()
run: nix build .
run: nix build .#all
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# Testing
db.sqlite3

# Nix
result
# Python
.direnv
__pycache__
.ruff_cache
.mypy_cache
.coverage
.coverage.*
result
db.sqlite3
htmlcov
*.egg-info

# Zig
*.so
*.so.o
zig-cache
zig-out
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
check: typecheck test lintcheck

# Build the Zig library for development.
build-zig:
cd rose-zig && zig build -Doptimize=Debug

typecheck:
mypy .

test:
test: build-zig
pytest -n logical .
coverage html

test-seq:
test-seq: build-zig
pytest .
coverage html

snapshot:
snapshot: build-zig
pytest --snapshot-update .

lintcheck:
Expand All @@ -24,4 +28,7 @@ lint:
ruff check --fix .
prettier --write .

.PHONY: check test typecheck lintcheck lint
clean:
git clean -xdf

.PHONY: build-zig check test typecheck lintcheck lint clean
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import pytest
from click.testing import CliRunner

from rose.cache import CACHE_SCHEMA_PATH, process_string_for_fts, update_cache
from rose.common import VERSION
from rose.config import Config, VirtualFSConfig
Expand Down
79 changes: 44 additions & 35 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
python = pkgs.python311;
uuid6-python = python.pkgs.buildPythonPackage {
python-pin = pkgs.python311;
version = nixpkgs.lib.strings.removeSuffix "\n" (builtins.readFile ./rose-py/rose/.version);
uuid6 = python-pin.pkgs.buildPythonPackage {
pname = "uuid6-python";
version = "2023.5.2";
src = pkgs.fetchFromGitHub {
Expand All @@ -26,30 +27,31 @@
};
doCheck = false;
};
prod-deps = with python.pkgs; [
appdirs
click
jinja2
llfuse
mutagen
send2trash
setuptools
tomli-w
uuid6-python
watchdog
];
dev-deps = with python.pkgs; [
mypy
pytest
pytest-timeout
pytest-cov
pytest-xdist
snapshottest
];
dev-cli = pkgs.writeShellScriptBin "rose" ''
cd $ROSE_ROOT
python -m rose_cli "$@"
'';
py-deps = with python-pin.pkgs; {
inherit
# Runtime deps.
appdirs
cffi
click
jinja2
llfuse
mutagen
send2trash
setuptools
tomli-w
uuid6
watchdog
# Dev tools.
mypy
pytest
pytest-timeout
pytest-cov
pytest-xdist
snapshottest;
};
python-with-deps = python-pin.withPackages (_:
pkgs.lib.attrsets.mapAttrsToList (a: b: b) py-deps
);
in
{
devShells.default = pkgs.mkShell {
Expand All @@ -62,29 +64,36 @@
echo "$path"
}
export ROSE_ROOT="$(find-up flake.nix)"
export ROSE_SO_PATH="$ROSE_ROOT/rose-zig/zig-out/lib/librose.so"
export PYTHONPATH="$ROSE_ROOT/rose-py:''${PYTHONPATH:-}"
export PYTHONPATH="$ROSE_ROOT/rose-watchdog:$PYTHONPATH"
export PYTHONPATH="$ROSE_ROOT/rose-vfs:$PYTHONPATH"
export PYTHONPATH="$ROSE_ROOT/rose-cli:$PYTHONPATH"
'';
buildInputs = [
(pkgs.buildEnv {
name = "rose-devshell";
paths = with pkgs; [
(python.withPackages (_: prod-deps ++ dev-deps))
python-with-deps
ruff
dev-cli
nodePackages.pyright
nodePackages.prettier
zig
zls
];
})
];
};
packages = rec {
rose = python.pkgs.buildPythonPackage {
pname = "rose";
version = nixpkgs.lib.strings.removeSuffix "\n" (builtins.readFile ./rose/.version);
src = ./.;
propagatedBuildInputs = prod-deps;
doCheck = false;
rose-zig = pkgs.callPackage ./rose-zig { inherit version; };
rose-py = pkgs.callPackage ./rose-py { inherit version python-pin py-deps rose-zig; };
rose-watchdog = pkgs.callPackage ./rose-watchdog { inherit version python-pin py-deps rose-py; };
rose-vfs = pkgs.callPackage ./rose-vfs { inherit version python-pin py-deps rose-py; };
rose-cli = pkgs.callPackage ./rose-cli { inherit version python-pin py-deps rose-py rose-vfs rose-watchdog; };
all = pkgs.buildEnv {
name = "rose-all";
paths = [ rose-zig rose-py rose-watchdog rose-vfs rose-cli ];
};
default = rose;
};
});
}
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ unfixable = [
strict = true
strict_optional = true
explicit_package_bases = true
exclude = [
"setup.py"
]

[[tool.mypy.overrides]]
module = "fuse"
Expand All @@ -86,6 +89,9 @@ ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "snapshottest"
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "cffi"
ignore_missing_imports = true

[tool.pytest.ini_options]
addopts = [
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions rose-cli/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ python-pin
, version
, py-deps
, rose-py
, rose-vfs
, rose-watchdog
}:

python-pin.pkgs.buildPythonPackage {
pname = "rose-cli";
version = version;
src = ./.;
propagatedBuildInputs = [
rose-py
rose-vfs
rose-watchdog
py-deps.click
];
doCheck = false;
}
File renamed without changes.
3 changes: 1 addition & 2 deletions rose_cli/__main__.py → rose-cli/rose_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import sys

import click
from rose import RoseExpectedError

from rose_cli.cli import CliExpectedError, cli


def main() -> None:
from rose import RoseExpectedError

try:
cli()
except (RoseExpectedError, CliExpectedError) as e:
Expand Down
14 changes: 11 additions & 3 deletions rose_cli/cli.py → rose-cli/rose_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from pathlib import Path

import click

from rose import (
VERSION,
Action,
Expand Down Expand Up @@ -51,6 +50,9 @@
toggle_release_new,
update_cache,
)
from rose_vfs import mount_virtualfs
from rose_watchdog import start_watchdog

from rose_cli.dump import (
dump_all_artists,
dump_all_collages,
Expand All @@ -70,8 +72,6 @@
dump_track,
)
from rose_cli.templates import preview_path_templates
from rose_vfs import mount_virtualfs
from rose_watchdog import start_watchdog

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -121,6 +121,14 @@ def version() -> None:
click.echo(VERSION)


@cli.command()
def tmp() -> None:
"""Temporary development command for FFI testing. If you see this, it's a bug."""
from rose.ffi import get_release

print(get_release())


@cli.group()
def config() -> None:
"""Utilites for configuring Rosé."""
Expand Down
9 changes: 7 additions & 2 deletions rose_cli/cli_test.py → rose-cli/rose_cli/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import pytest
from click.testing import CliRunner

from rose import AudioTags, Config
from rose.ffi import get_release
from rose_vfs.virtualfs_test import start_virtual_fs

from rose_cli.cli import (
Context,
InvalidReleaseArgError,
Expand All @@ -18,7 +20,6 @@
unwatch,
watch,
)
from rose_vfs.virtualfs_test import start_virtual_fs


@pytest.mark.usefixtures("seeded_cache")
Expand Down Expand Up @@ -125,3 +126,7 @@ def mock_exit(x: int) -> None:
# Assert that we can't kill a non-existent watchdog.
res = runner.invoke(unwatch, obj=ctx)
assert res.exit_code == 1


def test_ffi() -> None:
assert get_release() == "hello"
File renamed without changes.
2 changes: 1 addition & 1 deletion rose_cli/dump_test.py → rose-cli/rose_cli/dump_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from typing import Any

import pytest

from rose import Config, Matcher

from rose_cli.dump import (
dump_all_artists,
dump_all_collages,
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion rose_cli/templates.py → rose-cli/rose_cli/templates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import click

from rose import (
Config,
PathTemplate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
from click.testing import CliRunner

from rose import Config

from rose_cli.templates import (
preview_path_templates,
)
Expand Down
21 changes: 21 additions & 0 deletions rose-cli/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import setuptools

with open(".version") as f:
version = f.read().strip()

setuptools.setup(
name="rose-cli",
version=version,
python_requires=">=3.11.0",
author="blissful",
author_email="blissful@sunsetglow.net",
license="Apache-2.0",
entry_points={"console_scripts": ["rose = rose_cli.__main__:main"]},
packages=["rose_cli"],
install_requires=[
"click",
"rose",
"rose-vfs",
"rose-watchdog",
],
)
23 changes: 23 additions & 0 deletions rose-py/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ python-pin
, version
, py-deps
, rose-zig
}:

python-pin.pkgs.buildPythonPackage {
pname = "rose";
version = version;
src = ./.;
propagatedBuildInputs = [
rose-zig
py-deps.appdirs
py-deps.click
py-deps.jinja2
py-deps.mutagen
py-deps.send2trash
py-deps.tomli-w
py-deps.uuid6
];
doCheck = false;
ROSE_SO_PATH = "${rose-zig}/lib/librose.so";
}
1 change: 1 addition & 0 deletions rose-py/rose/.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.5.0
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8ca61ba

Please sign in to comment.