Skip to content

Commit

Permalink
Merge 808d32b into 36a53df
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Aug 18, 2022
2 parents 36a53df + 808d32b commit a75bfed
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 236 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ jobs:
python -m pip install --upgrade pip
pip install flake8
- name: Run flake8
run: |
flake8
# black
- name: Run flake8 (lint)
uses: suo/flake8-github-action@releases/v1
with:
checkName: 'lint' # NOTE: this needs to be the same as the job name
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run black (code style)
uses: psf/black@stable

test-matrix:
name: Python ${{ matrix.python-version }}
Expand Down
16 changes: 8 additions & 8 deletions adl2pydm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Convert MEDM's .adl files to PyDM's .ui format."""

__project__ = u"adl2pydm"
__project__ = "adl2pydm"
__description__ = __doc__
__copyright__ = u"2017-2022, UChicago Argonne, LLC"
__copyright__ = "2017-2022, UChicago Argonne, LLC"
__authors__ = [
u"Pete Jemian",
"Pete Jemian",
]
__author__ = ", ".join(__authors__)
__institution__ = u"Advanced Photon Source, Argonne National Laboratory"
__author_email__ = u"jemian@anl.gov"
__url__ = u"https://github.com/BCDA-APS/adl2pydm"
__license__ = u"(c) " + __copyright__
__license__ += u" (see LICENSE.txt file for details)"
__institution__ = "Advanced Photon Source, Argonne National Laboratory"
__author_email__ = "jemian@anl.gov"
__url__ = "https://github.com/BCDA-APS/adl2pydm"
__license__ = "(c) " + __copyright__
__license__ += " (see LICENSE.txt file for details)"
__platforms__ = "any"
__zip_safe__ = False
__exclude_project_dirs__ = "adl2pydm/tests tests conda-recipe build".split()
Expand Down
15 changes: 6 additions & 9 deletions adl2pydm/adl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def __str__(self):
return fmt % ", ".join(args)

def getNamedBlock(self, block_name, blocks):
"""
"""
"""docs needed"""
block = [b for b in blocks if b.symbol == block_name]
if len(block) > 0:
return block[0]
Expand Down Expand Up @@ -270,9 +269,7 @@ def parseAdlBuffer(self, buf): # lgtm [py/similar-function]
def parseChildren(self, main, blocks, buf):
for block in blocks:
if block.symbol in symbols.adl_widgets:
logger.debug(
"(#%d) %s" % (self.line_offset + block.start, block.symbol)
)
logger.debug("(#%d) %s" % (self.line_offset + block.start, block.symbol))
handler = self.medm_widget_handlers.get(block.symbol, MedmGenericWidget)
widget = handler(self.line_offset + block.start, main, block.symbol)
widget.parseAdlBuffer(buf[block.start + 1 : block.end])
Expand Down Expand Up @@ -305,9 +302,11 @@ def parseObjectBlock(self, buf):
def parsePlotcomBlock(self, buf, blocks):
block = self.getNamedBlock("plotcom", blocks)
if block is not None:
# fmt: off
self.parseColorAssignments(
self.locateAssignments(buf[block.start + 1 : block.end])
)
# fmt: on
aa = self.locateAssignments(buf[block.start + 1 : block.end])
for symbol in "clr bclr".split():
if symbol in aa:
Expand Down Expand Up @@ -338,7 +337,7 @@ def getAdlLines(self, fname=None):
raise ValueError(msg)
self.given_filename = fname
# brutal: simply discard any non-utf8 characters
buf = open(fname, "r", encoding='utf8', errors='ignore').readlines()
buf = open(fname, "r", encoding="utf8", errors="ignore").readlines()
return buf

def parseAdlBuffer(self, buf): # lgtm [py/similar-function]
Expand Down Expand Up @@ -436,9 +435,7 @@ def __init__(self, line, main, symbol):

def parseAdlBuffer(self, buf): # lgtm [py/similar-function]
# assignments, blocks =
MedmBaseWidget.parseAdlBuffer(
self, buf
)
MedmBaseWidget.parseAdlBuffer(self, buf)


class MedmArcWidget(MedmGenericWidget):
Expand Down
8 changes: 5 additions & 3 deletions adl2pydm/calc2rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def convertCalcToRuleExpression(medm_calc):
op = " not "
calc += op
elif tok.type == tokenize.OP:
calc += {"=": "==", "|": " or ", "&": " and ", }.get(
tok.string, tok.string
)
calc += {
"=": "==",
"|": " or ",
"&": " and ",
}.get(tok.string, tok.string)
elif tok.type not in (tokenize.NEWLINE, tokenize.ENDMARKER):
calc += tok.string

Expand Down
15 changes: 8 additions & 7 deletions adl2pydm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ def get_user_parameters():

msg = "MEDM '.adl' file(s) to convert"
parser.add_argument(
"adlfiles", action="store", nargs=argparse.ONE_OR_MORE, help=msg,
"adlfiles",
action="store",
nargs=argparse.ONE_OR_MORE,
help=msg,
)

msg = "output directory"
msg += ", default: same directory as input file"
parser.add_argument(
"-d", "--dir", action="store", dest="dir", help=msg, default=None
)
parser.add_argument("-d", "--dir", action="store", dest="dir", help=msg, default=None)

parser.add_argument(
"-v", "--version", action="version", version=adl2pydm.__version__
)
parser.add_argument("-v", "--version", action="version", version=adl2pydm.__version__)

parser.add_argument(
"-log",
Expand Down Expand Up @@ -84,10 +83,12 @@ def configure_logging(options):
}
level = levels.get(options.log.lower())
if level is None:
# fmt: off
raise ValueError(
f"log level given: {options.log}"
f" -- must be one of: {' | '.join(levels.keys())}"
)
# fmt: on
logging.basicConfig(level=level)
logger = logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit a75bfed

Please sign in to comment.