Skip to content

Commit d3cac39

Browse files
authored
Fixing GitHub workflows (#1)
1 parent 48db2c0 commit d3cac39

File tree

6 files changed

+89
-103
lines changed

6 files changed

+89
-103
lines changed

.github/workflows/linters.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
linters-ubuntu:
11-
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
python-version: ["3.9", "3.10", "3.11"]
15-
steps:
16-
- uses: actions/checkout@v4
17-
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v5
19-
with:
20-
python-version: ${{ matrix.python-version }}
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
python -m pip install pdm
25-
python -m pdm install --no-lock --no-self --no-default -G linters
26-
- name: Run flake8
27-
run: |
28-
python -m flake8 src/ tests/
10+
linters-ubuntu:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.9", "3.10", "3.11"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up PDM
19+
uses: pdm-project/setup-pdm@v3
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
pdm install --no-lock --no-self --no-default -G linters
26+
- name: Run flake8
27+
run: |
28+
pdm run -v flake8 src/ tests/

.github/workflows/testing.yml

+23-62
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,26 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
build-ubuntu:
14-
runs-on: ubuntu-latest
15-
strategy:
16-
matrix:
17-
python-version: ["3.9", "3.10", "3.11"]
18-
steps:
19-
- uses: actions/checkout@v3
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v3
22-
with:
23-
python-version: ${{ matrix.python-version }}
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
pip install pdm
28-
pdm install --no-lock -G tests
29-
- name: Test with pytest
30-
run: |
31-
cd tests/
32-
pytest .
33-
34-
build-macos:
35-
runs-on: macos-latest
36-
strategy:
37-
matrix:
38-
python-version: ["3.9", "3.10", "3.11"]
39-
steps:
40-
- uses: actions/checkout@v3
41-
- name: Set up Python ${{ matrix.python-version }}
42-
uses: actions/setup-python@v3
43-
with:
44-
python-version: ${{ matrix.python-version }}
45-
- name: Install dependencies
46-
run: |
47-
python -m pip install --upgrade pip
48-
pip install pdm
49-
pdm install --no-lock -G tests
50-
- name: Test with pytest
51-
run: |
52-
cd tests/
53-
pytest .
54-
55-
build-windows:
56-
runs-on: windows-latest
57-
strategy:
58-
matrix:
59-
python-version: ["3.9", "3.10", "3.11"]
60-
steps:
61-
- uses: actions/checkout@v3
62-
- name: Set up Python ${{ matrix.python-version }}
63-
uses: actions/setup-python@v3
64-
with:
65-
python-version: ${{ matrix.python-version }}
66-
- name: Install dependencies
67-
run: |
68-
python -m pip install --upgrade pip
69-
pip install pdm
70-
pdm install --no-lock -G tests
71-
- name: Test with pytest
72-
run: |
73-
cd tests/
74-
pytest .
13+
build:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
python-version: ["3.9", "3.10", "3.11"]
18+
os: [ubuntu-latest, macos-latest] # TODO: extend with windows-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
submodules: recursive
24+
- name: Set up PDM
25+
uses: pdm-project/setup-pdm@v3
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install dependencies
30+
run: |
31+
pdm install --no-lock -v -G tests
32+
- name: Test with pytest
33+
run: |
34+
cd tests/
35+
pdm run -v pytest .

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
2828
endif()
2929

3030
# Compiler flags
31-
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
31+
# Set default compile flags for GCC
32+
if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
33+
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
34+
endif()
3235
set(CMAKE_CXX_FLAGS_RELEASE "-O3") # is -O3 worth it? -O2
3336

3437
# Find libs nanobind

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ linters = [
2828
tests = [
2929
"pytest",
3030
"numpy >= 1.24.4",
31-
"torchaudio >= 2.0.1",
3231
"scipy",
3332
]
3433

src/_fastwave.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
#include <string>
1+
#include <array>
2+
#include <chrono>
3+
#include <cstring> // std::memcpy
4+
#include <iterator>
25
#include <iostream>
3-
#include <stdexcept>
4-
56
#include <fstream>
6-
#include <iterator>
7-
#include <vector>
8-
#include <chrono>
7+
#include <numeric>
8+
#include <string>
9+
#include <stdexcept>
910
#include <thread>
11+
#include <vector>
12+
13+
#if defined(__linux__) || defined(__APPLE__)
1014
#include <sys/mman.h> // include for mmap support
1115
// includes for open and it's flags
1216
#include <sys/stat.h>
1317
#include <fcntl.h>
14-
15-
#include <numeric>
18+
// #elif _WIN32
19+
// // windows code goes here
20+
// #else
21+
#endif
1622

1723
#include "nanobind/nanobind.h"
1824
#include "nanobind/ndarray.h"
@@ -376,7 +382,11 @@ namespace fastwave
376382
{
377383
if (_buffer != nullptr) {
378384
if (is_mmap) {
385+
#if defined(__linux__) || defined(__APPLE__)
379386
munmap(reinterpret_cast<void *>(_buffer), _buffer_size);
387+
#else
388+
throw std::runtime_error("MUNMAP is not supported on this platform!");
389+
#endif
380390
}
381391
else {
382392
free(_buffer);
@@ -387,6 +397,7 @@ namespace fastwave
387397

388398
void read_mmap(const std::string &file_path, bool is_shared)
389399
{
400+
#if defined(__linux__) || defined(__APPLE__)
390401
// Allow MAP_SHARED and MAP_PRIVATE
391402
// https://man7.org/linux/man-pages/man2/mmap.2.html
392403
// Unmap the memory if it was previously mapped
@@ -405,6 +416,9 @@ namespace fastwave
405416
// Update mmap flag:
406417
is_mmap = true;
407418
return;
419+
#else
420+
throw std::runtime_error("MMAP is not supported on this platform!");
421+
#endif
408422
}
409423

410424
void read_threads(const std::string &file_path, const size_t cache_size, const size_t num_threads)

tests/test_info.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
import numpy as np
4-
import torchaudio # reference library
4+
import wave # reference library -- native Python
55

66
import fastwave as f
77

@@ -15,7 +15,16 @@
1515

1616

1717
def ref_read(file_path):
18-
return torchaudio.info(file_path)
18+
info = {}
19+
with wave.open(file_path, mode="rb") as audio:
20+
# Need to calculate duration by hand:
21+
info["duration"] = audio.getnframes() / audio.getframerate()
22+
info["num_samples"] = audio.getnframes()
23+
info["num_channels"] = audio.getnchannels()
24+
info["sample_rate"] = audio.getframerate()
25+
# wave returns width in bytes, multiply it to get bits:
26+
info["bit_depth"] = audio.getsampwidth() * 8
27+
return info
1928

2029

2130
@pytest.mark.parametrize(
@@ -25,11 +34,11 @@ def ref_read(file_path):
2534
def test_info_direct(file_name):
2635
ref_info = ref_read(file_name)
2736
audio_info = f.info(file_name)
28-
assert ref_info.num_frames / ref_info.sample_rate == audio_info.duration
29-
assert ref_info.num_frames == audio_info.num_samples
30-
assert ref_info.num_channels == audio_info.num_channels
31-
assert ref_info.sample_rate == audio_info.sample_rate
32-
assert ref_info.bits_per_sample == audio_info.bit_depth
37+
assert ref_info["duration"] == audio_info.duration
38+
assert ref_info["num_samples"] == audio_info.num_samples
39+
assert ref_info["num_channels"] == audio_info.num_channels
40+
assert ref_info["sample_rate"] == audio_info.sample_rate
41+
assert ref_info["bit_depth"] == audio_info.bit_depth
3342

3443

3544
@pytest.mark.parametrize(
@@ -48,8 +57,8 @@ def test_info_direct(file_name):
4857
def test_info_read(file_name, mode):
4958
ref_info = ref_read(file_name)
5059
audio_info = f.read(file_name, mode=mode).info
51-
assert ref_info.num_frames / ref_info.sample_rate == audio_info.duration
52-
assert ref_info.num_frames == audio_info.num_samples
53-
assert ref_info.num_channels == audio_info.num_channels
54-
assert ref_info.sample_rate == audio_info.sample_rate
55-
assert ref_info.bits_per_sample == audio_info.bit_depth
60+
assert ref_info["duration"] == audio_info.duration
61+
assert ref_info["num_samples"] == audio_info.num_samples
62+
assert ref_info["num_channels"] == audio_info.num_channels
63+
assert ref_info["sample_rate"] == audio_info.sample_rate
64+
assert ref_info["bit_depth"] == audio_info.bit_depth

0 commit comments

Comments
 (0)