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

View file

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

View file

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

View file

@ -9,11 +9,11 @@ from hashlib import sha256
from pathlib import Path from pathlib import Path
from typing import List, Optional, Union from typing import List, Optional, Union
from .common import Package, sh, stow
import toml import toml
from vfs import Vfs from vfs import Vfs
from .common import Package, sh, stow
def tempf(name): def tempf(name):
root = Path("/tmp/stow") root = Path("/tmp/stow")
@ -94,11 +94,29 @@ class PackageV1(Package):
def post_install(self, fs: Vfs, dest: Path): def post_install(self, fs: Vfs, dest: Path):
self.do_sh_or_script(self.config().get("package", {}).get("post_install"), fs, dest) self.do_sh_or_script(self.config().get("package", {}).get("post_install"), fs, dest)
def json(self): def json(self):
return self.config() 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): class ProfileV1(PackageV1):
"""Unline packages, profiles don't support recursive stow of contents.""" """Unline packages, profiles don't support recursive stow of contents."""

View file

@ -6,7 +6,6 @@ import logging
from shutil import rmtree from shutil import rmtree
from subprocess import run from subprocess import run
_log = logging.getLogger(__name__) _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 from autoflake import main
if __name__ == "__main__": if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0]) sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
sys.exit(main()) sys.exit(main())

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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