Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wallento committed May 12, 2021
0 parents commit ed7d266
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*/version.py
.eggs
*.egg-info
__pycache__add
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EDA Container Wrapper
=====================
Empty file added edacontainerwrapper/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions edacontainerwrapper/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import argparse
import os
import sys

from .run import run, RunArguments, RunArgumentsDefaults, tools

def main():
if os.path.basename(sys.argv[0]) == "eda-container-wrapper":
parser = argparse.ArgumentParser()
parser.add_argument('--split-cwd-tail', type=int, default=RunArgumentsDefaults.split_cwd_tail)
parser.add_argument('--tool-version')
parser.add_argument('tool', choices=tools.keys())
parser.add_argument('toolargs', nargs='*')
args = parser.parse_args()
tool = args.tool
toolargs = args.toolargs
args = RunArguments(
split_cwd_tail = args.split_cwd_tail,
tool_version = args.tool_version if args.tool_version else tools[tool].default_version
)
else:
tool = sys.argv[0]
args = RunArguments(split_cwd_tail=0)
toolargs = sys.argv[1:]

run(tool, args, toolargs)

if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions edacontainerwrapper/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys
import subprocess
from collections import namedtuple
import os

RunArguments = namedtuple("RunArguments", "split_cwd_tail tool_version")
RunArgumentsDefaults = RunArguments(split_cwd_tail=0, tool_version=None)

def split_path(path, depth):
base = path
tail = ""
for d in range(depth):
base, t = os.path.split(base)
tail = os.path.join(t, tail)
return (base, tail)

ToolContainer = namedtuple("Toolcontainer", "image projectpath default_version")

tools = {
"verilator": ToolContainer(
image="verilator/verilator",
projectpath="/work",
default_version="latest"),
"openlane": ToolContainer(
image="edalize/openlane-sky130",
projectpath="/project",
default_version="v0.12")
}

def run(toolname, args, toolargs):
if toolname not in tools:
raise RuntimeError(f"Unknown Tool: {toolname}")

tool = tools[toolname]

version = os.getenv("TOOL_VERSION", args.tool_version)

root, tail = split_path(os.getcwd(), int(os.getenv("SPLIT_CWD_TAIL", args.split_cwd_tail)))
workdir = os.path.join(tool.projectpath, tail)

cmd = ["docker", "run", "-ti",
"-v", f"{root}:{tool.projectpath}",
"-u", f"{os.getuid()}:{os.getgid()}",
"-w", f"{workdir}",
f"{tool.image}:{version}"
] + toolargs

return subprocess.call(" ".join(cmd), shell=True)
31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup, find_packages
import pathlib

here = pathlib.Path(__file__).parent.resolve()

long_description = (here / 'README.md').read_text(encoding='utf-8')

setup(
name='eda-container-wrapper',
description="Synchronize ICS to Exchange",
packages=["edacontainerwrapper"],
use_scm_version={
"relative_to": __file__,
"write_to": "edacontainerwrapper/version.py",
},
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/librecores/eda-container-wrapper',
author="Stefan Wallentowitz",
author_email='[email protected]',
classifiers=[
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
"Topic :: Utilities",
],
entry_points={"console_scripts": ["eda-container-wrapper = edacontainerwrapper.main:main"]},
setup_requires=[
"setuptools_scm",
],
install_requires=[
]
)

0 comments on commit ed7d266

Please sign in to comment.