-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ext-source-type
- Loading branch information
Showing
12 changed files
with
287 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# ivpm | ||
IP and Verification Package Manager | ||
# IP and Verification Package Manager (IVPM) | ||
|
||
IVPM is a Python- and Git-centric utility for managing external | ||
project dependencies. It was initially designed to manage dependencies | ||
for hardware design projects, but has been used on a variety of other | ||
project styles including purely-software projects. | ||
|
||
You can find more detailed documentation on IVPM here: [IVPM docs](https://fvutils.github.io/ivpm) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import sys | ||
import dataclasses as dc | ||
import subprocess | ||
from ivpm.project_info_reader import ProjectInfoReader | ||
from ivpm.utils import fatal | ||
|
||
@dc.dataclass | ||
class CmdActivate(object): | ||
|
||
def __call__(self, args): | ||
if args.project_dir is None: | ||
# If a default is not provided, use the current directory | ||
# print("Note: project_dir not specified ; using working directory") | ||
args.project_dir = os.getcwd() | ||
|
||
proj_info = ProjectInfoReader(args.project_dir).read() | ||
|
||
if proj_info is None: | ||
fatal("Failed to locate IVPM meta-data (eg ivpm.yaml)") | ||
|
||
packages_dir = os.path.join(args.project_dir, "packages") | ||
if not os.path.isdir(packages_dir): | ||
fatal("No packages directory ; must run ivpm update first") | ||
|
||
python_dir = os.path.join(packages_dir, "python") | ||
if not os.path.isdir(python_dir): | ||
fatal("No packages/python directory ; must run ivpm update first") | ||
|
||
activate = os.path.join(python_dir, "bin/activate") | ||
|
||
# TODO: consider non-bash shells and non-Linux platforms | ||
shell = getattr(os.environ, "SHELL", "bash") | ||
cmd = None | ||
if shell.find("bash") != -1: | ||
cmd = [shell, "-rcfile", activate] | ||
|
||
if args.c is not None: | ||
cmd.extend(["-c", args.c]) | ||
|
||
cmd.extend(args.args) | ||
|
||
env = os.environ.copy() | ||
env["IVPM_PROJECT"] = args.project_dir | ||
env["IVPM_PACKAGES"] = os.path.join(args.project_dir, "packages") | ||
# env["VIRTUAL_ENV_DISABLE_PROMPT"] = "1" | ||
|
||
# PS1 = getattr(env, "PS1", None) | ||
# print("PS1: %s" % str(PS1)) | ||
# if PS1 is not None: | ||
# PS1 = "(ivpm) %s" % PS1 | ||
# else: | ||
# PS1 = "\\[\\](ivpm) " | ||
# env["PS1"] = PS1 | ||
|
||
for es in proj_info.env_settings: | ||
es.apply(env) | ||
|
||
result = subprocess.run( | ||
cmd, | ||
env=env) | ||
sys.exit(result.returncode) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#**************************************************************************** | ||
#* env_spec.py | ||
#* | ||
#* Copyright 2023 Matthew Ballance and Contributors | ||
#* | ||
#* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
#* not use this file except in compliance with the License. | ||
#* You may obtain a copy of the License at: | ||
#* | ||
#* http://www.apache.org/licenses/LICENSE-2.0 | ||
#* | ||
#* Unless required by applicable law or agreed to in writing, software | ||
#* distributed under the License is distributed on an "AS IS" BASIS, | ||
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
#* See the License for the specific language governing permissions and | ||
#* limitations under the License. | ||
#* | ||
#* Created on: | ||
#* Author: | ||
#* | ||
#**************************************************************************** | ||
import sys | ||
import enum | ||
from typing import Any, Dict | ||
|
||
class EnvSpec(object): | ||
|
||
class Act(enum.Enum): | ||
Set = enum.auto() | ||
Path = enum.auto() | ||
PathAppend = enum.auto() | ||
PathPrepend = enum.auto() | ||
|
||
def __init__(self, | ||
var : str, | ||
val : Any, | ||
act : 'EnvSpec.Act'): | ||
self.var = var | ||
self.val = val | ||
self.act = act | ||
|
||
def apply(self, env : Dict[str,str]): | ||
if isinstance(self.val, list): | ||
for i,v in enumerate(self.val): | ||
self.val[i] = self.expand(v, env) | ||
else: | ||
self.val = self.expand(self.val, env) | ||
|
||
if self.act == EnvSpec.Act.Set: | ||
val = self.val | ||
if isinstance(val, list): | ||
val = " ".join(val) | ||
env[self.var] = val | ||
elif self.act == EnvSpec.Act.Path: | ||
val = self.val | ||
if isinstance(val, list): | ||
val = ":".join(val) | ||
env[self.var] = val | ||
elif self.act == EnvSpec.Act.PathAppend: | ||
val = self.val | ||
if isinstance(val, list): | ||
val = ":".join(val) | ||
if self.var in env.keys(): | ||
env[self.var] = env[self.var] + ":" + val | ||
else: | ||
env[self.var] = val | ||
elif self.act == EnvSpec.Act.PathPrepend: | ||
val = self.val | ||
if isinstance(val, list): | ||
val = ":".join(val) | ||
if self.var in env.keys(): | ||
env[self.var] = val + ":" + env[self.var] | ||
else: | ||
env[self.var] = val | ||
else: | ||
raise Exception("Unknown action: %s" % str(self.act)) | ||
|
||
def expand(self, var, env): | ||
idx = 0 | ||
while idx < len(var): | ||
idx1 = var.find('${', idx) | ||
|
||
if idx1 == -1: | ||
break | ||
idx2 = var.find('}', idx1) | ||
if idx2 == -1: | ||
idx = idx1+2 | ||
else: | ||
key = var[idx1+2:idx2] | ||
if key in env.keys(): | ||
var = var[:idx1] + env[key] + var[idx2+1:] | ||
else: | ||
idx = idx2+1 | ||
return var | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import os | ||
import subprocess | ||
from .project_info_reader import ProjectInfoReader | ||
|
||
|
||
def ivpm_popen(cmd, **kwargs): | ||
""" | ||
Wrapper around subprocess.Popen that configures paths from | ||
the nearest IVPM project. | ||
""" | ||
ivpm_project = getattr(kwargs, "ivpm_project", None) | ||
|
||
if ivpm_project is None: | ||
# Search up from the invocation location | ||
cwd = os.getcwd() | ||
while cwd is not None and cwd != "/" and ivpm_project is None: | ||
if os.path.exists(os.path.join(cwd, "ivpm.yaml")): | ||
ivpm_project = cwd | ||
else: | ||
cwd = os.path.dirname(cwd) | ||
|
||
if ivpm_project is not None: | ||
# Update environment variables | ||
proj_info = ProjectInfoReader(ivpm_project).read() | ||
|
||
if proj_info is None: | ||
raise Exception("Failed to read ivpm.yaml @ %s" % ivpm_project) | ||
|
||
env = getattr(kwargs, "env", os.environ.copy()) | ||
env["IVPM_PROJECT"] = ivpm_project | ||
env["IVPM_PACKAGES"] = os.path.join(ivpm_project, "packages") | ||
|
||
# Add the virtual-environment path | ||
if "PATH" in env.keys(): | ||
env["PATH"] = os.path.join(ivpm_project, "packages/python/bin") + ":" + env["PATH"] | ||
else: | ||
env["PATH"] = os.path.join(ivpm_project, "packages/python/bin") | ||
|
||
for es in proj_info.env_settings: | ||
es.apply(env) | ||
|
||
kwargs["env"] = env | ||
|
||
return subprocess.Popen(cmd, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.