Implement single-file packages

Fixes #5
This commit is contained in:
Reid 'arrdem' McKenzie 2022-09-26 00:16:08 -06:00
parent 33bea69dff
commit 9ea96d0c1d
13 changed files with 39 additions and 34 deletions

View file

@ -2,28 +2,22 @@
import logging
import os
from pathlib import Path
import pickle
from typing import List, Optional, Union
import re
import platform
from pprint import pformat
import re
from collections import defaultdict
from . import (
__author__,
__copyright__,
__license__,
__version__,
)
from .v0 import PackageV0, ProfileV0
from .v1 import PackageV1, ProfileV1
from pathlib import Path
from pprint import pformat
from typing import List, Optional, Union
import click
import toml
from toposort import toposort_flatten
from vfs import Vfs
from . import __author__, __copyright__, __license__, __version__
from .v0 import PackageV0, ProfileV0
from .v1 import LightPackageV1, PackageV1, ProfileV1
log = logging.getLogger(__name__)
@ -114,7 +108,7 @@ def load(root: Path, name: str, clss):
def load_package(root, name):
log.debug(f"Attempting to load package {name} from {root}")
return load(root, name, [PackageV1, PackageV0])
return load(root, name, [LightPackageV1, PackageV1, PackageV0])
def load_profile(root, name):

View file

@ -1,14 +1,13 @@
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
from shlex import quote as sh_quote
import sys
from typing import List, Optional
from vfs import Vfs
# FIXME: This should be a config somewhere
SHELL = "/bin/sh"

View file

@ -3,13 +3,13 @@
An ill-considered pseudo-format.
"""
from pathlib import Path
import re
from .common import Package, sh, stow
from pathlib import Path
from vfs import Vfs
from .common import Package, sh, stow
class PackageV0(Package):
"""The original package format from install.sh."""

View file

@ -9,11 +9,11 @@ from hashlib import sha256
from pathlib import Path
from typing import List, Optional, Union
from .common import Package, sh, stow
import toml
from vfs import Vfs
from .common import Package, sh, stow
def tempf(name):
root = Path("/tmp/stow")
@ -94,11 +94,29 @@ class PackageV1(Package):
def post_install(self, fs: Vfs, dest: Path):
self.do_sh_or_script(self.config().get("package", {}).get("post_install"), fs, dest)
def json(self):
return self.config()
class LightPackageV1(PackageV1):
"""A package with no file content, defined in a single file."""
SPECIAL_FILES = []
_config = None
def config(self):
if not self._config:
with open(self.root, "r") as fp:
self._config = toml.load(fp)
return self._config
def test(self):
return self.root.exists() \
and self.root.is_file() \
and self.root.name.endswith(".toml") \
and self.config().get("cram", {}).get("version") == 1
class ProfileV1(PackageV1):
"""Unline packages, profiles don't support recursive stow of contents."""

View file

@ -6,7 +6,6 @@ import logging
from shutil import rmtree
from subprocess import run
_log = logging.getLogger(__name__)

View file

@ -0,0 +1,5 @@
[cram]
version = 1
[[package.install]]
run = "echo 'ok'"

View file

@ -9,7 +9,6 @@ import sys
from autoflake import main
if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
sys.exit(main())

View file

@ -5,7 +5,6 @@ import sys
from black import nullcontext, patched_main
parser = argparse.ArgumentParser()
parser.add_argument("--output-file", default=None)

View file

@ -1,5 +1,4 @@
from flake8.main import cli
if __name__ == "__main__":
cli.main()

View file

@ -9,7 +9,6 @@ import sys
from isort.main import main
if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\.pyw?|\.exe)?$", "", sys.argv[0])
sys.exit(main())

View file

@ -4,7 +4,6 @@ import sys
import pytest
if __name__ == "__main__":
cmdline = ["--ignore=external"] + sys.argv[1:]
print(cmdline, file=sys.stderr)

View file

@ -4,12 +4,8 @@ Validate 3rdparty library licenses as approved.
import re
from pkg_resources import (
DistInfoDistribution,
working_set,
)
import pytest
from pkg_resources import DistInfoDistribution, working_set
# Licenses approved as representing non-copyleft and not precluding commercial usage.
# This is all easy, there's a good schema here.

View file

@ -7,6 +7,5 @@ Shim for executing isort.
from unify import main
if __name__ == "__main__":
exit(main())