Skip to content

Commit

Permalink
Merge branch 'main' into add_copyright_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Frosty2500 authored Dec 3, 2024
2 parents 0c9b5a4 + 4c07fe1 commit 5c8175c
Show file tree
Hide file tree
Showing 36 changed files with 334 additions and 220 deletions.
99 changes: 83 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,47 @@ name: ci
on: [push, pull_request]

env:
X_PYTHON_VERSION: "3.12"
X_PYTHON_MIN_VERSION: "3.9"
X_PYTHON_MAX_VERSION: "3.12"

jobs:
check-python-versions:
# This job checks that the Python Versions we support match and are not End of Life
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./etc/scripts
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_MIN_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_MIN_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./check_python_versions_requirements.txt
- name: Check Supported Python Versions
run: |
python check_python_versions_supported.py \
${{ env.X_PYTHON_MIN_VERSION }} \
${{ env.X_PYTHON_MAX_VERSION }}
- name: Check Python Versions coincide with the SDKs pyproject.toml
run: |
python check_python_versions_coincide.py \
../../sdk/pyproject.toml \
${{ env.X_PYTHON_MIN_VERSION }} \
${{ env.X_PYTHON_MAX_VERSION }}
# Todo: Check other pyproject.toml here as well, as we add them

sdk-test:
# This job runs the unittests on the python versions specified down at the matrix
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.10", "3.12"]
python-version: ["3.9", "3.12"]
env:
COUCHDB_ADMIN_PASSWORD: "yo0Quai3"
# (2024-10-11, s-heppner)
Expand All @@ -32,9 +64,15 @@ jobs:
run:
working-directory: ./sdk
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Verify Matrix Version matches Global Version
run: |
if [ "${{ matrix.python-version }}" != "${{ env.X_PYTHON_MIN_VERSION }}" ] && [ "${{ matrix.python-version }}" != "${{ env.X_PYTHON_MAX_VERSION }}" ]; then
echo "Error: Matrix version ${{ matrix.python-version }} does not match global version."
exit 1
fi
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Collect schema files from aas-specs
Expand Down Expand Up @@ -64,11 +102,11 @@ jobs:
run:
working-directory: ./sdk
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
- uses: actions/checkout@v4
- name: Set up Python ${{ env.X_PYTHON_MIN_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
python-version: ${{ env.X_PYTHON_MIN_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -87,11 +125,11 @@ jobs:
run:
working-directory: ./sdk
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
- uses: actions/checkout@v4
- name: Set up Python ${{ env.X_PYTHON_MIN_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
python-version: ${{ env.X_PYTHON_MIN_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -113,11 +151,11 @@ jobs:
run:
working-directory: ./sdk
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
- uses: actions/checkout@v4
- name: Set up Python ${{ env.X_PYTHON_MIN_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
python-version: ${{ env.X_PYTHON_MIN_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -134,11 +172,11 @@ jobs:
run:
working-directory: ./sdk
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.X_PYTHON_VERSION }}
- uses: actions/checkout@v4
- name: Set up Python ${{ env.X_PYTHON_MIN_VERSION }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.X_PYTHON_VERSION }}
python-version: ${{ env.X_PYTHON_MIN_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -160,3 +198,32 @@ jobs:
run: |
chmod +x ./etc/scripts/set_copyright_year.sh
./etc/scripts/set_copyright_year.sh --check
server-package:
# This job checks if we can build our server package
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./server
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: |
docker build -t basyx-python-server .
- name: Run container
run: |
docker run -d --name basyx-python-server basyx-python-server
- name: Wait for container and server initialization
run: |
timeout 30s bash -c '
until docker logs basyx-python-server 2>&1 | grep -q "INFO success: quit_on_failure entered RUNNING state"; do
sleep 2
done
'
- name: Check if container is running
run: |
docker inspect --format='{{.State.Running}}' basyx-python-server | grep true
- name: Stop and remove the container
run: |
docker stop basyx-python-server && docker rm basyx-python-server
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ The following guidelines are for the commit or PR message text:

## Codestyle and Testing

Our code follows the [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/).
Our code follows the [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/)
with the following exceptions:
- Line length is allowed to be up to 120 characters, though lines up to 100 characters are preferred.

Additionally, we use [PEP 484 -- Type Hints](https://www.python.org/dev/peps/pep-0484/) throughout the code to enable type checking the code.

Before submitting any changes, make sure to let `mypy` and `pycodestyle` check your code and run the unit tests with
Expand Down
46 changes: 46 additions & 0 deletions etc/scripts/check_python_versions_coincide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
This helper script checks if the Python versions defined in a `pyproject.toml` coincide with the given `min_version`
and `max_version` and returns an error if they don't.
"""
import re
import argparse
import sys
from packaging.version import Version, InvalidVersion

def main(pyproject_toml_path: str, min_version: str, max_version: str) -> None:
# Load and check `requires-python` version from `pyproject.toml`
try:
with open(pyproject_toml_path, "r") as f:
pyproject_content = f.read()

match = re.search(r'requires-python\s*=\s*">=([\d.]+)"', pyproject_content)
if not match:
print(f"Error: `requires-python` field not found or invalid format in `{pyproject_toml_path}`")
sys.exit(1)

pyproject_version = match.group(1)
if Version(pyproject_version) < Version(min_version):
print(f"Error: Python version in `{pyproject_toml_path}` `requires-python` ({pyproject_version}) "
f"is smaller than `min_version` ({min_version}).")
sys.exit(1)

except FileNotFoundError:
print(f"Error: File not found: `{pyproject_toml_path}`.")
sys.exit(1)

print(f"Success: Version in pyproject.toml `requires-python` (>={pyproject_version}) "
f"matches expected versions ([{min_version} to {max_version}]).")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Check Python version support and alignment with pyproject.toml.")
parser.add_argument("pyproject_toml_path", help="Path to the `pyproject.toml` file to check.")
parser.add_argument("min_version", help="The minimum Python version.")
parser.add_argument("max_version", help="The maximum Python version.")
args = parser.parse_args()

try:
main(args.pyproject_toml_path, args.min_version, args.max_version)
except InvalidVersion:
print("Error: Invalid version format provided.")
sys.exit(1)
2 changes: 2 additions & 0 deletions etc/scripts/check_python_versions_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests>=2.23
packaging>=24.2
61 changes: 61 additions & 0 deletions etc/scripts/check_python_versions_supported.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
This helper script checks that the provided `min_version` and `max_version` are supported and released, respectively,
using the API from the great https://github.com/endoflife-date/endoflife.date project.
"""
import argparse
import sys
import requests
from packaging.version import InvalidVersion
from datetime import datetime

def main(min_version: str, max_version: str) -> None:
# Fetch supported Python versions and check min/max versions
try:
response = requests.get("https://endoflife.date/api/python.json")
response.raise_for_status()
eol_data = response.json()
eol_versions = {entry["cycle"]: {"eol": entry["eol"], "releaseDate": entry["releaseDate"]} for entry in eol_data}

# Get current date to compare with EoL and release dates
current_date = datetime.now().date()

# Check min_version EoL status
min_eol_date = eol_versions.get(min_version, {}).get("eol")
if min_eol_date and datetime.strptime(min_eol_date, "%Y-%m-%d").date() <= current_date:
print(f"Error: min_version {min_version} has reached End-of-Life.")
sys.exit(1)

# Check max_version EoL and release status
max_info = eol_versions.get(max_version)
if max_info:
max_eol_date = max_info["eol"]
max_release_date = max_info["releaseDate"]

# Check if max_version has a release date in the future
if max_release_date and datetime.strptime(max_release_date, "%Y-%m-%d").date() > current_date:
print(f"Error: max_version {max_version} has not been officially released yet.")
sys.exit(1)

# Check if max_version has reached EoL
if max_eol_date and datetime.strptime(max_eol_date, "%Y-%m-%d").date() <= current_date:
print(f"Error: max_version {max_version} has reached End-of-Life.")
sys.exit(1)

except requests.RequestException:
print("Error: Failed to fetch Python version support data.")
sys.exit(1)

print(f"Version check passed: min_version [{min_version}] is supported "
f"and max_version [{max_version}] is released.")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Check Python version support and alignment with pyproject.toml.")
parser.add_argument("min_version", help="The minimum Python version.")
parser.add_argument("max_version", help="The maximum Python version.")
args = parser.parse_args()

try:
main(args.min_version, args.max_version)
except InvalidVersion:
print("Error: Invalid version format provided.")
sys.exit(1)
4 changes: 2 additions & 2 deletions sdk/basyx/aas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
The package consists of the python implementation of the AssetAdministrationShell, as defined in the
'Details of the Asset Administration Shell' specification of Plattform Industrie 4.0.
The subpackage 'model' is an implementation of the meta-model of the AAS,
The subpackage 'model' is an implementation of the metamodel of the AAS,
in 'adapter', you can find JSON and XML adapters to translate between BaSyx Python SDK objects and JSON/XML schemas;
and in 'util', some helpful functionality to actually use the AAS meta-model you created with 'model' is located.
and in 'util', some helpful functionality to actually use the AAS metamodel you created with 'model' is located.
"""

__version__ = "1.0.0"
Loading

0 comments on commit 5c8175c

Please sign in to comment.