Skip to content

Commit

Permalink
format code using black
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Apr 21, 2022
1 parent 0ec63f8 commit 0ffbb0f
Show file tree
Hide file tree
Showing 406 changed files with 11,955 additions and 9,853 deletions.
1 change: 0 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ tag = True
[bumpversion:file:./docs/conf.py]
[bumpversion:file:./README.md]
[bumpversion:file:OpenFASoC/__init__.py]

18 changes: 15 additions & 3 deletions .github/scripts/dependencies/get_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,40 @@
import sys
import subprocess


def get_tag():
tag = None

try:
tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]).decode("utf8").strip()
tag = (
subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"])
.decode("utf8")
.strip()
)
except Exception as e:
pass

if tag is None:
try:
tag = open("./resolved_version").read()
except:
print("Please input the version of OpenLane you'd like to pull: ", file=sys.stderr)
print(
"Please input the version of OpenLane you'd like to pull: ",
file=sys.stderr,
)
try:
tag = input()
with open("./resolved_version", "w") as f:
f.write(tag)
except EOFError:
print("Could not resolve the version of OpenLane being used. This is a critical error.", file=sys.stderr)
print(
"Could not resolve the version of OpenLane being used. This is a critical error.",
file=sys.stderr,
)
exit(-1)

return tag


if __name__ == "__main__":
print(get_tag(), end="")
30 changes: 20 additions & 10 deletions .github/scripts/get_docker_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@
import subprocess
from enum import Enum


class Engine(Enum):
docker = 0b0000

misc_conmon = 0b1000
podman = 0b1001


def get_docker_config():
engine = Engine.docker

uid = subprocess.check_output([ "id", "-u", getpass.getuser() ]).decode("utf8").strip()
gid = subprocess.check_output([ "id", "-g", getpass.getuser() ]).decode("utf8").strip()
uid = (
subprocess.check_output(["id", "-u", getpass.getuser()]).decode("utf8").strip()
)
gid = (
subprocess.check_output(["id", "-g", getpass.getuser()]).decode("utf8").strip()
)

try:
info = ""
try:
info = subprocess.check_output([ "docker", "info", "--format", "{{json .}}"]).decode("utf8")
info = subprocess.check_output(
["docker", "info", "--format", "{{json .}}"]
).decode("utf8")
except:
raise Exception("Could not execute docker info.")

Expand All @@ -46,28 +54,29 @@ def get_docker_config():
except:
raise Exception("Docker info was not valid JSON.")


if info.get("host") is not None and info["host"].get("conmon") is not None:
engine = Engine.misc_conmon
if info["host"].get("remoteSocket") is not None and "podman" in info["host"]["remoteSocket"]["path"]:
if (
info["host"].get("remoteSocket") is not None
and "podman" in info["host"]["remoteSocket"]["path"]
):
engine = Engine.podman
elif info.get("Name") is not None:
elif info.get("Name") is not None:
engine = Engine.docker
rootless = False
sec_info = info.get("SecurityOptions")
sec_info = info.get("SecurityOptions")

for o in sec_info:

if "rootless" in o:
rootless = True
break

if rootless:
return "-u 0"


if engine == Engine.docker:
raise Exception("") # Output UID/GID Info
raise Exception("") # Output UID/GID Info

# Else, print nothing… Podman (and possibly other conmon-based solutions) do not handle the -u options in a similar manner.
return ""
Expand All @@ -77,5 +86,6 @@ def get_docker_config():

return f"--user {uid}:{gid}"


if __name__ == "__main__":
print(get_docker_config(), end="")
76 changes: 36 additions & 40 deletions .github/scripts/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
# 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.
import os
import re
import os
import subprocess
from types import SimpleNamespace


def export_env_default(key, value):
with open(os.getenv("GITHUB_ENV"), "a") as f:
f.write("%s=%s\n" % (key, value))


export_env = export_env_default


class Repo(object):
def __init__(self, name, url, branch_rx=None, extraction_rx=None):
print("[Repo Object] Initializing repo %s with URL %s…" % (name, url))
Expand All @@ -40,11 +42,7 @@ def __init__(self, name, url, branch_rx=None, extraction_rx=None):
def latest_commit(self):
if self._latest_commit is None:
print("[Repo Object] Fetching latest commit for %s…" % self.name)
p = subprocess.check_output([
"git",
"ls-remote",
self.url
]).decode("utf8")
p = subprocess.check_output(["git", "ls-remote", self.url]).decode("utf8")
for line in p.split("\n"):
if "HEAD" in line:
self._latest_commit = line[:40]
Expand All @@ -54,9 +52,9 @@ def latest_commit(self):
def branches(self):
if self._branches is None:
print("[Repo Object] Fetching branches for %s…" % self.name)
p = subprocess.check_output([
"git", "ls-remote", "--heads", self.url
]).decode("utf8")
p = subprocess.check_output(
["git", "ls-remote", "--heads", self.url]
).decode("utf8")
branches = []
for line in p.split("\n"):
if line.strip() == "":
Expand All @@ -66,7 +64,7 @@ def branches(self):

hash = match[0]
name = match[1]

branches.append((hash, name))
self._branches = branches
return self._branches
Expand All @@ -75,10 +73,9 @@ def branches(self):
def tags(self):
if self._tags is None:
print("[Repo Object] Fetching tags for %s…" % self.name)
p = subprocess.check_output([
"git", "ls-remote", "--tags", "--sort=v:refname",
self.url
]).decode("utf8")
p = subprocess.check_output(
["git", "ls-remote", "--tags", "--sort=v:refname", self.url]
).decode("utf8")

tags = []
for line in p.split("\n"):
Expand All @@ -89,60 +86,59 @@ def tags(self):

hash = match[0]
name = match[1].split("/")[2]

tags.append((hash, name))
self._tags = tags
return self._tags


def out_of_date(self):
return self.commit != self.latest_commit


if os.getenv("GITHUB_ACTIONS") != "true":
dn = os.path.dirname
dn = os.path.dirname
git_directory = dn(dn(dn(os.path.realpath(__file__))))

def git_command(*args):
return subprocess.check_output(
["git"] + list(args),
cwd=git_directory
).decode("utf-8")[:-1]
return subprocess.check_output(["git"] + list(args), cwd=git_directory).decode(
"utf-8"
)[:-1]

repo_url = git_command("remote", "get-url", "origin")
branch = git_command("branch", "--show-current")

os.environ["REPO_URL"] = repo_url
os.environ["BRANCH_NAME"] = branch
os.environ["GITHUB_WORKSPACE"] = git_directory
os.environ["GITHUB_EVENT_NAME"] = "workspace_dispatch"
os.environ["GITHUB_RUN_ID"] = "test_run"

def export_env_alt(key, value):
os.environ[key] = value
print("Setting ENV[%s] to %s..." % (key, value))

export_env = export_env_alt

if os.getenv("PDK_ROOT") is None:
print("Environment variables required: \"PDK_ROOT\"")
print('Environment variables required: "PDK_ROOT"')
exit(os.EX_CONFIG)

origin = os.getenv("REPO_URL")
repo = Repo("Openlane", origin)

# public
gh = SimpleNamespace(**{
"run_id": os.getenv("GITHUB_RUN_ID"),
"origin": origin,
"branch": os.getenv("BRANCH_NAME"),
"image": os.getenv("IMAGE_NAME"),
"root": os.getenv("GITHUB_WORKSPACE"),
"pdk": os.getenv("PDK_ROOT"),
"tool": os.getenv("TOOL"),
"event": SimpleNamespace(**{
"name": os.getenv("GITHUB_EVENT_NAME")
}),
"export_env": export_env,
"Repo": Repo,
"openlane": repo
})
gh = SimpleNamespace(
**{
"run_id": os.getenv("GITHUB_RUN_ID"),
"origin": origin,
"branch": os.getenv("BRANCH_NAME"),
"image": os.getenv("IMAGE_NAME"),
"root": os.getenv("GITHUB_WORKSPACE"),
"pdk": os.getenv("PDK_ROOT"),
"tool": os.getenv("TOOL"),
"event": SimpleNamespace(**{"name": os.getenv("GITHUB_EVENT_NAME")}),
"export_env": export_env,
"Repo": Repo,
"openlane": repo,
}
)
51 changes: 35 additions & 16 deletions .github/scripts/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@
# limitations under the License.

import yaml
from typing import Dict, List
from typing import Dict


class Tool(object):
def __init__(self, name, repo, commit, build_script="make && make install", in_install=True, in_container=True):
def __init__(
self,
name,
repo,
commit,
build_script="make && make install",
in_install=True,
in_container=True,
):
self.name = name
self.repo = repo
self.commit = commit
Expand All @@ -29,7 +38,7 @@ def repo_pretty(self):
gh_prefix = "https://github.com/"
repo = self.repo
if repo is not None and repo.startswith(gh_prefix):
return repo[len(gh_prefix):]
return repo[len(gh_prefix) :]
return repo

@property
Expand All @@ -40,35 +49,45 @@ def __repr__(self) -> str:
return f"<Tool {self.name} (using {self.repo_pretty or 'None'}@{self.commit or 'None'})>"

@staticmethod
def from_metadata_yaml(metadata_yaml: str) -> Dict[str, 'Tool']:
def from_metadata_yaml(metadata_yaml: str) -> Dict[str, "Tool"]:
final_dict = {}
tool_list = yaml.load(metadata_yaml, Loader=yaml.SafeLoader)
for tool in tool_list:
final_dict[tool['name']] = Tool(
name=tool['name'],
repo=tool['repo'],
commit=tool['commit'],
build_script=tool['build'],
in_container=tool['in_container'] if tool.get('in_container') is not None else True,
in_install=tool['in_install'] if tool.get('in_install') is not None else True
final_dict[tool["name"]] = Tool(
name=tool["name"],
repo=tool["repo"],
commit=tool["commit"],
build_script=tool["build"],
in_container=tool["in_container"]
if tool.get("in_container") is not None
else True,
in_install=tool["in_install"]
if tool.get("in_install") is not None
else True,
)
return final_dict


def main():
import os
import argparse

parser = argparse.ArgumentParser(description="Get Tool Info")
parser.add_argument("--docker-args", action="store_true")
parser.add_argument("--field", "-f")
parser.add_argument("tool")
tools = Tool.from_metadata_yaml(open(os.path.join(os.path.dirname(__file__), "tool_metadata.yml")).read())
tools = Tool.from_metadata_yaml(
open(os.path.join(os.path.dirname(__file__), "tool_metadata.yml")).read()
)
args = parser.parse_args()

tool = tools[args.tool]

if args.docker_args:
print(f"--build-arg {tool.name.upper()}_REPO={tool.repo} --build-arg {tool.name.upper()}_COMMIT={tool.commit}", end="")
print(
f"--build-arg {tool.name.upper()}_REPO={tool.repo} --build-arg {tool.name.upper()}_COMMIT={tool.commit}",
end="",
)
elif args.field:
field = tool.__dict__[args.field]
print(field, end="")
Expand Down
Loading

0 comments on commit 0ffbb0f

Please sign in to comment.