Package: reqif
ReqIFReqIF is a Python library for working with ReqIF format.Supported featuresParsing/unparsing ReqIFFormatting (pretty-printing) ReqIFBasic validation of ReqIFAnonymizing ReqIF files to safely exchange the problematic ReqIF files.Getting startedpipinstallreqifUsing ReqIF as a libraryParsing ReqIFfromreqif.parserimportReqIFParserinput_file_path="input.reqif"reqif_bundle=ReqIFParser.parse(input_file_path)forspecificationinreqif_bundle.core_content.req_if_content.specifications:print(specification.long_name)forcurrent_hierarchyinreqif_bundle.iterate_specification_hierarchy(specification):print(current_hierarchy)or for ReqIFz files:fromreqif.parserimportReqIFZParserinput_file_path="input.reqifz"reqifz_bundle=ReqIFZParser.parse(input_file_path)forreqif_bundleinreqifz_bundle.reqif_bundles:forspecificationinreqif_bundle.core_content.req_if_content.specifications:print(specification.long_name)forattachmentinreqifz_bundle.attachments:print(attachment)Unparsing ReqIFfromreqif.parserimportReqIFParserfromreqif.unparserimportReqIFUnparserinput_file_path="input.sdoc"output_file_path="output.sdoc"reqif_bundle=ReqIFParser.parse(input_file_path)reqif_xml_output=ReqIFUnparser.unparse(reqif_bundle)withopen(output_file_path,"w",encoding="UTF-8")asoutput_file:output_file.write(reqif_xml_output)The contents ofreqif_xml_outputshould be the same as the contents of theinput_file.Using ReqIF as a command-line toolAfter installing thereqifPip package, thereqifcommand becomes available
and can be executed from the command line.reqif
usage: reqif [-h] {passthrough,anonymize,dump,format,validate,version} ...
reqif: error: the following arguments are required: commandValidate commandThevalidatecommand is the first command to run against a ReqIF file. Thereqiflibrary contains two sets of checks:reqif-internal checks of a ReqIF file's schema and semantics.a check of a ReqIF file against theReqIF's official schemamaintained by the Object Management Group (OMG).The first set of checks is always enabled. To enable the second set of the
official ReqIF schema checks, use--use-reqif-schema:reqif validate --use-reqif-schema sample.reqifIf an error is found, thereqif validatecommand exits with 1. If no errors
are found, the exit code is0.Passthrough commandThereqif passthroughcommand is a useful tool for verifying whether the reqif
tool correctly parses a given ReqIF file format that the user has at hand.
Thepassthroughcommand first parses the ReqIF XML into in-memory Python
objects and then unparses these Python objects back to an output ReqIF file.If everything goes fine, the output of the passthrough command should be
identical to the contents of the input file.tests/integration/examplescontains samples of ReqIF files found on the
internet. The integration tests ensure that for these samples, the passthrough
command always produces outputs that are identical to inputs.Formatting ReqIFTheformatcommand is similar toclang-formatfor C/C++ files orcmake-formatfor CMake files. The input file is parsed and then pretty-printed
back to an output file.This command is useful when dealing with the ReqIF files that are hand-written
or the ReqIF files produced by the ReqIF tools that do not generate well-formed
XML with consistent indentation.Thetests/integration/commands/formatcontains typical examples of
incorrectly formatted ReqIF files. The integration tests ensure that theformatcommand fixes these issues.Anonymizing ReqIFThe anonymization helps when exchanging ReqIF documents between different ReqIF
tools including thisreqiflibrary. If a particular file is not recognized
correctly by a tool, a user can send their anonymized file to a developer for
further inspection.The anonymize command accepts an input.reqiffile and produces an anonymized
version of that file to the output.reqiffile.usage: reqif anonymize [-h] input_file output_file
main.py anonymize: error: the following arguments are required: input_file, output_fileExamples of anonymization:...<ATTRIBUTE-VALUE-STRINGTHE-VALUE="...Anonymized-2644691225...">...<ATTRIBUTE-VALUE-XHTML><DEFINITION><ATTRIBUTE-DEFINITION-XHTML-REF>rmf-7d0ed062-e964-424c-8305-45067118d959</ATTRIBUTE-DEFINITION-XHTML-REF></DEFINITION><THE-VALUE>...Anonymized-141441514...</THE-VALUE>...The anonymization algorithm preserves the uniqueness of the anonymized strings
in the document. This way, if the requirement UID identifiers are anonymized,
they will still be unique strings in an anonymized document.Implementation detailsThe core of the library is aReqIF first-stage parserthat only transforms
the contents of a ReqIF XML file into a ReqIF in-memory representation. The
in-memory representation is a tree of Python objects that map directly to the
objects of the ReqIF XML file structure (e.g, Spec Objects, Spec Types, Data
Types, Specifications, etc.).Parsing: Converting from ReqIF to other formatsThe first-stage parser (implemented by the classReqIFParser) can be used by
user's second-stage parser/converter scripts that convert the ReqIF in-memory
structure into a desired format such as Excel, HTML or other formats. The
two-stage process allows the first stage parsing to focus solely on creating an
in-memory ReqIF object tree, while the second stage parsing can further parse
the ReqIF object tree according to the logical structure of user's documents as
encoded in the ReqIF XML file that was produced by user's requirements
management tool.Unparsing: Converting from other formats to ReqIFThe reverse process is also possible. A user's script converts another format's
contents into a ReqIF in-memory representation. The ReqIF un-parser
(implemented by the classReqIFUnparser) can be used to render the in-memory
objects to the ReqIF XML file.ToleranceThe first-stage parser is made tolerant against possible issues in ReqIF.
It should be possible to parse a ReqIF file even if it is missing important
information.A minimum ReqIF parsed by thereqif:<?xml version="1.0" encoding="UTF-8"?><REQ-IFxmlns="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd"xmlns:configuration="http://eclipse.org/rmf/pror/toolextensions/1.0"></REQ-IF>A separate validation command shall be used to confirm the validity
of the ReqIF contents.Printing of the attributesThereqiflibrary uses a simple convention for printing the XML attributes: the
attributes are always printed in the alphabetic order of their attribute names.<DATATYPE-DEFINITION-REALACCURACY="10"IDENTIFIER="ID_TC1000_DatatypeDefinitionReal"LAST-CHANGE="2012-04-07T01:51:37.112+02:00"LONG-NAME="TC1000 DatatypeDefinitionReal"MAX="1234.5678"MIN="-1234.5678"/>Some tools do not respect this rule: for example some tools will print
the attributeACCURACY="10"after theLONG-NAMEattribute but thereqiflibrary does not provide support for preserving a non-alphabetic order of the
attributes.A bottom-up overview of the ReqIF formatReqIF is a standard. See reference documentRD01.ReqIF has a fixed structure (see "What is common for all ReqIF documents"
below)ReqIF standard does not define a document structure for every documents so
a ReqIF tool implementor is free to choose between several implementation
approaches. There is aReqIF Implementation Guidethat attempts to harmonize ReqIF tool developments. See also
"What is left open by the ReqIF standard" below.ReqIF files produced by various tool often have incomplete schemas.What is common for all ReqIF documentsAll documents have ReqIF tags:Document metadata is stored inside tags ofREQ-IF-HEADERtag.Requirements are stored as<SPEC-OBJECT>sRequirements types are stored as<SPEC-TYPE>sSupported data types are stored as<DATATYPE>Relationships such as 'Parent-Child' as stored as<SPEC-RELATIONS>What is left open by the ReqIF standardHow to distinguish requirements from headers/sections?One way: create separateSPEC-TYPES: one or more for requirements and
one for sections.Another way: have one spec type but have it provide aTYPEfield that can
be used to distinguish betweenREQUIREMENTorSECTION.Yet another way: Check if the "ReqIF.ChapterName" is present on the spec object.
When present, it is a section. When not, it is a requirement.Reference documents[RD01] ReqIF standardThe latest version is 1.2:Requirements Interchange Format[RD02] ReqIF Implementation GuideReqIF Implementation Guide v1.8