mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-30 13:29:55 +00:00
Compare commits
2 Commits
d18d146d79
...
39baf93560
Author | SHA1 | Date | |
---|---|---|---|
39baf93560 | |||
20a9134477 |
@ -43,7 +43,7 @@ RUN pacman -S --noconfirm --asdeps \
|
||||
pacman -S --noconfirm --asdeps \
|
||||
base-devel \
|
||||
python-build \
|
||||
python-hatchling \
|
||||
python-flit \
|
||||
python-installer \
|
||||
python-wheel \
|
||||
&& \
|
||||
|
@ -8,7 +8,7 @@ arch=('any')
|
||||
url="https://github.com/arcan1s/ahriman"
|
||||
license=('GPL3')
|
||||
depends=('devtools>=1:1.0.0' 'git' 'pyalpm' 'python-bcrypt' 'python-inflection' 'python-pyelftools' 'python-requests')
|
||||
makedepends=('python-build' 'python-hatchling' 'python-installer' 'python-wheel')
|
||||
makedepends=('python-build' 'python-flit' 'python-installer' 'python-wheel')
|
||||
optdepends=('python-aioauth-client: web server with OAuth2 authorization'
|
||||
'python-aiohttp: web server'
|
||||
'python-aiohttp-apispec>=3.0.0: web server'
|
||||
@ -32,25 +32,20 @@ backup=('etc/ahriman.ini'
|
||||
'etc/ahriman.ini.d/logging.ini')
|
||||
|
||||
build() {
|
||||
cd "$pkgname-$pkgver"
|
||||
cd "$pkgname-$pkgver"
|
||||
|
||||
python -m build --wheel --no-isolation
|
||||
python -m build --wheel --no-isolation
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$pkgname-$pkgver"
|
||||
cd "$pkgname-$pkgver"
|
||||
|
||||
python -m installer --destdir="$pkgdir" "dist/$pkgname-$pkgver-py3-none-any.whl"
|
||||
python -m installer --destdir="$pkgdir" "dist/$pkgname-$pkgver-py3-none-any.whl"
|
||||
|
||||
# hatchling doesn't support installation outside of the python root, so we need to install data files manually
|
||||
local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
|
||||
cp -a "$pkgdir$site_packages/$pkgname/data/"* "$pkgdir/usr/"
|
||||
rm -r "$pkgdir$site_packages/$pkgname/data"
|
||||
# keep usr/share configs as reference and copy them to /etc
|
||||
install -Dm644 "$pkgdir/usr/share/$pkgname/settings/ahriman.ini" "$pkgdir/etc/ahriman.ini"
|
||||
install -Dm644 "$pkgdir/usr/share/$pkgname/settings/ahriman.ini.d/logging.ini" "$pkgdir/etc/ahriman.ini.d/logging.ini"
|
||||
|
||||
# keep usr/share configs as reference and copy them to /etc
|
||||
install -Dm644 "$pkgdir/usr/share/$pkgname/settings/ahriman.ini" "$pkgdir/etc/ahriman.ini"
|
||||
install -Dm644 "$pkgdir/usr/share/$pkgname/settings/ahriman.ini.d/logging.ini" "$pkgdir/etc/ahriman.ini.d/logging.ini"
|
||||
|
||||
install -Dm644 "$srcdir/$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
|
||||
install -Dm644 "$srcdir/$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
|
||||
install -Dm644 "$srcdir/$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
|
||||
install -Dm644 "$srcdir/$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
requires = ["flit_core"]
|
||||
build-backend = "flit_core.buildapi"
|
||||
|
||||
[project]
|
||||
name = "ahriman"
|
||||
@ -89,26 +89,18 @@ web = [
|
||||
"setuptools", # required by aiohttp-apispec
|
||||
]
|
||||
|
||||
[tool.hatch.version]
|
||||
path = "src/ahriman/__init__.py"
|
||||
|
||||
[tool.hatch.build.targets.sdist]
|
||||
[tool.flit.sdist]
|
||||
include = [
|
||||
"AUTHORS",
|
||||
"CONTRIBUTING.md",
|
||||
"SECURITY.md",
|
||||
"package",
|
||||
"src",
|
||||
"subpackages.py",
|
||||
"web.png",
|
||||
]
|
||||
exclude = [
|
||||
"package/archlinux",
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = [
|
||||
"src/ahriman",
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.wheel.force-include]
|
||||
"package" = "ahriman/data"
|
||||
[tool.flit.external-data]
|
||||
directory = "package"
|
||||
|
@ -105,11 +105,11 @@ def run() -> int:
|
||||
Returns:
|
||||
int: application status code
|
||||
"""
|
||||
args_parser = _parser()
|
||||
args = args_parser.parse_args()
|
||||
parser = _parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command is None: # in case of empty command we would like to print help message
|
||||
args_parser.exit(status=2, message=args_parser.format_help())
|
||||
parser.exit(status=2, message=parser.format_help())
|
||||
|
||||
handler: Handler = args.handler
|
||||
return handler.execute(args)
|
||||
|
@ -478,7 +478,6 @@ def utcnow() -> datetime.datetime:
|
||||
def walk(directory_path: Path) -> Generator[Path, None, None]:
|
||||
"""
|
||||
list all file paths in given directory
|
||||
Credits to https://stackoverflow.com/a/64915960
|
||||
|
||||
Args:
|
||||
directory_path(Path): root directory path
|
||||
@ -487,18 +486,13 @@ def walk(directory_path: Path) -> Generator[Path, None, None]:
|
||||
Path: all found files in given directory with full path
|
||||
|
||||
Examples:
|
||||
Since the :mod:`pathlib` module does not provide an alternative to :func:`os.walk()`, this wrapper
|
||||
can be used instead::
|
||||
Wrapper around :func:`pathlib.Path.walk`, which emits all files in the directory::
|
||||
|
||||
>>> from pathlib import Path
|
||||
>>>
|
||||
>>> for file_path in walk(Path.cwd()):
|
||||
>>> print(file_path)
|
||||
|
||||
Note, however, that unlike the original method, it does not yield directories.
|
||||
"""
|
||||
for element in directory_path.iterdir():
|
||||
if element.is_dir():
|
||||
yield from walk(element)
|
||||
continue
|
||||
yield element
|
||||
for root, _, files in directory_path.walk():
|
||||
for file in files:
|
||||
yield root / file
|
||||
|
86
subpackages.py
Normal file
86
subpackages.py
Normal file
@ -0,0 +1,86 @@
|
||||
#
|
||||
# Copyright (c) 2021-2024 ahriman team.
|
||||
#
|
||||
# This file is part of ahriman
|
||||
# (see https://github.com/arcan1s/ahriman).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse
|
||||
import shutil
|
||||
import site
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
site_packages = Path(site.getsitepackages()[0]).relative_to("/")
|
||||
SUBPACKAGES = {
|
||||
"ahriman": [
|
||||
site_packages / "ahriman",
|
||||
],
|
||||
"ahriman-web": [
|
||||
site_packages / "ahriman" / "application" / "handlers" / "web.py",
|
||||
site_packages / "ahriman" / "web",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def process(root: Path, include: list[Path], exclude: list[Path]) -> None:
|
||||
"""
|
||||
remove files based on patterns
|
||||
|
||||
Args:
|
||||
root(Path): root directory
|
||||
include(list[Path]): list of files to include to the subpackage
|
||||
exclude(list[Path]): list of files to exclude from the subpackage
|
||||
"""
|
||||
for subdirectory, _, files in root.walk(top_down=False):
|
||||
for file in files:
|
||||
full_path = subdirectory / file
|
||||
relative_path = full_path.relative_to(root)
|
||||
|
||||
if not any(relative_path.is_relative_to(path) for path in include):
|
||||
full_path.unlink()
|
||||
elif any(relative_path.is_relative_to(path) for path in exclude):
|
||||
full_path.unlink()
|
||||
|
||||
content = list(subdirectory.iterdir())
|
||||
if not content:
|
||||
shutil.rmtree(subdirectory)
|
||||
|
||||
|
||||
def run() -> None:
|
||||
"""
|
||||
run application
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="Split package into subpackages")
|
||||
parser.add_argument("root", help="package root", type=Path)
|
||||
parser.add_argument("subpackage", help="subpackage name", choices=SUBPACKAGES.keys())
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
include = SUBPACKAGES[args.subpackage]
|
||||
exclude = [
|
||||
path
|
||||
for subpackage, portion in SUBPACKAGES.items()
|
||||
if subpackage != args.subpackage
|
||||
for path in portion
|
||||
if not any(include_path.is_relative_to(path) for include_path in include)
|
||||
]
|
||||
|
||||
process(args.root, include, exclude)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
Reference in New Issue
Block a user