Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update supported Python versions and update CI/CD #35

Merged
merged 9 commits into from
May 17, 2024
35 changes: 18 additions & 17 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.*"

Expand All @@ -50,7 +50,7 @@ jobs:
python -c "import packaging.version as v; v.Version(\"$(python -m setuptools_scm)\")"

- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: dist/*
name: dist
Expand All @@ -73,10 +73,9 @@ jobs:
- apt
- conda
python:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
exclude:
- os: macos-latest
type: apt
Expand All @@ -87,15 +86,14 @@ jobs:

- name: Set up Python
if: matrix.type == 'apt'
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
if: matrix.type == 'conda'
with:
python-version: ${{ matrix.python }}
miniforge-variant: Mambaforge
miniforge-version: latest
channels: conda-forge
channel-priority: true
Expand All @@ -112,27 +110,28 @@ jobs:

- name: Install conda dependencies
if: matrix.type == 'conda'
# Note: pytest-icdiff creates problems on macOS.
run: |
mamba install -y \
conda install -y \
coloredlogs \
mashumaro \
numpy \
packaging \
resolve-robotics-uri-py \
scipy \
trimesh \
xmltodict \
black \
isort \
pptree \
idyntree \
pytest \
robot_descriptions \
trimesh
# pytest-icdiff \ # creates problems on macOS
mamba install -y gz-sim7 idyntree
libgz-tools2 \
libsdformat13

- name: Download Python packages
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: dist
name: dist
Expand All @@ -150,13 +149,15 @@ jobs:

- name: Import the package
run: python -c "import rod"
env:
ROD_LOGGING_LEVEL: DEBUG

- uses: actions/checkout@v3
if: matrix.os != 'windows-latest'
- uses: actions/checkout@v4

- name: Run tests
if: matrix.os != 'windows-latest'
run: pytest
env:
ROD_LOGGING_LEVEL: DEBUG

publish:
name: Publish to PyPI
Expand All @@ -166,7 +167,7 @@ jobs:
steps:

- name: Download Python packages
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: dist
name: dist
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ classifiers =
Operating System :: MacOS
Operating System :: Microsoft :: Windows
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: Implementation :: CPython
Topic :: Games/Entertainment :: Simulation
Expand All @@ -53,7 +52,7 @@ zip_safe = False
packages = find:
package_dir =
=src
python_requires = >=3.8
python_requires = >=3.10
install_requires =
coloredlogs
mashumaro
Expand Down
42 changes: 36 additions & 6 deletions src/rod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# ===============================


def _is_editable():
def installation_is_editable():
"""
Check if the rod package is installed in editable mode.
"""
Expand All @@ -51,12 +51,42 @@ def _is_editable():
return rod_package_dir not in site.getsitepackages()


# Initialize the logging verbosity depending on the installation mode.
logging.configure(
level=logging.LoggingLevel.DEBUG if _is_editable() else logging.LoggingLevel.WARNING
)
def get_default_logging_level(env_var: str) -> logging.LoggingLevel:
"""
Get the default logging level.

Args:
env_var: The environment variable to check.

Returns:
The logging level to set.
"""

import os

try:
return logging.LoggingLevel[os.environ[env_var].upper()]

# Raise if the environment variable is set but the logging level is invalid.
except AttributeError:
msg = f"Invalid logging level defined in {env_var}: '{os.environ[env_var]}'"
raise ValueError(msg)

# If the environment variable is not set, return the logging level depending
# on the installation mode.
except KeyError:
return (
logging.LoggingLevel.DEBUG
if installation_is_editable()
else logging.LoggingLevel.WARNING
)


# Configure the logger with the default logging level.
logging.configure(level=get_default_logging_level(env_var="ROD_LOGGING_LEVEL"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the environment variable can only be ROD_LOGGING_LEVEL, is there a reason why you're passing it as the argument of this function? Can it just be hardcoded?

Suggested change
def get_default_logging_level(env_var: str) -> logging.LoggingLevel:
"""
Get the default logging level.
Args:
env_var: The environment variable to check.
Returns:
The logging level to set.
"""
import os
try:
return logging.LoggingLevel[os.environ[env_var].upper()]
# Raise if the environment variable is set but the logging level is invalid.
except AttributeError:
msg = f"Invalid logging level defined in {env_var}: '{os.environ[env_var]}'"
raise ValueError(msg)
# If the environment variable is not set, return the logging level depending
# on the installation mode.
except KeyError:
return (
logging.LoggingLevel.DEBUG
if installation_is_editable()
else logging.LoggingLevel.WARNING
)
# Configure the logger with the default logging level.
logging.configure(level=get_default_logging_level(env_var="ROD_LOGGING_LEVEL"))
def get_default_logging_level() -> logging.LoggingLevel:
"""
Get the default logging level.
Returns:
The logging level to set.
"""
import os
try:
return logging.LoggingLevel[os.environ["ROD_LOGGING_LEVEL"].upper()]
# Raise if the environment variable is set but the logging level is invalid.
except AttributeError:
msg = f"Invalid logging level defined in 'ROD_LOGGING_LEVEL'"
raise ValueError(msg)
# If the environment variable is not set, return the logging level depending
# on the installation mode.
except KeyError:
return (
logging.LoggingLevel.DEBUG
if installation_is_editable()
else logging.LoggingLevel.WARNING
)
# Configure the logger with the default logging level.
logging.configure(level=get_default_logging_level()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the environment variable explicitly defined makes it more visible to users rather than hiding it inside the logic of a function. Since we do not have documentation, I valued readability.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense, thanks for the explanation!


del _is_editable
del installation_is_editable
del get_default_logging_level

# =====================================
# Check for compatible sdformat version
Expand Down
Loading