Skip to content

Commit

Permalink
final tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <[email protected]>
  • Loading branch information
mballance committed Oct 24, 2024
1 parent d5ac865 commit 4e91daf
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 192 deletions.
25 changes: 0 additions & 25 deletions src/ivpm/cmds/cmd_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,5 @@ def __call__(self, args):
# SveFilelistWriter(OutWrapper(fp)).write(pkgs_info)


# def _write_requirements_txt(self,
# packages_dir,
# python_pkgs : List[Package],
# file):
# with open(file, "w") as fp:
# for pkg in python_pkgs:

# if pkg.url is not None:
# # Editable package
# # fp.write("-e file://%s/%s#egg=%s\n" % (
# # packages_dir.replace("\\","/"),
# # pkg.name,
# # pkg.name))
# fp.write("-e %s/%s\n" % (
# packages_dir.replace("\\","/"),
# pkg.name))
# else:
# # PyPi package
# if pkg.version is not None:
# if pkg.version[0] in ['<','>','=']:
# fp.write("%s%s\n" % (pkg.name, pkg.version))
# else:
# fp.write("%s==%s\n" % (pkg.name, pkg.version))
# else:
# fp.write("%s\n" % pkg.name)


2 changes: 1 addition & 1 deletion src/ivpm/ivpm_yaml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import yaml_srcinfo_loader
from yaml_srcinfo_loader.srcinfo import SrcInfo
from .package_factory_rgy import PackageFactoryRgy
from .package_factory import PackageFactory
from .package import Package

Expand Down Expand Up @@ -115,6 +114,7 @@ def read_dep_sets(self, info : ProjInfo, dep_sets):


def read_deps(self, ret : PackagesInfo, deps):
from .package_factory_rgy import PackageFactoryRgy

for d in deps:
si = d.srcinfo
Expand Down
6 changes: 4 additions & 2 deletions src/ivpm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,24 @@ class SourceType(Enum):
@dc.dataclass
class Package(object):
"""Contains leaf-level information about a single package"""

name : str
srcinfo : object = None
path : str = None
pkg_type : PackageType = None
src_type : str = None

process_deps : bool = True
setup_deps : Set = dc.field(default_factory=set)
setup_deps : Set[str] = dc.field(default_factory=set)
dep_set : str = "default"
proj_info : 'ProjInfo'= None

def build(self, pkgs_info):
pass

def update(self, update_info : UpdateInfo) -> 'ProjInfo':
from .project_info_reader import ProjectInfoReader
from .proj_info import ProjInfo

info = ProjectInfoReader(
os.path.join(update_info.deps_dir, self.name)).read()

Expand Down
6 changes: 0 additions & 6 deletions src/ivpm/package_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ def process_options(self, p : Package, d : Dict, si):
type_s, getlocstr(d["type"])))

p.pkg_type = Spec2PackageType[type_s]
else:
# if url is None and pkg.src_type != SourceType.PyPi:
# fatal("no type specified for package %s and no URL specified" % pkg.name)
# else:
# # We'll need to auto-probe later once we have source
p.pkg_type = PackageType.Unknown

def create(self, name, opts, si) -> Package:
p = Package(name)
Expand Down
27 changes: 27 additions & 0 deletions src/ivpm/package_factory_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,40 @@
#* Author:
#*
#****************************************************************************
import os
from typing import Dict
from .package_factory_url import PackageFactoryURL
from .package_file import PackageFile

class PackageFactoryFile(PackageFactoryURL):
src = "file"
description = "Core fetch fetcher"

def process_options(self, p: PackageFile, d: Dict, si):
super().process_options(p, d, si)


if "src" in d.keys():
p.src_type = d["src"]
else:
ext = os.path.splitext(p.url)
if ext == ".tgz":
p.src_type = ".tar.gz"
else:
p.src_type = os.path.splitext(p.url)[1]
if p.src_type in [".gz", ".xz", ".bz2"]:
pdot = p.url.rfind('.')
pdot = p.url.rfind('.', 0, pdot-1)
p.src_type = p.url[pdot:]

if "unpack" in d.keys():
p.unpack = d["unpack"]
else:
if p.src_type in [".jar"]:
p.unpack = False
else:
p.unpack = True

def create(self, name, opts, si) -> PackageFile:
p = PackageFile(name)
self.process_options(p, opts, si)
Expand Down
4 changes: 2 additions & 2 deletions src/ivpm/package_factory_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#*
#****************************************************************************
from ivpm.package import Package
from .package_factory_url import PackageFactoryURL
from .package_factory_file import PackageFactoryFile
from .package_http import PackageHttp

class PackageFactoryHttp(PackageFactoryURL):
class PackageFactoryHttp(PackageFactoryFile):
src = "http"
description = "HTTP fetcher"

Expand Down
3 changes: 2 additions & 1 deletion src/ivpm/package_factory_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class PackageFactoryPyPi(PackageFactory):

def process_options(self, p: Package, d: Dict, si):
super().process_options(p, d, si)
p.src_type = PackageFactoryPyPi.src

if "version" in d.keys():
p = d["version"]
p.version = d["version"]

def create(self, name, opts, si) -> PackagePyPi:
p = PackagePyPi(name)
Expand Down
56 changes: 28 additions & 28 deletions src/ivpm/package_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

@dc.dataclass
class PackageFile(PackageURL):
unpack : bool = None

def update(self, update_info : UpdateInfo) -> ProjInfo:
from .project_info_reader import ProjectInfoReader
Expand All @@ -44,39 +45,38 @@ def update(self, update_info : UpdateInfo) -> ProjInfo:
info : ProjInfo = ProjectInfoReader(pkg_dir).read()

return info

def _install(self, pkg_src, pkg_path):
if self.src_type in (".tar.gz", ".tar.xz", ".tar.bz2"):
self._install_tgz(pkg_src, pkg_path)
elif self.src_type in (".jar", ".zip"):
self._install_zip(pkg_src, pkg_path)
else:
raise Exception("Unsupported src_type: %s" % self.src_type)

def _install_tgz(self, pkg, pkg_path):
def _install_tgz(self, pkg_src, pkg_path):
cwd = os.getcwd()
os.chdir(self.packages_dir)
try:
os.chdir(os.path.dirname(pkg_path))

tf = tarfile.open(pkg_path)

for fi in tf:
if fi.name.find("/") != -1:
fi.name = fi.name[fi.name.find("/")+1:]
tf.extract(fi, path=pkg.name)
tf.close()
tf = tarfile.open(pkg_src)

os.chdir(cwd)
for fi in tf:
if fi.name.find("/") != -1:
fi.name = fi.name[fi.name.find("/")+1:]
tf.extract(fi, path=os.path.basename(pkg_path))
tf.close()
finally:
os.chdir(cwd)

def _install_zip(self, pkg, pkg_path):
ext = os.path.splitext(pkg.name)[1]

if ext == "":
if self.debug:
print("_install_zip: %s %s" % (str(pkg), str(pkg_path)))
def _install_zip(self, pkg_src, pkg_path):
cwd = os.getcwd()
os.chdir(self.packages_dir)
sys.stdout.flush()
with ZipFile(pkg_path, 'r') as zipObj:
zipObj.extractall(pkg.name)
os.chdir(cwd)
else:
# Copy the .zip file to the destination
if self.debug:
print("_install_zip: copy file")
shutil.copyfile(
pkg_path,
os.path.join(self.packages_dir, pkg.name))
try:
os.chdir(os.path.dirname(pkg_path))
sys.stdout.flush()
with ZipFile(pkg_src, 'r') as zipObj:
zipObj.extractall(os.path.basename(pkg_path))
finally:
os.chdir(cwd)


16 changes: 11 additions & 5 deletions src/ivpm/package_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import subprocess
import dataclasses as dc
from .package import Package
from .proj_info import ProjInfo
from .project_info_reader import ProjectInfoReader
from .update_info import UpdateInfo
from .utils import note, fatal

Expand All @@ -35,7 +37,7 @@ class PackageGit(Package):
depth : str = None
anonymous : bool = None

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

Expand Down Expand Up @@ -97,9 +99,13 @@ def update(self, update_info : UpdateInfo):


# TODO: Existence of .gitmodules should trigger this
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)
if os.path.isfile(os.path.join(update_info.deps_dir, self.name, ".gitmodules")):
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)

proj_info = ProjectInfoReader(pkg_dir).read()
return proj_info


Loading

0 comments on commit 4e91daf

Please sign in to comment.