Skip to content

Commit

Permalink
Add github workflow for linting. Also clean up entire codebase to pass
Browse files Browse the repository at this point in the history
lint (lots and lots of minor non-functional changes).
  • Loading branch information
Nathan Pemberton committed Aug 26, 2021
1 parent d25efe5 commit 2688fd5
Show file tree
Hide file tree
Showing 27 changed files with 475 additions and 422 deletions.
2 changes: 2 additions & 0 deletions .github/linters/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore: E501,E121,E123,E126,E226,E24,E704,W503,W504
53 changes: 53 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
#################################
#################################
## Super Linter GitHub Actions ##
#################################
#################################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
pull_request:
branches: [master, main]

###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://ghcr.io/github/super-linter:slim-v4
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_PYTHON_FLAKE8: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ wlutil/_command.sh
*__pycache__
.doit.db*
marshal-config.yaml
.ropeproject
2 changes: 1 addition & 1 deletion boards/default/distros/bare/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .bare import *
from .bare import * # NOQA
26 changes: 13 additions & 13 deletions boards/default/distros/bare/bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@

bare_dir = os.path.dirname(os.path.realpath(__file__))


def hashOpts(opts):
return None


def mergeOpts(base, new):
return base
return base


def initOpts(cfg):
pass


class Builder:
"""Bare is basically a noop just to have consistency with other distros"""
def __init__(self, opts):
pass


def getWorkload(self):
return {
'name' : 'bare',
'isDistro' : True,
'distro' : {
'name' : 'bare',
'opts' : {}
'name': 'bare',
'isDistro': True,
'distro': {
'name': 'bare',
'opts': {}
},
'workdir' : bare_dir,
'qemu' : None,
'builder' : self
'workdir': bare_dir,
'qemu': None,
'builder': self
}


def buildBaseImage(self):
raise NotImplementedError("Baremetal workloads currently do not support disk images")


def upToDate(self):
"""Report whether the distro is up to date or not.
Trivially true because the bare-distro doesn't actually do anything
"""
return [True]


# Set up the image such that, when run in qemu, it will run the script "script"
# If None is passed for script, any existing bootscript will be deleted
@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion boards/default/distros/br/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .br import *
from .br import * # NOQA
49 changes: 20 additions & 29 deletions boards/default/distros/br/br.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import os
import subprocess as sp
import shutil
import logging
import string
import pathlib
import git
import doit
import hashlib
import wlutil
Expand Down Expand Up @@ -67,8 +64,8 @@ def hashOpts(opts):
def mergeOpts(base, new):
"""Given two ['distro']['opts'] objects, return a merged version"""
merged = {
"configs" : base['configs'] + new['configs'],
"environment" : {**base['environment'], **new['environment']}
"configs": base['configs'] + new['configs'],
"environment": {**base['environment'], **new['environment']}
}

return merged
Expand Down Expand Up @@ -104,12 +101,13 @@ def initOpts(cfg):
# Expand any variables the user provided for their environment (including
# the workload path variable we add)
os.environ[cfg['name'].upper().replace("-", "_") + "_PATH"] = str(cfg['workdir'])
for k,v in opts['environment'].items():
for k, v in opts['environment'].items():
opts['environment'][k] = os.path.expandvars(v)
os.environ = envBackup

opts['environment'][cfg['name'].upper().replace("-", "_") + "_PATH"] = str(cfg['workdir'])


class Builder:
"""A builder object will be created for each unique set of options (as
identified by hashOpts) and used to construct the base rootfs for this
Expand All @@ -125,21 +123,19 @@ def __init__(self, opts):

self.outputImg = wlutil.getOpt('image-dir') / (self.name + ".img")


def getWorkload(self):
return {
'name' : self.name,
'isDistro' : True,
'distro' : {
'name' : 'br',
'opts' : { 'configs' : [] }
'name': self.name,
'isDistro': True,
'distro': {
'name': 'br',
'opts': {'configs': []}
},
'workdir' : br_dir,
'builder' : self,
'img' : self.outputImg
'workdir': br_dir,
'builder': self,
'img': self.outputImg
}


def configure(self, env):
"""Construct the final buildroot configuration for this environment. After
calling this, it is safe to call 'make' in the buildroot directory."""
Expand All @@ -161,11 +157,10 @@ def configure(self, env):
wlutil.run(['make', 'defconfig'], cwd=(br_dir / 'buildroot'), env=env)
shutil.copy(br_dir / 'buildroot' / '.config', defconfig)

kFrags = [ defconfig, toolKfrag ] + self.opts['configs']
kFrags = [defconfig, toolKfrag] + self.opts['configs']
mergeScript = br_dir / 'merge_config.sh'
wlutil.run([mergeScript] + kFrags, cwd=(br_dir / 'buildroot'), env=env)


# Build a base image in the requested format and return an absolute path to that image
def buildBaseImage(self):
"""Ensures that the image file specified by baseConfig() exists and is up to date.
Expand All @@ -179,7 +174,7 @@ def buildBaseImage(self):
env = os.environ.copy()
env.pop('PERL_MM_OPT', None)
env = {**env, **self.opts['environment']}

self.configure(env)

# This is unfortunate but buildroot can't remove things from the
Expand All @@ -193,7 +188,6 @@ def buildBaseImage(self):
except wlutil.SubmoduleError as e:
return doit.exceptions.TaskFailed(e)


def fileDeps(self):
# List all files that should be checked to determine if BR is uptodate
deps = []
Expand All @@ -202,14 +196,12 @@ def fileDeps(self):

return deps


# Return True if the base image is up to date, or False if it needs to be
# rebuilt. This is in addition to the files in fileDeps()
def upToDate(self):
return [wlutil.config_changed(wlutil.checkGitStatus(br_dir / 'buildroot')),
wlutil.config_changed(hashOpts(self.opts))]


# Set up the image such that, when run in qemu, it will run the script "script"
# If None is passed for script, any existing bootscript will be deleted
@staticmethod
Expand All @@ -219,7 +211,7 @@ def generateBootScriptOverlay(script, args):
# script that init will run last. This script will run the /firesim.sh
# script at boot. We just overwrite this script.
scriptDst = overlay / 'firesim.sh'
if script != None:
if script is not None:
shutil.copy(script, scriptDst)
else:
scriptDst.unlink()
Expand All @@ -231,24 +223,23 @@ def generateBootScriptOverlay(script, args):
scriptDst.chmod(0o755)

with open(overlay / 'etc/init.d/S99run', 'w') as f:
if args == None:
if args is None:
f.write(initTemplate.substitute(args=''))
else:
f.write(initTemplate.substitute(args=' '.join(args)))

return overlay


def stripUart(self, lines):
stripped = []
inBody = False
for l in lines:
for line in lines:
if not inBody:
if re.match("launching firesim workload run/command", l):
if re.match("launching firesim workload run/command", line):
inBody = True
else:
if re.match("firesim workload run/command done", l):
if re.match("firesim workload run/command done", line):
break
stripped.append(l)
stripped.append(line)

return stripped
2 changes: 1 addition & 1 deletion boards/default/distros/fedora/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .fedora import *
from .fedora import * # NOQA
34 changes: 19 additions & 15 deletions boards/default/distros/fedora/fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,41 @@
StandardOutput=journal+console"""

# Some common directories for this module (all absolute paths)
fed_dir=pathlib.Path(__file__).resolve().parent
fed_dir = pathlib.Path(__file__).resolve().parent

# Temporary overlay used for applying init scripts
overlay=fed_dir / 'overlay'
overlay = fed_dir / 'overlay'


# Fedora doesn't support any options
def hashOpts(opts):
return None


# Fedora doesn't support any options
def mergeOpts(base, new):
return base


def initOpts(cfg):
return


class Builder:
def __init__(self, opts):
return

def getWorkload(self):
return {
'name' : 'fedora-base',
'isDistro' : True,
'distro' : {
'name' : 'fedora',
'opts' : {}
'name': 'fedora-base',
'isDistro': True,
'distro': {
'name': 'fedora',
'opts': {}
},
'workdir' : fed_dir,
'builder' : self,
'img' : fed_dir / "rootfs.img"
'workdir': fed_dir,
'builder': self,
'img': fed_dir / "rootfs.img"
}

def buildBaseImage(self):
Expand All @@ -72,7 +76,7 @@ def generateBootScriptOverlay(self, script, args):
# custom service (firesim.service) that runs a script (/init.sh). We
# can change the default boot behavior by changing this script.
scriptDst = overlay / 'etc/firesim/firesim.sh'
if script != None:
if script is not None:
print("applying script: " + str(scriptDst))
shutil.copy(script, scriptDst)
else:
Expand All @@ -81,7 +85,7 @@ def generateBootScriptOverlay(self, script, args):
# Alternatively: we could consider replacing the default.target
# symlink to disable the firesim target entirely
scriptDst.touch()

scriptDst.chmod(0o755)

# Create the service script
Expand All @@ -97,9 +101,9 @@ def generateBootScriptOverlay(self, script, args):

def stripUart(self, lines):
stripped = []
pat = re.compile(".*firesim.sh\[\d*\]: (.*\n)")
for l in lines:
match = pat.match(l)
pat = re.compile(r".*firesim.sh\[\d*\]: (.*\n)")
for line in lines:
match = pat.match(line)
if match:
stripped.append(match.group(1))

Expand Down
Loading

0 comments on commit 2688fd5

Please sign in to comment.