Code Monkey home page Code Monkey logo

epicsmacrolib's Introduction

epicsmacrolib

epics-base compliant macro tools.

What?

Do you want epics-base compliant macro expansion, with all of its idiosyncracies?

No? I didn't think so. This is a really boring project and you probably don't need it.

Then why?

This will be the future of the macro and IOC shell splitting tools in whatrecord, removing its reliance on Cython and epicscorelibs.

Examples

macros_from_string

from epicsmacrolib import macros_from_string

macros_from_string("A=5,  B=$(A=3)")
# -> {'A': '5', 'B': '$(A=3)'}

MacroContext

from epicsmacrolib import MacroContext

ctx = MacroContext(use_environment=True)
ctx.define(TEST="A")
print(ctx.expand("TEST=$(TEST) SHELL=$(SHELL)"))
# TEST=A SHELL=/bin/bash

ctx = MacroContext(use_environment=False)
ctx.define_from_string("A=5,B=6")
ctx.define(C="7")
print(ctx.expand("$(A) $(B) ${C} ${D=5} ${E}"))
# -> 5 6 7 5 $(E)

ctx = MacroContext(use_environment=False, show_warnings=True)
ctx.define_from_string("A=5,B=6")
ctx.define(C="7")
print(ctx.expand("$(A) $(B) ${C} ${D=5} ${E}"))
# -> 5 6 7 5 $(E,undefined)

ctx.define_from_string("A=5,B=$(B)")
print(ctx.expand("$(A) $(B)"))
# -> 5 $(B,recursive)

with ctx.scoped(A="10", B="0"):
    print(ctx.expand("$(A)"))
    # -> 10
    with ctx.scoped(A="0"):
        print(ctx.expand("$(A)"))
        # -> 0
    print(ctx.expand("$(A)"))
    # -> 10

split_iocsh_line (like shlex.split)

from epicsmacrolib import split_iocsh_line
split_iocsh_line("dbLoadRecords > output_filename")
# -> IocshSplit(
#     argv=["dbLoadRecords"],
#     redirects={1: IocshRedirect(fileno=1, name="output_filename", mode="w")},
#     error=None,
# )

License

The Python portions of this code is under a BSD-3 clause license (LicenseRef-BSD-3-Clause-SLAC, see LICENSE). Portions of epics-base have been vendored in src under its original license (see src/LICENSE).

epicsmacrolib's People

Contributors

klauer avatar zllentz avatar

Watchers

 avatar

Forkers

klauer zllentz

epicsmacrolib's Issues

Python 3.11 support

Expected Behavior

epicsmacrolib should work on Python 3.11

Current Behavior

It fails to build with:

epicsmacrolib/iocsh.cpp -o build/temp.linux-x86_64-cpython-311/epicsmacrolib/iocsh.o
      epicsmacrolib/iocsh.cpp: In function ‘void __Pyx_AddTraceback(const char*, int, int, const char*)’:
      epicsmacrolib/iocsh.cpp:465:62: error: invalid use of incomplete type ‘PyFrameObject’ {aka ‘struct _frame’}
        465 |   #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
            |                                                              ^~
      epicsmacrolib/iocsh.cpp:5302:5: note: in expansion of macro ‘__Pyx_PyFrame_SetLineNumber’
       5302 |     __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
            |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      In file included from /opt/hostedtoolcache/Python/3.11.2/x64/include/python3.11/Python.h:42,
                       from epicsmacrolib/iocsh.cpp:25:
      /opt/hostedtoolcache/Python/3.11.2/x64/include/python3.11/pytypedefs.h:22:16: note: forward declaration of ‘PyFrameObject’ {aka ‘struct _frame’}
         22 | typedef struct _frame PyFrameObject;
            |                ^~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

Possible Solution

Re-cythonize the bundled .cpp file

PyPI upload failing [LCLSPC-666]

Current Behavior

setuptools-scm is generating unclean version numbers for what was the 0.6.0 release:
epicsmacrolib-0.6.1.dev0+gc5cd708.d20230307-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 483 kB (see https://github.com/pcdshub/epicsmacrolib/actions/runs/4356819358/jobs/7615336174)

PyPI rejects those:

ERROR    HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/        
         '0.6.1.dev0+gc5cd708.d20230307' is an invalid value for Version. Error:
         Can't use PEP 440 local versions. See                                  
         https://packaging.python.org/specifications/core-metadata for more     
         information.              

Possible Solution

This is probably due to the CI job rebuilding the Cythonized C++ source code or something along those lines.

Not sure how best to address this since we aren't really in control of the cibuildwheel process.

(Moving this effort back to blocked on Jira)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.