Skip to content

Commit

Permalink
Merge branch 'main' into lobster-codebeamer-support-TDS/TCS
Browse files Browse the repository at this point in the history
  • Loading branch information
SurajBDeore authored Oct 29, 2024
2 parents 4570e35 + f09cc93 commit a688973
Show file tree
Hide file tree
Showing 25 changed files with 771 additions and 30 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ jobs:
name: wheels
path: |
packages/*/dist/*.whl
packages/*/dist/*.gz
packages/*/meta_dist/*.whl
packages/*/meta_dist/*.gz
upload-test:
name: PyPI Upload
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## Changelog

### 0.9.18-dev

### 0.9.19-dev

* Fixes packaging of `bmw-lobster`.

### 0.9.18

* Added a new tool `lobster-cpptest` which can extract references
from C++ unit tests using various regex patterns.
The references must be provided in a format similar to Doxygen comments.

* Add support to `lobster-codebeamer` to generate output using the following schemas:
- requirement
Expand Down
208 changes: 208 additions & 0 deletions CODING_GUIDELINE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# Coding Guideline

Since the introduction of the coding guideline,
we mostly follow the [_Black_ Code Style](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html).

Note that there is still older code around,
where the coding guideline has not yet been applied.

## Classes

The nomenclature of classes shall adhere to the following guideline:

- Classes shall use the CamelCase pattern.
- File names shall be equal to the class names, but all lower case letters.
- Private members shall have at least one leading underscore.
Refer to [Private variables and name mangling](https://docs.python.org/3/tutorial/classes.html#private-variables)
to read more about it.

Example:
```python
class CamelCase:
pass
```
Here the file shall be named `camelcase.py`.

In general, files should not be too lengthy.
We don't want to give a specific limit on the number of lines.
Consider to keep classes in separate files,
instead of having one large file for multiple classes.

## Tests
We are using the `unittest` test framework for unit tests.
Test class names shall consist of the name of the class under test,
with a `Test` postfix.

Example:
```python
from unittest import TestCase

class CamelCaseTest(TestCase):
def test_function1(self):
instance_under_test = CamelCase()
result = instance_under_test.function1()
self.assertEqual(True, result)
```

The file name shall be `test_camelcase.py`

## Line Length
The line length is 88 characters.

## Architecture
Consider to create classes with dedicated properties over using dictionaries with keys.

Example of the preferred approach:
```python
from dataclasses import dataclass


@dataclass
class Car:
color: str

car = Car(color="red")
```

Counter-example of the disfavoured approach:
```python
car = {"color": "red"}
```
The latter examples with a dictionary is easier to get started with,
but it is harder to maintain and refactor.
Also pylint will not be able to give warnings when accessing a key that does not exist.



## Comments

It's good to avoid inline comments and single line comments should be preferred.

```python
def generate_lobster_report():

# Please prefer to use this single line commenting style for better readability.
lobster_report = ""

return lobster_report # Avoid commenting style like this comment.
```


## Documentation Strings a.k.a. Docstring

### One line docstring

One line docstrings as the name suggests, should fit in one line

Example:
```python
def sum_of_two_numbers(number1, number2):
"""Return the sum of two numbers."""
return number1 + number2
```


### Multi-line docstring

Multi-line docstring consists of a single line summary with a blank line followed by it and then followed by more
detailed description. To know more about it please visit official documentation [Python Multi-line docstrings](https://peps.python.org/pep-0257/#multi-line-docstrings).

```python
def generate_lobster_report(data, metadata):
"""
Function to generate a lobster report.
Keyword arguments:
data -- data contains the actual data used to generate the report
metadata -- metadata about the report
"""

# some operations
lobster_report = ""
return lobster_report
```


## Blank lines

- Top-level functions and classes should be separated by 2 blank lines.
- A single blank line should be added between two methods of a class.
- Used blank lines inside a function/method based on logical sections and refrain from adding too much blank lines.


## Imports

Imports should always be added on top of the file and there order should be as in the below mentioned sequence.
- Standard library imports
- Third-party imports
- Application imports

Add a blank line between each type of imports.


- ### **Direct package/Module imports**
- ```python
# This is Correct
import sys
import os

# Don't do this
import sys, os

# This one is fine
from os import path
```
- ### **Absolute vs relative imports**
- As per the PEP 8 guidelines absolute imports are recommended over relative imports.
- ```python
import lobster.items
from lobster import items
from lobster.items import Implementation, TracingTag

# Although in case of complex package layouts relative imports are acceptable

from .items import Implementation
```

- ### **Long import statements**
For long import statements i.e. line length more than 88 characters, use the below format for import statements
```python
from lobster.items import Tracing_Tag, Requirement, Implementation, Activity, Tracing_Status
# The above import line is above 88 characters so surround the import statements using
# round brackets.

from lobster.items import (
Tracing_Tag, Requirement, Implementation, Activity, Tracing_Status
)
```

- ### Important points
- #### **Use relative imports only when the package structure is complex like one given in the example below**
- #### **Do not use wildcard imports as it makes unclear exactly what is used from the imported package/module**
- Example of wildcard imports
```python
# Don't use wildcard imports
from lobster import *
```


## String Quotes

Python supports single quoted as well as double-quoted strings. The PEP8 guideline doesn't have any guideline to use these.
But using one style would help the reader on focusing on the code and avoid any distraction.
The *Black coding style recommends to used double-quoted string as it match with the
docstring standard as per PEP8*


## Function Lengths

There is no standard as such defined for the length of the functions.
However, if a functions is too long i.e lot of screen scrolling required to read as a whole then it is advisable to identify
and club related code and move them to new functions. Breaking the code into smaller functions would also help in code reusability.


## Constants

Constants are generally defined at module level and in capital letters. For separation underscores are used.

Example : `SCHEMA`, `ERROR_SEVERITY`
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The individual packages that `bmw-lobster` depends on are:
* `bmw-lobster-core` the core API and various report generators. All
other tools depend on this.
* `bmw-lobster-tool-cpp` (for C/C++ code)
* `bmw-lobster-tool-cpptest` (for C/C++ code)
* `bmw-lobster-tool-gtest` (for GoogleTest tests)
* `bmw-lobster-tool-python` (for Python3 code)
* `bmw-lobster-tool-beamer` (for requirements in Codebeamer)
Expand All @@ -70,6 +71,7 @@ The individual packages that `bmw-lobster` depends on are:
### For LOBSTER developers

* [Code Coverage Report](https://bmw-software-engineering.github.io/lobster/htmlcov/index.html)
* [Coding Guideline](CODING_GUIDELINE.md)

## Planned inputs

Expand Down
17 changes: 7 additions & 10 deletions lobster/tools/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ def get_item(root, path, required):
elif required:
raise Malformed_Input("object does not contain %s" % field,
root)
else:
return None
return None

elif required:
raise Malformed_Input("not an object", root)

else:
return None
return None


def syn_test_name(file_name):
Expand Down Expand Up @@ -107,15 +104,15 @@ def process_tool_options(self, options, work_list):

@classmethod
def process(cls, options, file_name):
with open(file_name, "r", encoding="UTF-8") as fd:
data = json.load(fd)

# First we follow the test-list items to get the actual data
# we're interested in.
try:
with open(file_name, "r", encoding="UTF-8") as fd:
data = json.load(fd)
data = get_item(root = data,
path = options.test_list,
required = True)
except UnicodeDecodeError as decode_error:
print("%s: File is not encoded in utf-8: %s" % (file_name, decode_error))
return False, []
except Malformed_Input as err:
pprint(err.data)
print("%s: malformed input: %s" % (file_name, err.msg))
Expand Down
1 change: 0 additions & 1 deletion lobster/tools/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ def main():
if options.out:
with open(options.out, "w", encoding="UTF-8") as fd:
lobster_write(fd, schema, "lobster_python", items)
fd.write("\n")
print("Written output for %u items to %s" % (len(items),
options.out))
else:
Expand Down
7 changes: 4 additions & 3 deletions lobster/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.

VERSION_TUPLE = (0, 9, 18)
VERSION_TUPLE = (0, 9, 19)
VERSION_SUFFIX = "dev"

LOBSTER_VERSION = ("%u.%u.%u" % VERSION_TUPLE) + \
("-%s" % VERSION_SUFFIX if VERSION_SUFFIX else "")
LOBSTER_VERSION = ("%u.%u.%u" % VERSION_TUPLE) + (
"-%s" % VERSION_SUFFIX if VERSION_SUFFIX else ""
)

FULL_NAME = "LOBSTER %s" % LOBSTER_VERSION
2 changes: 1 addition & 1 deletion packages/lobster-core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ package:
cp -Rv $(LOBSTER_ROOT)/lobster/html lobster
cp $(LOBSTER_ROOT)/lobster/tools/*.py lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/core lobster/tools
@python3 -m build
@python3 -m build --wheel
2 changes: 1 addition & 1 deletion packages/lobster-metapackage/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package:
@python3 -m build
@python3 -m build --wheel
1 change: 1 addition & 0 deletions packages/lobster-metapackage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LOBSTER packages as a convenience:
* [bmw-lobster-core](https://pypi.org/project/bmw-lobster-core)
* [bmw-lobster-tool-codebeamer](https://pypi.org/project/bmw-lobster-tool-codebeamer)
* [bmw-lobster-tool-cpp](https://pypi.org/project/bmw-lobster-tool-cpp)
* [bmw-lobster-tool-cpptest](https://pypi.org/project/bmw-lobster-tool-cpptest)
* [bmw-lobster-tool-gtest](https://pypi.org/project/bmw-lobster-tool-gtest)
* [bmw-lobster-tool-json](https://pypi.org/project/bmw-lobster-tool-json)
* [bmw-lobster-tool-python](https://pypi.org/project/bmw-lobster-tool-python)
Expand Down
2 changes: 1 addition & 1 deletion packages/lobster-monolithic/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package:
rm -rf lobster dist meta_dist
cp -Rv $(LOBSTER_ROOT)/lobster lobster
@python3 -m build
@python3 -m build --wheel
mv dist meta_dist
2 changes: 1 addition & 1 deletion packages/lobster-tool-codebeamer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/codebeamer lobster/tools
@python3 -m build
@python3 -m build --wheel
2 changes: 1 addition & 1 deletion packages/lobster-tool-cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/cpp lobster/tools
@python3 -m build
@python3 -m build --wheel
2 changes: 1 addition & 1 deletion packages/lobster-tool-cpptest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/cpptest lobster/tools
@python3 -m build
@python3 -m build --wheel
2 changes: 1 addition & 1 deletion packages/lobster-tool-gtest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/gtest lobster/tools
@python3 -m build
@python3 -m build --wheel
2 changes: 1 addition & 1 deletion packages/lobster-tool-json/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/json lobster/tools
@python3 -m build
@python3 -m build --wheel
2 changes: 1 addition & 1 deletion packages/lobster-tool-python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/python lobster/tools
@python3 -m build
@python3 -m build --wheel
8 changes: 8 additions & 0 deletions packages/lobster-tool-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ Please note that the generated output json files always use `PyTest` as framewor
}
```

## Known Issues

The resulting lobster file does not use the method names, but instead uses the class name together with an integer counter for consecutive methods.
This only affects methods in a class.
It does not affect functions.
For details see [issue 89](https://github.com/bmw-software-engineering/lobster/issues/89).
It will be fixed with the next release.

## Copyright & License information

The copyright holder of LOBSTER is the Bayerische Motoren Werke
Expand Down
2 changes: 1 addition & 1 deletion packages/lobster-tool-trlc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package:
rm -rf lobster
mkdir -p lobster/tools
cp -Rv $(LOBSTER_ROOT)/lobster/tools/trlc lobster/tools
@python3 -m build
@python3 -m build --wheel
Loading

0 comments on commit a688973

Please sign in to comment.