Skip to content

Commit

Permalink
Tweaks to new plug-in scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <[email protected]>
  • Loading branch information
mballance committed Oct 23, 2024
1 parent 6afe542 commit 7198c20
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 28 deletions.
5 changes: 5 additions & 0 deletions src/ivpm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
from .utils import load_project_package_info
import ivpm.setup

from .package import Package
from .package_factory import PackageFactory
from .package_factory_rgy import PackageFactoryRgy
from .update_info import UpdateInfo

def get_pkg_version(setup_py_path):
"""Returns the package version based on the etc/ivpm.info file"""
rootdir = os.path.dirname(os.path.realpath(setup_py_path))
Expand Down
29 changes: 27 additions & 2 deletions src/ivpm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def fetch_file(



def get_parser():
def get_parser(parser_ext = None):
"""Create the argument parser"""
parser = argparse.ArgumentParser(prog="ivpm")

Expand Down Expand Up @@ -230,10 +230,35 @@ def get_parser():
snapshot_cmd.add_argument("snapshot_dir",
help="Specifies the directory where the snapshot will be created")

if parser_ext is not None:
for ext in parser_ext:
ext(subparser)

return parser

def main(project_dir=None):
parser = get_parser()

# First things first: load any extensions
import sys
if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points

discovered_plugins = entry_points(group='ivpm.ext')
parser_ext = []
for p in discovered_plugins:
try:
mod = p.load()
if hasattr(mod, "ivpm_subcommand"):
parser_ext.append(getattr(mod, "ivpm_subcommand"))
except Exception as e:
print("Error: caught exception while loading IVPM extension %s (%s)" %(
p.name,
str(e)))
raise e

parser = get_parser(parser_ext)

args = parser.parse_args()

Expand Down
2 changes: 1 addition & 1 deletion src/ivpm/cmds/cmd_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __call__(self, args):
args.project_dir,
dep_set=ds_name,
anonymous=args.anonymous
)
).update()


# with open(os.path.join(packages_dir, "sve.F"), "w") as fp:
Expand Down
4 changes: 4 additions & 0 deletions src/ivpm/ivpm_yaml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def read(self, fp, name) -> ProjInfo:
else:
ret.version = None

if "deps-dir" in pkg.keys():
ret.deps_dir = pkg["deps-dir"]


if "deps" in pkg.keys() or "dev-deps" in pkg.keys():
# old-style format
print("Note: Package %s uses old-style ivpm.yaml format" % ret.name)
Expand Down
2 changes: 1 addition & 1 deletion src/ivpm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build(self, pkgs_info):
def update(self, update_info : UpdateInfo) -> 'ProjInfo':
from .project_info_reader import ProjectInfoReader
info = ProjectInfoReader(
os.path.join(update_info.packages_dir, self.name)).read()
os.path.join(update_info.deps_dir, self.name)).read()

return info

Expand Down
2 changes: 1 addition & 1 deletion src/ivpm/package_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update(self, update_info : UpdateInfo):
src_path,
self.name
))
dst_path = os.path.join(update_info.packages_dir, self.name)
dst_path = os.path.join(update_info.deps_dir, self.name)

if os.path.isdir(dst_path):
note("Destination directory for %s exists ... skipping copy" % self.name)
Expand Down
2 changes: 1 addition & 1 deletion src/ivpm/package_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PackageFile(PackageURL):
def update(self, update_info : UpdateInfo) -> ProjInfo:
from .project_info_reader import ProjectInfoReader

pkg_dir = os.path.join(update_info.packages_dir, self.name)
pkg_dir = os.path.join(update_info.deps_dir, self.name)
self.path = pkg_dir.replace("\\", "/")

# Install (unpack) the file
Expand Down
8 changes: 4 additions & 4 deletions src/ivpm/package_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PackageGit(Package):
anonymous : bool = None

def update(self, update_info : UpdateInfo):
pkg_dir = os.path.join(update_info.packages_dir, self.name)
pkg_dir = os.path.join(update_info.deps_dir, self.name)
self.path = pkg_dir.replace("\\", "/")

if os.path.exists(pkg_dir):
Expand All @@ -45,7 +45,7 @@ def update(self, update_info : UpdateInfo):
note("loading package %s" % self.name)

cwd = os.getcwd()
os.chdir(update_info.packages_dir)
os.chdir(update_info.deps_dir)
sys.stdout.flush()

git_cmd = ["git", "clone"]
Expand Down Expand Up @@ -87,7 +87,7 @@ def update(self, update_info : UpdateInfo):

# Checkout a specific commit
if self.commit is not None:
os.chdir(os.path.join(self.packages_dir, self.name))
os.chdir(os.path.join(self.deps_dir, self.name))
git_cmd = "git reset --hard %s" % self.commit
status = os.system(git_cmd)

Expand All @@ -97,7 +97,7 @@ def update(self, update_info : UpdateInfo):


# TODO: Existence of .gitmodules should trigger this
os.chdir(os.path.join(update_info.packages_dir, self.name))
os.chdir(os.path.join(update_info.deps_dir, self.name))
sys.stdout.flush()
status = os.system("git submodule update --init --recursive")
os.chdir(cwd)
Expand Down
18 changes: 9 additions & 9 deletions src/ivpm/package_handler_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def update(self, update_info : UpdateInfo):
setup_deps_pkgs.append(pkgs_info[dep])

requirements_path = os.path.join(
update_info.packages_dir, "python_pkgs_%d.txt" % (
update_info.deps_dir, "python_pkgs_%d.txt" % (
len(python_requirements_paths)+1))
self._write_requirements_txt(
update_info.packages_dir,
update_info.deps_dir,
setup_deps_pkgs,
requirements_path)
python_requirements_paths.append(requirements_path)
Expand All @@ -162,11 +162,11 @@ def update(self, update_info : UpdateInfo):

if len(python_pkgs) > 0:
requirements_path = os.path.join(
update_info.packages_dir, "python_pkgs_%d.txt" % (
update_info.deps_dir, "python_pkgs_%d.txt" % (
len(python_requirements_paths)+1))

self._write_requirements_txt(
update_info.packages_dir,
update_info.deps_dir,
python_pkgs,
requirements_path)
python_requirements_paths.append(requirements_path)
Expand Down Expand Up @@ -197,9 +197,9 @@ def update(self, update_info : UpdateInfo):

if len(python_pkgs):
requirements_path = os.path.join(
packages_dir, "python_pkgs_%d.txt" % (len(python_requirements_paths)+1))
deps_dir, "python_pkgs_%d.txt" % (len(python_requirements_paths)+1))
self._write_requirements_txt(
packages_dir,
deps_dir,
python_pkgs,
requirements_path)
python_requirements_paths.append(requirements_path)
Expand All @@ -214,12 +214,12 @@ def update(self, update_info : UpdateInfo):
note("Installing Python dependencies in %d phases" % len(python_requirements_paths))
for reqfile in python_requirements_paths:
cwd = os.getcwd()
os.chdir(os.path.join(packages_dir))
os.chdir(os.path.join(deps_dir))
cmd = [
get_venv_python(os.path.join(packages_dir, "python")),
get_venv_python(os.path.join(deps_dir, "python")),
"-m",
"ivpm.pywrap",
get_venv_python(os.path.join(packages_dir, "python")),
get_venv_python(os.path.join(deps_dir, "python")),
"-m",
"pip",
"install",
Expand Down
7 changes: 4 additions & 3 deletions src/ivpm/package_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@
import dataclasses as dc
from .package_file import PackageFile
from .update_info import UpdateInfo
from .package import SourceType2Ext

class PackageHttp(PackageFile):

def update(self, update_info : UpdateInfo):
pkg_dir = os.path.join(update_info.packages_dir, self.name)
pkg_dir = os.path.join(update_info.deps_dir, self.name)
self.path = pkg_dir.replace("\\", "/")

# Need to fetch, then unpack these
download_dir = os.path.join(update_info.packages_dir, ".download")
download_dir = os.path.join(update_info.deps_dir, ".download")

if not os.path.isdir(download_dir):
os.makedirs(download_dir)

# if pkg.src_type not in SourceType2Ext.keys():
# fatal("Unsupported source-type %s for package %s" % (str(pkg.src_type), pkg.name))
filename = self.name + SourceType2Ext[pkg.src_type]
filename = self.name + SourceType2Ext[self.src_type]

pkg_path = os.path.join(download_dir, filename)

Expand Down
8 changes: 4 additions & 4 deletions src/ivpm/package_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self,
anonymous_git=False,
load=True):
self.debug = False
self.packages_dir = packages_dir
self.deps_dir = packages_dir
self.all_pkgs = PackagesInfo("root")
self.new_deps = []
self.anonymous_git = anonymous_git
Expand Down Expand Up @@ -114,14 +114,14 @@ def _update_pkg(self, pkg : Package) -> ProjInfo:
"""Loads a single package. Returns any dependencies"""
must_update=False

update_info = UpdateInfo(self.packages_dir)
update_info = UpdateInfo(self.deps_dir)

print("********************************************************************")
print("* Processing package %s" % pkg.name)
print("********************************************************************")


pkg_dir = os.path.join(self.packages_dir, pkg.name)
pkg_dir = os.path.join(self.deps_dir, pkg.name)
pkg.path = pkg_dir.replace("\\", "/")

info = pkg.update(update_info)
Expand Down Expand Up @@ -169,7 +169,7 @@ def _update_pkg(self, pkg : Package) -> ProjInfo:
# check what we have
if pkg.pkg_type == PackageType.Unknown:
for py in ("setup.py", "pyproject.toml"):
if os.path.isfile(os.path.join(self.packages_dir, pkg.name, py)):
if os.path.isfile(os.path.join(self.deps_dir, pkg.name, py)):
pkg.pkg_type = PackageType.Python
break

Expand Down
3 changes: 3 additions & 0 deletions src/ivpm/proj_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ def __init__(self, is_src):

self.ivpm_info = {}
self.requirements_txt = None

self.name = None
self.version = None
self.deps_dir = "packages"

self.process_deps = True
self.paths : Dict[str, Dict[str, List[str]]] = {}

Expand Down
2 changes: 1 addition & 1 deletion src/ivpm/project_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def update(self):
if proj_info is None:
fatal("Failed to locate IVPM meta-data (eg ivpm.yaml)")

packages_dir = os.path.join(self.root_dir, "packages")
packages_dir = os.path.join(self.root_dir, proj_info.deps_dir)

# Ensure that we have a python virtual environment setup
if not self.skip_venv:
Expand Down
2 changes: 1 addition & 1 deletion src/ivpm/update_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@dc.dataclass
class UpdateInfo(object):
packages_dir : str
deps_dir : str
anonymous_git : bool = False


0 comments on commit 7198c20

Please sign in to comment.