Commit graph

209 commits

Author SHA1 Message Date
6a5e5aaf0d jw.pkg.cmds.distro.CmdRefresh: Add command
Add CmdRefresh, the class providing the "jw-pkg.py distro refresh"
subcommand.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
d0311560da jw.pkg.cmds.distro: Add __init__.py
Add a hand-coded __init__.py into jw.pkg.cmds.distro. Auto-generation
works fine, but has to run before it can work. For a freshly
downloaded toplevel Makefile / project-dirs-minimal.mk, the targets
pkg-install-xxx-deps requires a working package manager without
jw-pkg built.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:11:09 +01:00
ad45ee8510 jw.pkg.cmds.distro: Add directory
Add the subdirectory structure for the distro subcommand.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 18:08:48 +01:00
53601c8abd jw.pkg.cmds.projects.CmdListRepos: Remove test code
Remove --insecure from curl invocation on janware.test.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 17:44:28 +01:00
4274a71c62 lib.util.run_cmd(): Rewrite it to be async
run_cmd() is synchronous. Now that all commands are asynchronous, we
can await it, so rewrite it to be asynchronous, too.

Other changes:

  - Make it return stderr as well in case its needed

  - Drop into a pseuto-tty if
    - cmd_input == "mode:interactive" or
    - cmd_input == "mode:auto" and stdin is a TTY

  - Add argument env, defaulting to None. If it's a dict, it will be
    the environment the command is run in

This entails making all functions using run_cmd() async, too,
including run_curl(), get_username() and get_password().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 17:41:40 +01:00
9c06103a4a cmds.project.*: Make _run() async
Cmd._run(), as conceived for working with lib.App, is meant to be an
async method. To be conservative about changes, jw-pkg's legacy way
of handling _run() was kept when deriving from libApp, and async was
not propagated down to the _run() implementations. This commit
rectifies that before adding additional subcommands.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 17:41:10 +01:00
f175f9d5c9 lib.Cmd: Add argument "parent" to __init__()
During __init__(), commands have no idea of their parent. This is not
a problem as of now, but is easy to fix, and it's architecturally
desirable to be prepared just in case, so add the parent argument to
the ctor before more commands are added.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-28 15:24:24 +01:00
f6ed191d73 jw.pkg.App.get_modules_from_project_txt(): Add Scope
Add the Enum "Scope" to denote the scope argument of
jw.pkg.App.get_modules_from_project_txt(), because it explains itself
better than an integer.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
bf4834085e jw.pkg.App: Annotate add_modules_from_project_txt()
Type-annotate add_modules_from_project_txt()'s parameter list.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
5cdc32abd7 jw.pkg.App: Add lru_cache where possible
ResultCache is a home-grown result cache. The @lru_cache decorator,
now available in Python 3, accomplishes the same thing, so try to
ditch ResultCache for it.

Sadly, this doesn't entirely work as of now, because it uses hash()
to hash the arguments, which won't work for the two list-type
arguments to add_modules_from_project_txt() (buf and visited).

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
a377745e5e jw.pkg.App: Make member variables private
With the exception of top_name, which cmds.project.GetVal needs
read-access to, all member variables of jw.pkg.App can be made
private.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
917f56a814 CmdBuild: Don't use App.res_cache()
App.res_cache should be private. It's needed here to cache the
results of a function which is private to CmdBuild anyway, so solve
that with lru_cache, to allow App to do it's private thing with
caching.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
eafed6434b CmdBuild: Don't use App.dep_cache
App.dep_cache is only used by CmdBuild, prepare for removing it from
App.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
95fa2f0d06 jw.pkg.App: Remove .debug() and friends
Replace the jw.pkg.App.debug(), .warn() and .err() methods by the
global log() function. There's no obvious benefit in having App know
what's logged.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
aefe983920 jw.pkg.App: Support --topdir-format
Add support for --topdir-format. The option supports several
different values, affecting the console output of App wherever it
knows that the output contains a reference to the projects' toplevel
directory.

  - "unaltered" will have it print the toplevel directory in the same
    format as passed to the commandline

  - "absolute" will try to resolve it to an absolute path before
    printing

  - make:XXX will return the make-varible $(XXX) instead

To implement this, the proj_dir() member function is turned into the
private member function __proj_dir(), and a new member function
find_dir() is supplied, with two additional parameters:
search_subdirs and search_absdirs, which will try to find an existing
directory relative to the toplevel directory of the given module, or
in the search_absdirs list, respectively.

Command modules in cmds.projects have been updated to use the new
function.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
0b83c863a2 jw.build.cmds: Move build.cmds -> cmds.projects
Reorganize the Python module structure. Placing the command classes
under jw.cmds.projects instead of jw.build.cmds will allow to add a
nested command structure, with the current commands, being mostly
related to building software, found below a "projects" toplevel
command.

Other conceivable commands could be "package" for packaging, or
"distro" for commands wrapping the distribution's package manager.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
c8c5788aeb jw.pkg.App.proj_dir(): Return absolute path
Make App.proj_dir() return an absolute path. This looks like a good
idea, because some of the $(call proj_query xxx) paths end up being
relative, because they get proj_dir()'s idea of a directory
prepended. This prohibits caching them in $(TOPDIR)/make/.cache.mk
for make benefit glorious nation of performance.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
adb9837c63 jw.pkg.App: Remove --debug option
Remove the --debug option, which is superseded by the semantically
richer --log-level debug in the base class.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
737f3986df jw.pkg.App: Use lib.log
Replace print() by log().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
1f26391452 jw.pkg.cmds.Cmd: Derive from lib.Cmd
The body of Cmd is pretty much entirely obviated by its base class.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
e39047e0dd jw.pkg.App: Derive from jw.pkg.lib.App
Derive jw.pkg.App from jw.pkg.lib.App. App.run() dissolves as follows:

  - Its sub-command invocation logic is left to the base class
  - parser.add_arguments() are moved into self._add_arguments()
  - So is handling of early-parsed arguments
  - async def _run() is reimplemented to set some member variables

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
0be02c7154 lib.App, .Cmd: Add modules
Add App and Cmd as generic base classes for multi-command
applications. The code is taken from jw-python: The exising
jw.pkg.App is very similar to the more capable jwutils.Cmds class,
so, to avoid code duplication, add it here to allow for jwutils.Cmds
and jw.pkg.App to derive from it at some point in the future.

Both had to be slightly modified to work within jw-pkg's less
equipped context, and will need futher code cleanup.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
18467a6500 lib.Types: Add module
Types is a container for types, notably classes, which are
dynamically loaded from other modules. Which modules are loaded is
based on the following criteria passed to its constructor:

  - mod_names: A list of modules to load and investigate

  - type_name_filter: A regular filter expression or None (default).
    If it's None, all types pass this filter.

  - type_filter: A list of types the returned types must match.
    Defaults to [], in which case all types pass this filter

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
f7cc364be2 lib.log: Add module
A dedicated logging module is currently provided by jw-python, but
since it's often needed also in jw-pkg, and it's relatively small and
maintainable, it seems justified to move it into jw-pkg.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
2e69639362 jw.pkg.build.lib: Move to jw.pkg.lib
In preparation of reorganizing the tree below cmds, move the lib
subdirectory a level up.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
eb2dd919a1 cmds.CmdGetval.add_arguments(): Don't use app.top_name
CmdGetval.add_arguments() uses self.app.top_name, which may or may
not be initialized at the time this runs. Not using it makes
CmdGetval's ctor safe to run in the context of App.__init__().

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-26 17:58:23 +01:00
c39c268d98 jw-projects.sh: Fix -p / --prefix help message
--prefix doesn't denote an "App Path Prefix", "Parent directory of
project source directories" decribes it better.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-20 15:04:48 +01:00
49086708e4 build.cmds.CmdListRepos: Support local repos
Make jw-projects.py list-repos support a local directory as base URL
of all git repositories, notably used by PROJECTS_DIR_REMOTE_BASE,
which can now point to a local directory.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-01-15 15:05:23 +00:00
ced42938e1 projects.mk / jw-projects.py: Support tmpl_dir && tmpls-dir
For a project to supply templates, it needs to advertise their
location. For this, the tmpl_dir make variable is added to
projects.mk. If other-project wants to get hold of some-project's
templates, it can do, e.g.:

  TEMPLATES = $(wilcard $(call tmpl_dir,some-project)/*.tmpl)

To achieve this, support for the tmpls-dir command is added to
jw-projects.py.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-12-23 11:07:37 +01:00
4ad7091159 cmds.CmdBuild: import time
import time is missing from CmdBuild, fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-28 20:18:52 +01:00
441051ea4a jw.pkg: Add Makefile
Re-add Python modules into the installed package by adding
src/python/jw/pkg/Makefile.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-28 15:34:24 +01:00
6340eeace9 Everywhere: Replace "jw_build" by "jw_pkg"
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-28 13:35:56 +01:00
9217d38964 Everywhere: Rename package "jw-build" to "jw-pkg"
jw-build doesn't stop at building software, packaging it afterwards
is also a core feature, so this commit gives the package a better
name.

The commit replaces strings s/jw-build/jw-pkg/ in text files and file
names. Fallout to the functionality is fixed, variable names are left
as they are, though. To be adjusted by later commits.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-28 13:35:56 +01:00
fc02dad92c projects-dir-minimal.mk: Default PROJECTS_DIR_REMOTE_BASE to jw-build's remote
If jw-build is already cloned, infect all other repositories with its
remote via PROJECTS_DIR_REMOTE_BASE.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 16:54:04 +01:00
f4106e9da2 build.lib.cmds.SSHClient: Fix dtor exception
SSHClient's destructor raises an exception because of broken
os.environ syntax, fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 15:48:13 +01:00
babf58e2dd build.lib.cmds.SSHClient: Finish __init_askpass()
Finish and test the __init_askpass() method, works.

__init_askpass() had never been tested. Finish it and make sure it
works.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 12:42:45 +01:00
27e9b23849 build.cmds.CmdListRepos: Support username/password authentication
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 11:29:50 +01:00
50744fc41e build.cmds.CmdListRepos: Pass -f to curl
curl exits with 0 success status, even if the server returns HTTP
401. Passing -f fixes that and has curl error out with exit code 22.
It doesn't show which error, though.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 10:56:47 +01:00
150bc97fc9 build.lib.util, build.App: Beautify exceptions
Make exceptions somewhat more readable.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 10:44:14 +01:00
9d06e0bf2e CmdGetAuthInfo: Code beautification
Fix clumsy code printing auth info.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-20 10:26:16 +01:00
e95f91aff8 CmdGetAuthInfo: Fix: Suppress user name "None"
Don't print username="None" if there's no such user

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-19 20:00:13 +01:00
f750b2cf05 CmdGetAuthInfo: Don't use non-git jw-build
Don't try to use non-git jw-build repositories to retrieve auth info.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-19 09:15:13 +01:00
bf6a83ccac build.cmds.CmdListRepos: Fix ssh://git.janware.com
A typo breaks enumeration of Git repos on git.janware.com, fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-19 08:40:24 +01:00
1187c10c86 build.cmds.GetAuthInfo: Add module
Add command get-auth-info to jw-projects.py. It is meant to retrieve
JANWARE_USER from an already cloned jw-build tree.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-19 08:14:43 +01:00
d484749b79 cmds.CmdListRepos: Don't import from lib
Don't directly import from lib (i.e. from __init__.py), because that
won't work until "make all" has not run through, i.e. during fresh
checkout.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-18 20:09:23 +01:00
9b85b3e8a6 build.cmds.CmdListRepos: Add module
Add the command list-repos to jw-projects.py. It is meant to do the
same thing as "git-srv-adm.sh list-personal-projects", i.e. enumerate
remote Git repositories, but also support additional servers and
protocols.  As of this commit, support for https://github.com and for
forgejo installations over HTTPS is implemented.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-18 12:56:14 +01:00
b5ab0a3d26 build.lib.SSHClient: Add module
SSHClient(hostname) is an abstract class for SSH / SCP operations. It
comes with two implementations, SSHClientInternal an SSHClientCmd.
The former needs paramiko installed, which might be a reason to fail
on unprepared systems, the latter is slower and more limited.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-18 12:11:31 +01:00
9f15868dd4 build.lib.utils: Add module
Add some utility functions, namely:

  run_cmd(cmd: list[str], wd=None, throw=True, verbose=False) -> str|None
  run_curl(args: list[str], parse_json: bool=True) -> dict|str
  get_username(args: Namespace|None=None, url: str|None=None) -> str
  get_password(args: Namespace|None=None, url: str|None=None, askpass_env: list[str]=[]) -> str

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-18 12:07:02 +01:00
bc2033490f jw.build.lib: Add module
Add jw.build.lib as a location for generic utility modules.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-18 12:05:58 +01:00
a863bb9747 jw.build.App: Unroll run_from_cmd_module()
run_from_cmd_module() is a helper function used to allow command
selection alongside the legacy and now obsolete method. Unrolling it
is a step towards adding proper argparse subparsers, so do that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-11-18 15:42:16 +01:00