jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via ruff, yapf, mypy and pyright into place. They are checked with the make check target, and this commit adds the fixes for the target to succeed.
It does some refactoring where type checking dug up dirty bits, and also adds lots of churn in the Python code. To a good deal, that's owed to mere formatting changes. It would have been better to seperate those from syntax and refactoring fixes into multiple commits, so that the interesting changes don't drown in the formatting nose. However, that would have been a lot of additional work only to be thrown away by later commits, hence this commit has a big diff in one piece. The size of the diff is regrettable but hopefully a one-off: What it buys is automatic format checking for CI and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check . - mypy . - pyright- Format check:
- yapf --diff --recursive .The refactoring includes:
- Turn the Result class into a more elaborate object, capable of doing more heavy lifting around stderr and stdout decoding, summarizing outcome, and matching error strings.Aside from fixing broken type checks, this also removes lots of boilerplate calling code which is currently used for handling possible call outcome scenarios. Trying to access an inexistent, decoded string should raise a meaningful exception by itself now, which removes lots of code with case distinctions.- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because the checker rightfully complains it can't instantiate a Cmd instance where constructor arguments were needed. They never were, but the type used at the instantiating code's location in jw.pkg.App so claims.- Lots of sub- and sub-subcommands are derived from the base class of the invoking command. That provides some properties shared across the ancestor hierarchy of a command, but is semantically unsound. Fix that by introducing jw.pkg.BaseCmd class as a place to provide basic helpers shared across all commands used in a jw.pkg.App's context, and derive all command classes from that afresh. The parent command is still reachable via a common parent property.Formatting changes are conforming to PEP-8, mostly, with minor tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger. For Python 3, the default encoding is UTF-8, anyway.- Allow to run "make py-format" without having it produce any changes. It's basically "yapf --in-place --recursive ." with some code style settings, see conf/topdir/pyproject.toml. The settings may be debatable. I've had custom tweaks in place on that target, too, but then again, IDEs would have more hassle to integrate that.- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see [tool.isort] in pyproject.toml.- Hide imports needed for type-checking only behind
if TYPE_CHECKING- Spaces around assignments accounts for much churn. Having having no spaces in inline parameter list assignments and default parameter values would arguably be more compact where it's useful. On the other hand, I have not found a code formatter which allows spaces around assignments in parameter lists broken into one per line and that's often better than a wall of text.- Add two spaces before # export, as this seems to be mandated by PEP-8- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
|
|
@ -106,8 +106,8 @@ class BaseCmdPkgRelations(Cmd):
|
|||
default = False,
|
||||
help = (
|
||||
"Don't consider or output modules matching the os cascade in their "
|
||||
"[build].exclude config"
|
||||
)
|
||||
'[build].exclude config'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hide-self',
|
||||
|
|
|
|||
|
|
@ -1,65 +1,120 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import os
|
||||
import re
|
||||
|
||||
import os, re, sys, subprocess, datetime, time
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
from functools import lru_cache
|
||||
|
||||
from ...lib.util import get_profile_env
|
||||
from ...lib.log import *
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from ...App import Scope
|
||||
from ...lib.log import DEBUG, ERR, NOTICE, log
|
||||
from ...lib.util import get_profile_env, pretty_cmd
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdBuild(Cmd): # export
|
||||
class CmdBuild(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'build', help='janware software project build tool')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'build', help = 'janware software project build tool')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('--exclude', default='', help='Space seperated ist of modules to be excluded from build')
|
||||
parser.add_argument('-n', '--dry-run', action='store_true',
|
||||
default=False, help='Don\'t build anything, just print what would be done.')
|
||||
parser.add_argument('-O', '--build-order', action='store_true',
|
||||
default=False, help='Don\'t build anything, just print the build order.')
|
||||
parser.add_argument('-I', '--ignore-deps', action='store_true',
|
||||
default=False, help='Don\'t build dependencies, i.e. build only modules specified on the command line')
|
||||
parser.add_argument('--env-reinit', action='store_true',
|
||||
default=False, help='Source /etc/profile before each build step. Discard environment unless --env-keep is specified')
|
||||
parser.add_argument('--env-keep', default='none', help='Comma seperated list of environment variables to keep, '
|
||||
+ '"all" or "none", only meaningful if --env-reinit is specified')
|
||||
parser.add_argument('target', default='all', help='Build target')
|
||||
parser.add_argument('modules', nargs='+', default='', help='Modules to be built')
|
||||
parser.add_argument(
|
||||
'--exclude',
|
||||
default = '',
|
||||
help = 'Space seperated ist of modules to be excluded from build',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-n',
|
||||
'--dry-run',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = "Don't build anything, just print what would be done.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'-O',
|
||||
'--build-order',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = "Don't build anything, just print the build order.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'-I',
|
||||
'--ignore-deps',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = (
|
||||
"Don't build dependencies, i.e. build only modules specified "
|
||||
'on the command line'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--env-reinit',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = (
|
||||
'Source /etc/profile before each build step. Discard environment '
|
||||
'unless --env-keep is specified'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--env-keep',
|
||||
default = 'none',
|
||||
help = (
|
||||
'Comma seperated list of environment variables to keep, '
|
||||
'"all" or "none", only meaningful if --env-reinit is specified'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'target',
|
||||
default = 'all',
|
||||
help = 'Build target',
|
||||
)
|
||||
parser.add_argument(
|
||||
'modules',
|
||||
nargs = '+',
|
||||
default = '',
|
||||
help = 'Modules to be built',
|
||||
)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def read_deps(cur, prereq_type):
|
||||
@lru_cache(maxsize = None)
|
||||
def read_deps(cur, prereq_type: str) -> list[str]:
|
||||
# dep cache doesn't make a difference at all
|
||||
if prereq_type in dep_cache:
|
||||
if cur in dep_cache[prereq_type]:
|
||||
return dep_cache[prereq_type][cur]
|
||||
else:
|
||||
dep_cache[prereq_type]: dict[str, str] = {}
|
||||
dep_cache[prereq_type] = {}
|
||||
|
||||
ret = self.app.get_project_refs([ cur ], ['pkg.requires.jw'],
|
||||
prereq_type, scope = Scope.Subtree, add_self=False, names_only=True)
|
||||
ret = self.app.get_project_refs(
|
||||
[cur],
|
||||
['pkg.requires.jw'],
|
||||
prereq_type,
|
||||
scope = Scope.Subtree,
|
||||
add_self = False,
|
||||
names_only = True,
|
||||
)
|
||||
log(DEBUG, 'prerequisites = ' + ' '.join(ret))
|
||||
if cur in ret:
|
||||
ret.remove(cur)
|
||||
log(DEBUG, 'inserting', prereq_type, "prerequisites of", cur, ":", ' '.join(ret))
|
||||
|
||||
log(
|
||||
DEBUG,
|
||||
(f'Inserting {prereq_type}, prerequisites of {cur}: {" ".join(ret)}'),
|
||||
)
|
||||
|
||||
dep_cache[prereq_type][cur] = ret
|
||||
return ret
|
||||
|
||||
def add_dep_tree(cur, prereq_types, tree, all_deps):
|
||||
log(DEBUG, "adding prerequisites " + ' '.join(prereq_types) + " of module " + cur)
|
||||
log(DEBUG, 'Adding deps "{" ".join(prereq_types)}" of module {cur)')
|
||||
if cur in all_deps:
|
||||
log(DEBUG, 'already handled module ' + cur)
|
||||
log(DEBUG, 'Already handled module "{cur}"')
|
||||
return 0
|
||||
deps = set()
|
||||
all_deps.add(cur)
|
||||
for t in prereq_types:
|
||||
log(DEBUG, "checking prereqisites of type " + t)
|
||||
log(DEBUG, 'Checking deps of type "{t}"')
|
||||
deps.update(read_deps(cur, t))
|
||||
for d in deps:
|
||||
add_dep_tree(d, prereq_types, tree, all_deps)
|
||||
|
|
@ -70,17 +125,20 @@ class CmdBuild(Cmd): # export
|
|||
all_deps = set()
|
||||
dep_tree = {}
|
||||
for m in modules:
|
||||
log(DEBUG, "--- adding dependency tree of module " + m)
|
||||
log(DEBUG, '--- Adding dependency tree of module "{m}"')
|
||||
add_dep_tree(m, prereq_types, dep_tree, all_deps)
|
||||
while len(all_deps):
|
||||
# Find any leaf
|
||||
for d in all_deps:
|
||||
if not len(dep_tree[d]): # Dependency d doesn't have dependencies itself
|
||||
break # found
|
||||
else: # no Leaf found
|
||||
# Dependency d doesn't have dependencies itself
|
||||
if not len(dep_tree[d]):
|
||||
break # found
|
||||
else: # no Leaf found
|
||||
print(all_deps)
|
||||
raise Exception("fatal: the dependencies between these modules are unresolvable")
|
||||
order.append(d) # do it
|
||||
raise Exception(
|
||||
'Fatal: the dependencies between these modules are unresolvable'
|
||||
)
|
||||
order.append(d) # do it
|
||||
# bookkeep it
|
||||
all_deps.remove(d)
|
||||
for k in dep_tree.keys():
|
||||
|
|
@ -88,56 +146,68 @@ class CmdBuild(Cmd): # export
|
|||
dep_tree[k].remove(d)
|
||||
return 1
|
||||
|
||||
async def run_make(module, target, cur_project, num_projects):
|
||||
async def run_make(module, target, cur_project, num_projects) -> None:
|
||||
|
||||
patt = self.app.is_excluded_from_build(module)
|
||||
if patt is not None:
|
||||
title = f'---- {module}'
|
||||
log(NOTICE, f',{title} >')
|
||||
log(NOTICE, f'| Configured to skip build on platform >{patt}<')
|
||||
log(NOTICE, f'`{title} <')
|
||||
return
|
||||
|
||||
make_cmd = [ "make", target ]
|
||||
wd = self.app.find_dir(module, pretty=False)
|
||||
title = '---- [%d/%d]: Running "%s" in %s -' % (cur_project, num_projects, ' '.join(make_cmd), wd)
|
||||
make_cmd = ['make', target]
|
||||
wd = self.app.find_dir(module, pretty = False)
|
||||
title = '---- [%d/%d]: Running "%s" in %s -' % (
|
||||
cur_project,
|
||||
num_projects,
|
||||
' '.join(make_cmd),
|
||||
wd,
|
||||
)
|
||||
|
||||
mod_env = None
|
||||
if args.env_reinit:
|
||||
keep: bool|list[str] = False
|
||||
keep: bool | list[str] = False
|
||||
if args.env_keep is not None:
|
||||
match args.env_keep:
|
||||
case 'all':
|
||||
keep=True
|
||||
keep = True
|
||||
case 'none':
|
||||
keep=False
|
||||
keep = False
|
||||
case _:
|
||||
keep = args.env_keep.split(',')
|
||||
mod_env = await get_profile_env(keep=keep)
|
||||
mod_env = await get_profile_env(keep = keep)
|
||||
|
||||
try:
|
||||
await self.app.exec_context.run(
|
||||
make_cmd,
|
||||
wd=wd,
|
||||
throw=True,
|
||||
verbose=True,
|
||||
mod_env=mod_env,
|
||||
title=title
|
||||
wd = wd,
|
||||
throw = True,
|
||||
verbose = True,
|
||||
mod_env = mod_env,
|
||||
title = title,
|
||||
)
|
||||
except Exception as e:
|
||||
log(ERR, f'Failed to make target "{target}" in module "{module}" below base {self.app.projs_root}: {str(e)}')
|
||||
log(
|
||||
ERR,
|
||||
(
|
||||
f'Failed to make target "{target}" in module "{module}" '
|
||||
f'below base {self.app.projs_root}: {str(e)}'
|
||||
),
|
||||
)
|
||||
raise
|
||||
|
||||
async def run_make_on_modules(modules, order, target):
|
||||
cur_project = 0
|
||||
num_projects = len(order)
|
||||
if target in ["clean", "distclean"]:
|
||||
if target in ['clean', 'distclean']:
|
||||
for m in reversed(order):
|
||||
cur_project += 1
|
||||
await run_make(m, target, cur_project, num_projects)
|
||||
if m in modules:
|
||||
modules.remove(m)
|
||||
if not len(modules):
|
||||
log(NOTICE, "All modules cleaned")
|
||||
log(NOTICE, 'All modules cleaned')
|
||||
return
|
||||
else:
|
||||
for m in order:
|
||||
|
|
@ -146,7 +216,7 @@ class CmdBuild(Cmd): # export
|
|||
|
||||
async def run(args):
|
||||
|
||||
log(DEBUG, "----------------------------------------- running ", ' '.join(sys.argv))
|
||||
log(DEBUG, f'-------------------------------------- running {pretty_cmd()}')
|
||||
|
||||
modules = args.modules
|
||||
exclude = args.exclude.split()
|
||||
|
|
@ -154,19 +224,19 @@ class CmdBuild(Cmd): # export
|
|||
|
||||
env_exclude = os.getenv('BUILD_EXCLUDE', '')
|
||||
if len(env_exclude):
|
||||
log(NOTICE, "Exluding modules from environment: " + env_exclude)
|
||||
exclude += " " + env_exclude
|
||||
log(NOTICE, 'Exluding modules from environment: ' + env_exclude)
|
||||
exclude += ' ' + env_exclude
|
||||
|
||||
# -- build
|
||||
order = []
|
||||
|
||||
glob_prereq_types = [ "build" ]
|
||||
if re.match("pkg-.*", target) is not None:
|
||||
glob_prereq_types = [ "build", "run", "release", "devel" ]
|
||||
glob_prereq_types = ['build']
|
||||
if re.match('pkg-.*', target) is not None:
|
||||
glob_prereq_types = ['build', 'run', 'release', 'devel']
|
||||
|
||||
if target != 'order' and not args.build_order:
|
||||
log(NOTICE, "Using prerequisite types " + ' '.join(glob_prereq_types))
|
||||
log(NOTICE, "Calculating order for modules ... ")
|
||||
log(NOTICE, 'Using prerequisite types ' + ' '.join(glob_prereq_types))
|
||||
log(NOTICE, 'Calculating order for modules ... ')
|
||||
|
||||
calculate_order(order, modules, glob_prereq_types)
|
||||
if args.ignore_deps:
|
||||
|
|
@ -177,18 +247,24 @@ class CmdBuild(Cmd): # export
|
|||
exit(0)
|
||||
|
||||
cur_project = 0
|
||||
log(NOTICE, "Building target %s in %d projects:" % (target, len(order)))
|
||||
log(NOTICE, 'Building target %s in %d projects:' % (target, len(order)))
|
||||
for m in order:
|
||||
cur_project += 1
|
||||
log(NOTICE, " %3d %s" % (cur_project, m))
|
||||
log(NOTICE, ' %3d %s' % (cur_project, m))
|
||||
|
||||
if args.dry_run:
|
||||
exit(0)
|
||||
|
||||
await run_make_on_modules(modules, order, target)
|
||||
|
||||
log(NOTICE, 'Build done at %s' % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
|
||||
log(
|
||||
NOTICE,
|
||||
(
|
||||
'Build done at %s' %
|
||||
(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
),
|
||||
)
|
||||
|
||||
dep_cache: dict[dict[str, str]] = {}
|
||||
dep_cache: dict[str, dict[str, list[str]]] = {}
|
||||
|
||||
await run(args)
|
||||
|
|
|
|||
|
|
@ -1,54 +1,72 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from argparse import ArgumentParser, Namespace
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
|
||||
from ...lib.log import *
|
||||
from ...lib.base import InputMode
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from ...App import Scope
|
||||
from ...lib.log import NOTICE, log
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ...lib.base import Result
|
||||
|
||||
class CmdCanonicalizeRemotes(Cmd): # export
|
||||
class CmdCanonicalizeRemotes(Cmd): # export
|
||||
|
||||
def __rewrite_url(self, url: str) -> str:
|
||||
return url.replace('/srv/git', '')
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'canonicalize-remotes', help='Streamline janware Git remotes')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'canonicalize-remotes', help = 'Streamline janware Git remotes'
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('-n', '--dry-run', default=False, action='store_true', help='Only log what would be done')
|
||||
parser.add_argument(
|
||||
'-n',
|
||||
'--dry-run',
|
||||
default = False,
|
||||
action = 'store_true',
|
||||
help = 'Only log what would be done',
|
||||
)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
|
||||
async def git(cmd: list[str], ro=False, throw=True) -> Result:
|
||||
async def git(cmd: list[str], ro = False, throw = True) -> Result:
|
||||
cmd = ['/usr/bin/git', *cmd]
|
||||
log(NOTICE, f'-- {" ".join(cmd)}')
|
||||
if ro or not args.dry_run:
|
||||
return await self.app.exec_context.run(cmd, cmd_input=InputMode.NonInteractive, throw=throw)
|
||||
remotes: dict[str, dict[str, str]] = {}
|
||||
stdout, stderr, status = await git(['remote', '-v'], ro=True)
|
||||
for line in stdout.decode().splitlines():
|
||||
return await self.app.exec_context.run(
|
||||
cmd, cmd_input = InputMode.NonInteractive, throw = throw
|
||||
)
|
||||
return Result(b'', None, 0)
|
||||
|
||||
remotes: dict[str, dict[str, str | list[str]]] = {}
|
||||
result = await git(['remote', '-v'], ro = True)
|
||||
for line in result.stdout_str.splitlines():
|
||||
name, url, fp = line.split()
|
||||
remote = remotes.setdefault(name, {})
|
||||
key = 'url' if fp == '(fetch)' else 'pushurl'
|
||||
fpurls = remote.setdefault(key, [])
|
||||
assert isinstance(fpurls, list)
|
||||
fpurls.append(url)
|
||||
for remote, config in remotes.items():
|
||||
for name, remote in remotes.items():
|
||||
dirty_keys: set[str] = set()
|
||||
for key, urls in config.items():
|
||||
for key, urls in remote.items():
|
||||
for url in urls:
|
||||
if url != self.__rewrite_url(url):
|
||||
dirty_keys.add(key)
|
||||
for key in dirty_keys:
|
||||
urls = config[key]
|
||||
await git(['config', '--unset-all', f'remote.{remote}.{key}'], throw=False)
|
||||
urls = remote[key]
|
||||
await git(
|
||||
['config', '--unset-all', f'remote.{name}.{key}'], throw = False
|
||||
)
|
||||
for url in urls:
|
||||
await git(['config', '--add', f'remote.{remote}.{key}', self.__rewrite_url(url)])
|
||||
await git(
|
||||
[
|
||||
'config',
|
||||
'--add',
|
||||
f'remote.{name}.{key}',
|
||||
self.__rewrite_url(url),
|
||||
]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from ...App import Scope
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdCflags(Cmd): # export
|
||||
class CmdCflags(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'cflags', help='cflags')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'cflags', help = 'cflags')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], 'build',
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
'build',
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
out = []
|
||||
for m in reversed(deps):
|
||||
path = self.app.find_dir(m, ['/include'])
|
||||
|
|
|
|||
|
|
@ -1,24 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from ...lib.log import NOTICE, log
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ...lib.log import *
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdCheck(Cmd): # export
|
||||
|
||||
class CmdCheck(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'check', help='Check for circular dependencies between given modules')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'check',
|
||||
help = 'Check for circular dependencies between given modules',
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('-f', '--flavour', nargs='?', default = 'build')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
parser.add_argument('-f', '--flavour', nargs = '?', default = 'build')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
path = self.app.find_circular_deps(args.module, args.flavour)
|
||||
if path:
|
||||
log(NOTICE, f'Found circular dependency in flavour {args.flavour}:', ' -> '.join(path))
|
||||
if self.app.find_circular_deps(args.module, args.flavour):
|
||||
log(NOTICE, f'Found circular dependency in flavour {args.flavour}')
|
||||
exit(1)
|
||||
log(NOTICE, f'No circular dependency found for flavour {args.flavour} in modules:', ' '.join(args.module))
|
||||
log(
|
||||
NOTICE,
|
||||
f'No circular dependency found for flavour {args.flavour} in modules:',
|
||||
' '.join(args.module),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdCommands(Cmd): # export
|
||||
|
||||
class CmdCommands(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'commands', help='List available commands')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'commands', help = 'List available commands')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys, re, os, glob
|
||||
this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
ret = []
|
||||
for file_name in glob.glob('Cmd*.py', root_dir=this_dir):
|
||||
for file_name in glob.glob('Cmd*.py', root_dir = this_dir):
|
||||
cc_name = re.sub(r'^Cmd|\.py', '', file_name)
|
||||
name = re.sub(r'(?<!^)(?=[A-Z])', '-', cc_name).lower()
|
||||
ret.append(name)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdExepath(Cmd): # export
|
||||
class CmdExepath(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'exepath', help='exepath')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'exepath', help = 'exepath')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], [ 'run', 'build', 'devel' ],
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
['run', 'build', 'devel'],
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
out = []
|
||||
for m in deps:
|
||||
path = self.app.find_dir(m, ['/bin'])
|
||||
|
|
|
|||
|
|
@ -1,44 +1,72 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
|
||||
import re, os
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...lib.log import *
|
||||
from ...lib.log import DEBUG, log
|
||||
from ...lib.Uri import Uri
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdGetAuthInfo(Cmd): # export
|
||||
class CmdGetAuthInfo(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'get-auth-info', help='Try to retrieve authentication information from the source tree')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'get-auth-info',
|
||||
help = 'Try to retrieve authentication information from the source tree',
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('--only-values', default=False, action='store_true',
|
||||
help='Don\'t prefix values by "<field-name>="')
|
||||
parser.add_argument('--username', default=False, action='store_true',
|
||||
help='Show user name')
|
||||
parser.add_argument('--password', default=False, action='store_true',
|
||||
help='Show password')
|
||||
parser.add_argument('--remote-owner-base', default=False, action='store_true',
|
||||
help='Show remote base URL for owner jw-pkg was cloned from')
|
||||
parser.add_argument('--remote-base', default=False, action='store_true',
|
||||
help='Show remote base URL')
|
||||
parser.add_argument(
|
||||
'--only-values',
|
||||
default = False,
|
||||
action = 'store_true',
|
||||
help = 'Don\'t prefix values by "<field-name>="',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--username',
|
||||
default = False,
|
||||
action = 'store_true',
|
||||
help = 'Show user name'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--password',
|
||||
default = False,
|
||||
action = 'store_true',
|
||||
help = 'Show password'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--remote-owner-base',
|
||||
default = False,
|
||||
action = 'store_true',
|
||||
help = 'Show remote base URL for owner jw-pkg was cloned from',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--remote-base',
|
||||
default = False,
|
||||
action = 'store_true',
|
||||
help = 'Show remote base URL',
|
||||
)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
keys = ['username', 'password']
|
||||
|
||||
# --- Milk jw-pkg repo
|
||||
jw_pkg_dir = self.app.find_dir('jw-pkg', pretty=False)
|
||||
jw_pkg_dir = self.app.find_dir('jw-pkg', pretty = False)
|
||||
if not os.path.isdir(jw_pkg_dir + '/.git'):
|
||||
log(DEBUG, f'jw-pkg directory is not a Git repo: {jw_pkg_dir}')
|
||||
return
|
||||
remotes, stderr, status = (await self.app.exec_context.run(['git', '-C', jw_pkg_dir, 'remote', '-v'])).decode()
|
||||
git_result = await self.app.exec_context.run(
|
||||
['git', '-C', jw_pkg_dir, 'remote', '-v']
|
||||
)
|
||||
result: dict[str, str] = {}
|
||||
for line in remotes.splitlines():
|
||||
for line in git_result.stdout_str.splitlines():
|
||||
name, url, typ = re.split(r'\s+', line)
|
||||
if name == 'origin' and typ in ['(pull)', '(fetch)']: # TODO: Use other remotes, too?
|
||||
if name == 'origin' and typ in [
|
||||
'(pull)',
|
||||
'(fetch)',
|
||||
]: # TODO: Use other remotes, too?
|
||||
parsed = Uri(url)
|
||||
for key in keys:
|
||||
result[key] = getattr(parsed, key)
|
||||
|
|
@ -52,7 +80,7 @@ class CmdGetAuthInfo(Cmd): # export
|
|||
|
||||
# --- Print results
|
||||
for key, val in result.items():
|
||||
if getattr(args, key, None) != True:
|
||||
if not getattr(args, key, None):
|
||||
continue
|
||||
if val is None:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdGetval(Cmd): # export
|
||||
|
||||
class CmdGetval(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'getval', help='Get value from project config')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'getval', help = 'Get value from project config')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('--project', default = None, help = 'Project name, default is name of project\'s topdir')
|
||||
parser.add_argument(
|
||||
'--project',
|
||||
default = None,
|
||||
help = "Project name, default is name of project's topdir",
|
||||
)
|
||||
parser.add_argument('section', default = '', help = 'Config section')
|
||||
parser.add_argument('key', default = '', help = 'Config key')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdHtdocsDir(Cmd): # export
|
||||
|
||||
class CmdHtdocsDir(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'htdocs-dir', help='Print source directory containing document root of a given module')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'htdocs-dir',
|
||||
help = 'Print source directory containing document root of a given module',
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
r = []
|
||||
for m in args.module:
|
||||
r.append(self.app.htdocs_dir(m))
|
||||
print(' '.join(r))
|
||||
|
|
|
|||
|
|
@ -1,27 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdLdflags(Cmd): # export
|
||||
class CmdLdflags(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'ldflags', help='ldflags')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'ldflags', help = 'ldflags')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('--exclude', action='append', help='Exclude Modules', default=[])
|
||||
parser.add_argument('-s', '--add-self', action='store_true',
|
||||
default=False, help='Include libflags of specified modules, too, not only their dependencies')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
parser.add_argument(
|
||||
'--exclude', action = 'append', help = 'Exclude Modules', default = []
|
||||
)
|
||||
parser.add_argument(
|
||||
'-s',
|
||||
'--add-self',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = (
|
||||
'Include libflags of specified modules, too, '
|
||||
'not only their dependencies'
|
||||
),
|
||||
)
|
||||
|
||||
# -L needs to contain more paths than libs linked with -l would require
|
||||
def __get_ldpathflags(self, names: list[str], exclude: list[str] = []) -> str:
|
||||
deps = self.app.get_project_refs(names, ['pkg.requires.jw'], 'build',
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
def __get_ldpathflags(
|
||||
self, names: list[str], exclude: list[str] = []
|
||||
) -> str | None:
|
||||
deps = self.app.get_project_refs(
|
||||
names,
|
||||
['pkg.requires.jw'],
|
||||
'build',
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
ret = []
|
||||
for m in deps:
|
||||
if m in exclude:
|
||||
|
|
@ -35,11 +50,17 @@ class CmdLdflags(Cmd): # export
|
|||
ret.append('-L' + path)
|
||||
if not ret:
|
||||
return None
|
||||
return(' '.join(ret))
|
||||
return ' '.join(ret)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], 'build',
|
||||
scope = Scope.One, add_self=args.add_self, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
'build',
|
||||
scope = Scope.One,
|
||||
add_self = args.add_self,
|
||||
names_only = True,
|
||||
)
|
||||
out = []
|
||||
for m in reversed(deps):
|
||||
if m in args.exclude:
|
||||
|
|
|
|||
|
|
@ -1,23 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdLdlibpath(Cmd): # export
|
||||
class CmdLdlibpath(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'ldlibpath', help='ldlibpath')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'ldlibpath', help = 'ldlibpath')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], [ 'run', 'build', 'devel' ],
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
['run', 'build', 'devel'],
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
out = []
|
||||
for m in deps:
|
||||
path = self.app.find_dir(m, ['/lib'])
|
||||
|
|
|
|||
|
|
@ -1,18 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdLibname(Cmd): # export
|
||||
|
||||
class CmdLibname(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'libname', help='libname')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'libname', help = 'libname')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
print(self.app.get_libname(args.module))
|
||||
|
|
|
|||
|
|
@ -1,62 +1,105 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
|
||||
import re, os
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...lib.util import get_username, get_password, run_curl
|
||||
from ...lib.log import *
|
||||
from ...lib.base import Input
|
||||
from ...lib.log import DEBUG, log
|
||||
from ...lib.Uri import Uri
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from ...lib.util import get_password, get_username, run_curl_into
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdListRepos(Cmd): # export
|
||||
class CmdListRepos(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'list-repos', help='Query a remote GIT server for repositories')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'list-repos', help = 'Query a remote GIT server for repositories'
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('base_url', help='Base URL of all Git repositories without user part')
|
||||
parser.add_argument('--username', help='Username for SSH or HTTP authentication, don\'t specify for unauthenticated', default=None)
|
||||
parser.add_argument('--askpass', help='Program to echo password for SSH or HTTP authentication, don\'t specify for unauthenticated', default=None)
|
||||
parser.add_argument('--from-owner', help='List from-owner\'s projects', default='janware')
|
||||
parser.add_argument(
|
||||
'base_url', help = 'Base URL of all Git repositories without user part'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--username',
|
||||
help = (
|
||||
"Username for SSH or HTTP authentication, don't "
|
||||
'specify for unauthenticated'
|
||||
),
|
||||
default = None,
|
||||
)
|
||||
parser.add_argument(
|
||||
'--askpass',
|
||||
help = (
|
||||
'Program to echo password for SSH or HTTP authentication, '
|
||||
"don't specify for unauthenticated"
|
||||
),
|
||||
default = None,
|
||||
)
|
||||
parser.add_argument(
|
||||
'--from-owner', help = "List from-owner's projects", default = 'janware'
|
||||
)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
|
||||
base_url = Uri(args.base_url)
|
||||
askpass_env=['GIT_ASKPASS', 'SSH_ASKPASS']
|
||||
username = await get_username(args=args, url=args.base_url, askpass_env=askpass_env)
|
||||
askpass_env = ['GIT_ASKPASS', 'SSH_ASKPASS']
|
||||
username = await get_username(
|
||||
args = args, url = args.base_url, askpass_env = askpass_env
|
||||
)
|
||||
password = None
|
||||
if username is not None:
|
||||
password = await get_password(args=args, url=args.base_url, askpass_env=askpass_env)
|
||||
password = await get_password(
|
||||
args = args, url = args.base_url, askpass_env = askpass_env
|
||||
)
|
||||
match base_url.scheme:
|
||||
case 'ssh':
|
||||
if re.match(r'ssh://.*devgit\.janware\.com/', args.base_url):
|
||||
from jw.pkg.lib.ec.SSHClient import SSHClient, ssh_client
|
||||
from jw.pkg.lib.ec.SSHClient import ssh_client
|
||||
|
||||
if username is not None:
|
||||
base_url.set_username(username)
|
||||
if password is not None:
|
||||
base_url.set_password(password)
|
||||
ssh = ssh_client(base_url, interactive=self.app.interactive, verbose_default=self.app.verbose)
|
||||
cmd = ['/opt/jw-pkg/bin/git-srv-admin.sh', '-u', args.from_owner, '-j', 'list-personal-projects']
|
||||
ssh = ssh_client(
|
||||
base_url,
|
||||
interactive = self.app.interactive,
|
||||
verbose_default = self.app.verbose,
|
||||
)
|
||||
cmd = [
|
||||
'/opt/jw-pkg/bin/git-srv-admin.sh',
|
||||
'-u',
|
||||
args.from_owner,
|
||||
'-j',
|
||||
'list-personal-projects',
|
||||
]
|
||||
result = await ssh.run(cmd)
|
||||
print('\n'.join(result.stdout.decode().splitlines()))
|
||||
print('\n'.join(result.stdout_str.splitlines()))
|
||||
return
|
||||
case 'https':
|
||||
from jw.pkg.lib.base import InputMode
|
||||
cmd_input = InputMode.NonInteractive
|
||||
|
||||
cmd_input: Input = InputMode.NonInteractive
|
||||
if re.match(r'https://github.com', args.base_url):
|
||||
curl_args = [
|
||||
'-f',
|
||||
'-H', 'Accept: application/vnd.github+json',
|
||||
'-H', 'X-GitHub-Api-Version: 2022-11-28',
|
||||
'-H',
|
||||
'Accept: application/vnd.github+json',
|
||||
'-H',
|
||||
'X-GitHub-Api-Version: 2022-11-28',
|
||||
]
|
||||
if password is not None:
|
||||
assert username is not None, f'Assertion failed: username is empty but password isn\'t for "{args.base_url}"'
|
||||
assert username is not None, (
|
||||
'Assertion failed: username is empty but password '
|
||||
'isn\'t for "{args.base_url}"'
|
||||
)
|
||||
cmd_input = (f'-u {username}:{password}').encode('utf-8')
|
||||
curl_args.extend(['-K-'])
|
||||
curl_args.append(f'https://api.github.com/users/{args.from_owner}/repos')
|
||||
repos, stderr, status = await run_curl(curl_args, cmd_input=cmd_input, parse_json=True)
|
||||
curl_args.append(
|
||||
f'https://api.github.com/users/{args.from_owner}/repos'
|
||||
)
|
||||
repos = await run_curl_into(list, curl_args, cmd_input = cmd_input)
|
||||
for repo in repos:
|
||||
print(repo['name'])
|
||||
return
|
||||
|
|
@ -69,33 +112,44 @@ class CmdListRepos(Cmd): # export
|
|||
cmd_input = (f'-u {username}:{password}').encode('utf-8')
|
||||
curl_args.extend(['-K-'])
|
||||
for entities_dir in ['orgs', 'users']:
|
||||
api_url = f'{args.base_url}/api/v1/{entities_dir}/{args.from_owner}/repos'
|
||||
api_url = (
|
||||
f'{args.base_url}/api/v1/{entities_dir}/'
|
||||
f'{args.from_owner}/repos'
|
||||
)
|
||||
try:
|
||||
tried.append(api_url)
|
||||
repos, stderr, status = await run_curl(curl_args + [api_url], cmd_input=cmd_input, parse_json=True)
|
||||
repos = await run_curl_into(
|
||||
list,
|
||||
curl_args + [api_url],
|
||||
cmd_input = cmd_input,
|
||||
)
|
||||
for repo in repos:
|
||||
print(repo['name'])
|
||||
break
|
||||
except Exception as e:
|
||||
msg = 'curl {} failed ({}), trying next'.format(
|
||||
' '.join(curl_args + [api_url]),
|
||||
str(e)
|
||||
' '.join(curl_args + [api_url]), str(e)
|
||||
)
|
||||
log(DEBUG, msg)
|
||||
tried[-1] += ': ' + msg
|
||||
raise
|
||||
else:
|
||||
raise RuntimeError(f'Failed to fetch repository list from assumed Forgejo instance at {args.base_url}, tried {', '.join(tried)}')
|
||||
raise RuntimeError(
|
||||
f'Failed to fetch repository list from assumed Forgejo '
|
||||
f'instance at {args.base_url}, tried {", ".join(tried)}'
|
||||
)
|
||||
return
|
||||
if os.path.isdir(args.base_url):
|
||||
for subdir in ["." , args.from_owner]:
|
||||
for subdir in ['.', args.from_owner]:
|
||||
out = []
|
||||
for entry in os.scandir(args.base_url + "/" + subdir):
|
||||
for entry in os.scandir(args.base_url + '/' + subdir):
|
||||
path = entry.path
|
||||
if os.path.isdir(path + "/.git") or os.path.exists(path + "/HEAD"):
|
||||
if os.path.isdir(path + '/.git') or os.path.exists(path + '/HEAD'):
|
||||
out.append(path)
|
||||
if out:
|
||||
print('\n'.join(out))
|
||||
break
|
||||
return
|
||||
raise Exception(f'Don\'t know how to enumerate Git repos at base url {args.base_url}')
|
||||
raise Exception(
|
||||
f"Don't know how to enumerate Git repos at base url {args.base_url}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,44 +1,57 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...lib.log import *
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from ...lib.log import DEBUG, log
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdModules(Cmd): # export
|
||||
class CmdModules(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'modules', help='Query existing janware packages')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'modules', help = 'Query existing janware packages')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('-F', '--filter', nargs='?', default=None, help='Key-value pairs, seperated by commas, to be searched for in project.conf')
|
||||
parser.add_argument(
|
||||
'-F',
|
||||
'--filter',
|
||||
nargs = '?',
|
||||
default = None,
|
||||
help =
|
||||
'Key-value pairs, seperated by commas, to be searched for in project.conf',
|
||||
)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import pathlib
|
||||
|
||||
proj_root = self.app.projs_root
|
||||
log(DEBUG, "proj_root = " + proj_root)
|
||||
log(DEBUG, 'proj_root = ' + proj_root)
|
||||
path = pathlib.Path(self.app.projs_root)
|
||||
modules = [p.parents[1].name for p in path.glob('*/make/project.conf')]
|
||||
log(DEBUG, "modules = ", modules)
|
||||
log(DEBUG, 'modules = ', modules)
|
||||
out = []
|
||||
filters = None if args.filter is None else [re.split("=", f) for f in re.split(",", args.filter)]
|
||||
filters = (
|
||||
None if args.filter is None else
|
||||
[re.split('=', f) for f in re.split(',', args.filter)]
|
||||
)
|
||||
for m in modules:
|
||||
if filters:
|
||||
for f in filters:
|
||||
path = f[0].rsplit('.')
|
||||
if len(path) > 1:
|
||||
sec = path[0]
|
||||
key = path[1]
|
||||
else:
|
||||
sec = None
|
||||
key = path[0]
|
||||
val = self.app.get_value(m, sec, key)
|
||||
log(DEBUG, 'Checking in {} if {}="{}", is "{}"'.format(m, f[0], f[1], val))
|
||||
if val and val == f[1]:
|
||||
out.append(m)
|
||||
break
|
||||
else:
|
||||
if not filters:
|
||||
out.append(m)
|
||||
continue
|
||||
for f in filters:
|
||||
path_str = f[0].rsplit('.')
|
||||
if len(path_str) > 1:
|
||||
sec = path_str[0]
|
||||
key = path_str[1]
|
||||
else:
|
||||
sec = None
|
||||
key = path_str[0]
|
||||
val = self.app.get_value(m, sec, key)
|
||||
log(
|
||||
DEBUG,
|
||||
'Checking in {} if {}="{}", is "{}"'.format(m, f[0], f[1], val),
|
||||
)
|
||||
if val and val == f[1]:
|
||||
out.append(m)
|
||||
break
|
||||
print(' '.join(out))
|
||||
|
|
|
|||
|
|
@ -1,26 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdPath(Cmd): # export
|
||||
class CmdPath(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'path', help='path')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'path', help = 'path')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], 'run',
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
'run',
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
out = []
|
||||
for m in deps:
|
||||
path = self.app.find_dir(m, '/bin')
|
||||
path = self.app.find_dir(m, ['/bin'])
|
||||
if path is not None:
|
||||
out.append(path)
|
||||
print(':'.join(out))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
|
||||
from .BaseCmdPkgRelations import BaseCmdPkgRelations as Base
|
||||
from .Cmd import Parent
|
||||
|
||||
class CmdPkgConflicts(Base): # export
|
||||
class CmdPkgConflicts(Base): # export
|
||||
|
||||
def __init__(self, parent: Base) -> None:
|
||||
super().__init__(parent, 'conflicts', help='Print packages conflicting with a given package')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'conflicts',
|
||||
help = 'Print packages conflicting with a given package'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
|
||||
from .BaseCmdPkgRelations import BaseCmdPkgRelations as Base
|
||||
from .Cmd import Parent
|
||||
|
||||
class CmdPkgProvides(Base): # export
|
||||
class CmdPkgProvides(Base): # export
|
||||
|
||||
def __init__(self, parent: Base) -> None:
|
||||
super().__init__(parent, 'provides', help='Print packages and capabilities provided by a given package')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'provides',
|
||||
help = 'Print packages and capabilities provided by a given package',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
|
||||
from .BaseCmdPkgRelations import BaseCmdPkgRelations as Base
|
||||
from .Cmd import Parent
|
||||
|
||||
class CmdPkgRequires(Base): # export
|
||||
class CmdPkgRequires(Base): # export
|
||||
|
||||
def __init__(self, parent: Base) -> None:
|
||||
super().__init__(parent, 'requires', help='Print packages required for a given package')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'requires', help = 'Print packages required for a given package'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from ...lib.log import WARNING, log
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ...lib.log import *
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdProjDir(Cmd): # export
|
||||
|
||||
class CmdProjDir(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'proj-dir', help='Print directory of a given package')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'proj-dir', help = 'Print directory of a given package'
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
out = []
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdPythonpath(Cmd): # export
|
||||
class CmdPythonpath(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'pythonpath', help='Generate PYTHONPATH for given modules')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'pythonpath', help = 'Generate PYTHONPATH for given modules'
|
||||
)
|
||||
|
||||
def add_arguments(self, p: ArgumentParser) -> None:
|
||||
super().add_arguments(p)
|
||||
p.add_argument('module', help='Modules', nargs='*')
|
||||
p.add_argument('module', help = 'Modules', nargs = '*')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], [ 'run', 'build' ],
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
['run', 'build'],
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
out = []
|
||||
for m in deps:
|
||||
path = self.app.find_dir(m, ['src/python', 'tools/python'])
|
||||
|
|
|
|||
|
|
@ -1,30 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
class CmdPythonpathOrig(Cmd): # export
|
||||
class CmdPythonpathOrig(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'pythonpath_orig', help='pythonpath')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'pythonpath_orig', help = 'pythonpath')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
deps = self.app.get_project_refs(args.module, ['pkg.requires.jw'], [ 'run', 'build' ],
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
deps = self.app.get_project_refs(
|
||||
args.module,
|
||||
['pkg.requires.jw'],
|
||||
['run', 'build'],
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
r = ''
|
||||
for m in deps:
|
||||
pd = self.app.find_dir(m, pretty=False)
|
||||
pd = self.app.find_dir(m, pretty = False)
|
||||
if pd is None:
|
||||
continue
|
||||
for subdir in [ 'src/python', 'tools/python' ]:
|
||||
cand = pd + "/" + subdir
|
||||
if isdir(cand):
|
||||
for subdir in ['src/python', 'tools/python']:
|
||||
cand = pd + '/' + subdir
|
||||
if os.path.isdir(cand):
|
||||
r = r + ':' + cand
|
||||
print(r[1:])
|
||||
|
|
|
|||
|
|
@ -1,45 +1,60 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Iterable
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ...App import Scope
|
||||
from ...lib.log import *
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
from ...lib.log import DEBUG, log
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
# TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations
|
||||
class CmdRequiredOsPkg(Cmd): # export
|
||||
class CmdRequiredOsPkg(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'required-os-pkg', help='List distribution packages required for a package')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'required-os-pkg',
|
||||
help = 'List distribution packages required for a package',
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('flavours', help='Dependency flavours', default='build')
|
||||
parser.add_argument('modules', nargs='*', help='Modules')
|
||||
parser.add_argument('--skip-excluded', action='store_true', default=False,
|
||||
help='Output empty prerequisite list for excluded modules')
|
||||
parser.add_argument('--quote', action='store_true', default=False,
|
||||
help='Put double quotes around each listed dependency')
|
||||
parser.add_argument('flavours', help = 'Dependency flavours', default = 'build')
|
||||
parser.add_argument('modules', nargs = '*', help = 'Modules')
|
||||
parser.add_argument(
|
||||
'--skip-excluded',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'Output empty prerequisite list for excluded modules',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--quote',
|
||||
action = 'store_true',
|
||||
default = False,
|
||||
help = 'Put double quotes around each listed dependency',
|
||||
)
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
modules = args.modules
|
||||
flavours = set(args.flavours.split(','))
|
||||
if 'build' in flavours:
|
||||
# TODO: This adds too much. Only the run dependencies of the build dependencies would be needed.
|
||||
# TODO: This adds too much. Only the run dependencies of the build
|
||||
# dependencies would be needed.
|
||||
flavours.add('run')
|
||||
if 'release' in flavours:
|
||||
flavours |= set(['run', 'devel', 'build'])
|
||||
log(DEBUG, "flavours = " + args.flavours)
|
||||
deps = self.app.get_project_refs(modules, ['pkg.requires.jw'], flavours,
|
||||
scope = Scope.Subtree, add_self=True, names_only=True)
|
||||
log(DEBUG, 'flavours = ' + args.flavours)
|
||||
deps = self.app.get_project_refs(
|
||||
modules,
|
||||
['pkg.requires.jw'],
|
||||
list(flavours),
|
||||
scope = Scope.Subtree,
|
||||
add_self = True,
|
||||
names_only = True,
|
||||
)
|
||||
if args.skip_excluded:
|
||||
for d in deps:
|
||||
if self.app.is_excluded_from_build(d) is not None:
|
||||
deps.remove(d)
|
||||
subsecs = self.app.distro.os_cascade
|
||||
log(DEBUG, "subsecs = ", subsecs)
|
||||
log(DEBUG, 'subsecs = ', subsecs)
|
||||
requires: set[str] = set()
|
||||
for sec in subsecs:
|
||||
for flavour in flavours:
|
||||
|
|
@ -47,6 +62,6 @@ class CmdRequiredOsPkg(Cmd): # export
|
|||
if vals:
|
||||
requires |= set(vals)
|
||||
if args.quote:
|
||||
requires = [f'"{dep}"' for dep in requires]
|
||||
out = [f'"{dep}"' for dep in requires]
|
||||
# TODO: add all not in build tree as -devel
|
||||
print(' '.join(requires))
|
||||
print(' '.join(out))
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdSummary(Cmd): # export
|
||||
|
||||
class CmdSummary(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'summary', help='Print summary description of given modules')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'summary', help = 'Print summary description of given modules'
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
r = []
|
||||
for m in args.module:
|
||||
summary = self.app.get_value(m, "summary", None)
|
||||
summary = self.app.get_value(m, 'summary', None)
|
||||
if summary is not None:
|
||||
r.append(summary)
|
||||
print(' '.join(r))
|
||||
|
|
|
|||
|
|
@ -1,18 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdTest(Cmd): # export
|
||||
|
||||
class CmdTest(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'test', help='Test')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'test', help = 'Test')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('blah', default='', help='The blah argument')
|
||||
parser.add_argument('blah', default = '', help = 'The blah argument')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
print("blah = " + args.blah)
|
||||
print('blah = ' + args.blah)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from argparse import Namespace, ArgumentParser
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
from ..Cmd import Cmd
|
||||
from ..CmdProjects import CmdProjects
|
||||
class CmdTmplDir(Cmd): # export
|
||||
|
||||
class CmdTmplDir(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdProjects) -> None:
|
||||
super().__init__(parent, 'tmpl-dir', help='Print directory containing templates of a given module')
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'tmpl-dir',
|
||||
help = 'Print directory containing templates of a given module',
|
||||
)
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('module', nargs='*', help='Modules')
|
||||
parser.add_argument('module', nargs = '*', help = 'Modules')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
r = []
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ __all__ = detect_modules(
|
|||
package_name = __name__,
|
||||
package_path = __path__,
|
||||
namespace = globals(),
|
||||
prefix = "Cmd",
|
||||
skip = {"Cmd"},
|
||||
) # pyright: ignore[reportUnsupportedDunderAll]
|
||||
prefix = 'Cmd',
|
||||
skip = {'Cmd'},
|
||||
) # pyright: ignore[reportUnsupportedDunderAll]
|
||||
|
|
|
|||