Skip to content

Commit

Permalink
chore: add types, setup ci (#62)
Browse files Browse the repository at this point in the history
- original code largely intact. only adding types to check for logic errors.
- fix: explicitly use uint16 for enums
- fix: `end_time` -> `duration_s`
- fix: `global_time` should be `seconds_since_start`
- rename: `traffic.ap` -> `traffic.autopilot`
- rename: `ConvertHistoricDemo` time -> timestamps
- fix misc logic errors
- chore: properly run ruff, mypy and tests with uv
  • Loading branch information
cathaypacific8747 committed Dec 20, 2024
1 parent f28da11 commit cf24007
Show file tree
Hide file tree
Showing 30 changed files with 2,321 additions and 1,525 deletions.
127 changes: 56 additions & 71 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,72 @@
name: Tests
name: tests

on:
workflow_dispatch:
pull_request_target:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:

style-check:
name: "style and type checking"
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/')))
runs-on: ${{ matrix.platform }}
strategy:
max-parallel: 5
fail-fast: false
matrix:
include:
- os: ubuntu-latest
label: linux-64
prefix: /usr/share/miniconda3/envs/airtrafficsim
platform: [ubuntu-latest]
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"

# - os: macos-latest
# label: osx-64
# prefix: /Users/runner/miniconda3/envs/airtrafficsim
steps:
- uses: actions/checkout@v4

# - os: windows-latest
# label: win-64
# prefix: C:\Miniconda3\envs\airtrafficsim
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true

name: ${{ matrix.label }}
runs-on: ${{ matrix.os }}

defaults:
run:
shell: bash -el {0}
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3

- name: Cache conda
uses: actions/cache@v2
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}

- name: Setup miniconda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: airtrafficsim
channel-priority: strict
environment-file: environment.yml
python-version: 3.11
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!

- run: |
conda info
conda list
- name: Install the project
run: uv sync

- name: Style checking
run: |
uv run ruff check airtrafficsim tests
uv run ruff format --check airtrafficsim tests
- name: Download data from private repository
uses: actions/checkout@v3
with:
repository: HKUST-OCTAD-LAB/AirTrafficSim-data
ssh-key: ${{ secrets.SSH_KEY }}
path: AirTrafficSim-data
- name: Type checking
run: uv run mypy airtrafficsim tests


- name: Unzip data
run: |
unzip AirTrafficSim-data/BADA.zip -d airtrafficsim/data/performance/BADA
mv AirTrafficSim-data/.cdsapirc $HOME/
# testing
- name: Download data from private repository
uses: actions/checkout@v3
with:
repository: HKUST-OCTAD-LAB/AirTrafficSim-data
ssh-key: ${{ secrets.SSH_KEY }}
path: AirTrafficSim-data

# - name: Lint with flake8
# run: |
# conda install flake8
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Unzip data
run: |
unzip AirTrafficSim-data/BADA.zip -d airtrafficsim/data/performance/BADA
mv AirTrafficSim-data/.cdsapirc $HOME/
- name: Test with pytest
run: |
coverage run -m pytest
coverage xml
- name: Run tests
run: |
uv run pytest --cov --cov-report xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Upload coverage to Codecov
if: ${{ github.event_name != 'pull_request_target' }}
uses: codecov/codecov-action@v5
with:
env_vars: ${{ matrix.python-version }}
22 changes: 16 additions & 6 deletions airtrafficsim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import airtrafficsim.server.server as server


def main():
def main() -> None:
# Unpack client
if (
not Path(__file__)
Expand All @@ -21,19 +21,26 @@ def main():
).extractall(Path(__file__).parent.resolve().joinpath("./data/client/"))

# Create a parser for command line arguments
# FIXME(abrah): use typer.
parser = argparse.ArgumentParser(
prog="AirTrafficSim",
description="Command line interfaces of AirTrafficSim.",
)
parser.add_argument(
"--init",
type=Path,
help="Create a symbloic link to the data folder: airtrafficsim init <path to a folder>.",
help=(
"Create a symbolic link to the data folder: "
"airtrafficsim init <path to a folder>."
),
)
parser.add_argument(
"--headless",
type=str,
help="Run user defined environment without UI: airtrafficsim --headless <env name>.",
help=(
"Run user defined environment without UI: "
"airtrafficsim --headless <env name>."
),
)

args = parser.parse_args()
Expand All @@ -59,10 +66,12 @@ def main():
)
else:
raise IOError(
"The path you provided does not exist. Please provide a valid path."
"The path you provided does not exist. "
"Please provide a valid path."
)
else:
# Give error if BADA data is missing TODO: To be removed when OpenAP is implemented
# Give error if BADA data is missing
# TODO: To be removed when OpenAP is implemented
if (
len(
list(
Expand All @@ -75,7 +84,8 @@ def main():
<= 1
):
raise IOError(
"BADA folder is empty. Remember to put the BADA performance data into /data/performance/BADA/."
"BADA folder is empty. Remember to put the BADA performance "
"data into /data/performance/BADA/."
)
if args.headless:
# Run user defined environment without UI
Expand Down
Loading

0 comments on commit cf24007

Please sign in to comment.