Skip to content

Commit ae327bb

Browse files
committed
Merge PR #134: Prepare ThinkDSP for PyPI packaging
2 parents 92729d0 + 9ce669c commit ae327bb

File tree

11 files changed

+6121
-18
lines changed

11 files changed

+6121
-18
lines changed

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.10"
16+
- name: Build sdist and wheel
17+
run: |
18+
python -m pip install --upgrade pip
19+
python -m pip install build
20+
python -m build
21+
- uses: actions/upload-artifact@v4
22+
with:
23+
name: dist
24+
path: dist/*
25+
26+
publish:
27+
needs: build
28+
runs-on: ubuntu-latest
29+
environment:
30+
name: pypi
31+
url: https://pypi.org/p/thinkdsp-kim
32+
permissions:
33+
id-token: write
34+
steps:
35+
- uses: actions/download-artifact@v4
36+
with:
37+
name: dist
38+
path: dist
39+
- uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
11
.ipynb_checkpoints/
2+
.DS_Store
3+
4+
# Python
5+
__pycache__/
6+
*.py[cod]
7+
*.pyd
8+
.python-version
9+
*.egg-info/
10+
.eggs/
11+
12+
# Virtual environments
13+
.venv/
14+
venv/
15+
16+
# Packaging/build
17+
build/
18+
dist/
19+
.pytest_cache/
20+
.coverage
21+
coverage.xml
22+
htmlcov/
23+
24+
# Poetry
25+
poetry.lock

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2013 Allen B. Downey
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
[Read *Think DSP* in HTML](http://greenteapress.com/thinkdsp/html/index.html).
1010

11+
## Attribution
12+
13+
This repository packages the `thinkdsp` code from *Think DSP* by Allen B. Downey.
14+
Original code and copyright remain with the author under the MIT License.
15+
This packaging fork is maintained by `hoppa1231` and is not affiliated with the
16+
original author or publisher.
17+
1118
The premise of this book (and the other books in the Think X series) is that if you know how to program, you can use that skill to learn other things. I am writing this book because I think the conventional approach to digital signal processing is backward: most books (and the classes that use them) present the material bottom-up, starting with mathematical abstractions like phasors.
1219

1320
With a programming-based approach, I can go top-down, which means I can present the most important ideas right away. By the end of the first chapter, you can decompose a sound into its harmonics, modify the harmonics, and generate new sounds.

nb/thinkdsp.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
try:
2424
from IPython.display import Audio
2525
except ImportError:
26-
warnings.warn(
27-
"Can't import Audio from IPython.display; " "Wave.make_audio() will not work."
28-
)
26+
Audio = None
2927

3028
PI2 = np.pi * 2
3129

@@ -73,7 +71,7 @@ def write(self, wave):
7371
wave: Wave
7472
"""
7573
zs = wave.quantize(self.bound, self.dtype)
76-
self.fp.writeframes(zs.tostring())
74+
self.fp.writeframes(zs.tobytes())
7775

7876
def close(self, duration=0):
7977
"""Closes the file.
@@ -112,7 +110,7 @@ def read_wave(filename="sound.wav"):
112110
xs = np.fromstring(z_str, dtype=np.int8).astype(np.int32)
113111
ys = (xs[2::3] * 256 + xs[1::3]) * 256 + xs[0::3]
114112
else:
115-
ys = np.fromstring(z_str, dtype=dtype_map[sampwidth])
113+
ys = np.frombuffer(z_str, dtype=dtype_map[sampwidth])
116114

117115
# if it's in stereo, just pull out the first channel
118116
if nchannels == 2:
@@ -1087,6 +1085,11 @@ def play(self, filename="sound.wav"):
10871085

10881086
def make_audio(self):
10891087
"""Makes an IPython Audio object."""
1088+
if Audio is None:
1089+
raise ImportError(
1090+
"IPython is required for Wave.make_audio(). "
1091+
"Install with `pip install ipython`."
1092+
)
10901093
audio = Audio(data=self.ys.real, rate=self.framerate)
10911094
return audio
10921095

pyproject.toml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
[tool.poetry]
2-
name = "thinkdsp"
3-
version = "0.1.0"
4-
description = ""
2+
name = "thinkdsp-kim"
3+
version = "0.1.1"
4+
description = "DSP utilities from the Think DSP book"
55
authors = ["Allen Downey <allen.downey@olin.edu>"]
6+
maintainers = ["Kim Maxim <maksimkim005@gmail.com>"]
7+
readme = "README.md"
8+
license = "MIT"
9+
packages = [{ include = "thinkdsp", from = "src" }]
10+
include = ["LICENSE"]
11+
exclude = ["book", "code", ".devcontainer", ".github"]
12+
classifiers = [
13+
"Development Status :: 3 - Alpha",
14+
"Intended Audience :: Education",
15+
"License :: OSI Approved :: MIT License",
16+
"Programming Language :: Python :: 3",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Topic :: Multimedia :: Sound/Audio :: Analysis",
19+
"Topic :: Scientific/Engineering :: Mathematics",
20+
]
621

722
[tool.poetry.dependencies]
8-
python = "^3.8"
9-
jupyter = "^1.0.0"
10-
numpy = "^1.19.4"
11-
matplotlib = "^3.3.3"
12-
seaborn = "^0.11.0"
13-
pandas = "^1.1.4"
14-
scipy = "^1.5.4"
23+
python = ">=3.9,<4.0"
24+
numpy = ">=1.22.4,<3.0"
25+
scipy = ">=1.13.0,<2.0"
26+
matplotlib = ">=3.8.0,<4.0"
27+
jupyter = { version = "^1.0.0", optional = true }
28+
pandas = { version = "^1.1.4", optional = true }
29+
seaborn = { version = "^0.11.0", optional = true }
1530

16-
[tool.poetry.dev-dependencies]
31+
[tool.poetry.extras]
32+
notebooks = ["jupyter", "pandas", "seaborn"]
33+
34+
[tool.poetry.group.dev.dependencies]
35+
pytest = "^7.0"
1736

1837
[build-system]
19-
requires = ["poetry>=0.12"]
20-
build-backend = "poetry.masonry.api"
38+
requires = ["poetry-core>=1.0.0"]
39+
build-backend = "poetry.core.masonry.api"

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-r requirements.txt
22
black
3+
nb_black==1.0.5
34
flake8
5+
nbformat
46
nbmake
57
pytest

0 commit comments

Comments
 (0)