Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 44 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,44 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install flit
flit install
uv sync --all-extras --group test --group data

- name: Test with pytest
run: pytest -v
run: uv run pytest -v

- name: Docstring doctest
run: pytest --doctest-modules stringcalc -v
run: uv run pytest --doctest-modules stringcalc -v

- name: Test code blocks
run: pytest --codeblocks README.md docs -v
run: uv run pytest --codeblocks README.md docs -v

- name: Check type annotations
run: |
mypy --non-interactive .
uv run mypy --non-interactive .

- name: Check data prep scripts still work
run: |
# Copy to temp location
mkdir -p ../tmp/stringcalc
cp -vr data ../tmp/stringcalc/
cp -vr stringcalc ../tmp/stringcalc/
mkdir -p stringcalc/data/_orig
cp stringcalc/data/*.csv stringcalc/data/_orig/

# Run scripts
cd ../tmp/stringcalc/data
for f in *.py; do
if [ $f == "daddario_extract.py" ]; then continue; fi
python $f
for f in data/*.py; do
if [ $(basename $f) == "daddario_extract.py" ]; then continue; fi
uv run python $f
done

# Compare results to those in the repo
cd ../stringcalc/data
cd stringcalc/data
rc=0
for f in *.csv; do
echo $f
cmp $f $GITHUB_WORKSPACE/stringcalc/data/$f || rc=$?
cmp _orig/$f $f || rc=$?
done
exit $rc

Expand All @@ -78,26 +77,45 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install dependencies (micromamba)
uses: mamba-org/setup-micromamba@v2
- name: Set up Python
uses: actions/setup-python@v6
with:
environment-file: panel/environment.yml
cache-environment: true
cache-downloads: true
python-version: "3.13"

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install dependencies
run: |
uv sync --group panel

- name: Install stringcalc (${{ matrix.stringcalc }})
run: |
if [ "${{ matrix.stringcalc }}" == "local" ]; then
pip install . --no-deps
:
elif [ "${{ matrix.stringcalc }}" == "pypi" ]; then
pip install stringcalc
uv pip install stringcalc
else
exit 1
fi

- name: Run the app script
run: python panel/app.py
run: uv run python panel/app.py

- name: Check type annotations in app script
run: |
uv pip install mypy
uv run mypy --non-interactive panel/app.py

- name: Run mypy
- name: Build app (pyodide)
run: |
mypy --non-interactive panel/app.py
uv run panel convert panel/app.py --to pyodide
mv ./app.html ./stringcalc-panel.html

- name: Upload built app
if: matrix.stringcalc == 'pypi'
uses: actions/upload-artifact@v6
with:
name: panel
path: stringcalc-panel.html
retention-days: 1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ data/*.png
docs/api/
panel/app.html

uv.lock


# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
24 changes: 16 additions & 8 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ build:
os: ubuntu-lts-latest
tools:
python: "3.13"

python:
install:
- method: pip
path: .
extra_requirements:
- doc
- cli
jobs:
pre_create_environment:
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
create_environment:
- uv venv "${READTHEDOCS_VIRTUALENV_PATH}"
install:
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}"
uv sync
--group doc
--group panel
--extra cli
pre_build:
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}"
uv run panel convert panel/app.py --to pyodide --out docs/_static/panel/

sphinx:
configuration: docs/conf.py
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,29 @@ stringcalc gauge --suggest -T 17 -L 23 -P G2 -P D3 -P A3 -P E4 -N 6 --type DA:LE
```

<img src="./docs/cli_gauge-suggest_tb23nw.svg" alt="CLI gauge suggestion output for 23&quot; TB for D'Addario loop-end nickel-wound strings" width="550">

## Development

Using [uv](https://docs.astral.sh/uv/), prepare the venv:

```
uv sync --all-groups --all-extras
```

Run the tests:

```
uv run pytest
```

Build the Panel app:

```
uv run panel convert panel/app.py --to pyodide --out docs/_static/panel/
```

Build the docs:

```
uv run sphinx-build docs docs/_build/html
```
14 changes: 5 additions & 9 deletions data/aquila.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@

sys.path.append("../")

# import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from stringcalc.tension import load_data

plt.close("all")

HERE = Path(__file__).parent


Expand Down Expand Up @@ -60,10 +56,10 @@
#
# What do the data suggest that we are comparing to?

(1300 / df[["gauge_nylon_web", "gauge_nylon_pdf"]].pow(2).div(df.gauge.pow(2), axis="rows")).plot(
ylabel="estimated nylon density",
marker=".",
)
# (1300 / df[["gauge_nylon_web", "gauge_nylon_pdf"]].pow(2).div(df.gauge.pow(2), axis="rows")).plot(
# ylabel="estimated nylon density",
# marker=".",
# )

# Estimate density of D'Addario NYL strings
df2 = load_data().query("group_id == 'DA:NYL'").copy()
Expand All @@ -73,7 +69,7 @@
assert df2.rho.std() / df2.rho.mean() < 0.001
rho_bar = df2.rho.mean()

df2.plot(x="gauge", y="rho", ylabel="Computed D'Addario NYL density")
# df2.plot(x="gauge", y="rho", ylabel="Computed D'Addario NYL density")

# rho ~ 1/gauge^2 => rho gauge^2 = c
df["gauge_da_nylon"] = np.sqrt(1300 * df.gauge**2 / rho_bar)
Expand Down
4 changes: 0 additions & 4 deletions data/worth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

sys.path.append("../")

# import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

# from stringcalc.tension import load_data

plt.close("all")

HERE = Path(__file__).parent


Expand Down
2 changes: 2 additions & 0 deletions docs/_static/panel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
""",
}

html_static_path = ["_static"]

napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_preprocess_types = True
Expand Down
2 changes: 1 addition & 1 deletion docs/panel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Panel app
.. raw:: html

<iframe
src="https://filedn.com/l8PDOka7grmu3ycpLliPls4/stringcalc-panel.html"
src="_static/panel/app.html"
height="650px"
width="490px"
>
Expand Down
10 changes: 2 additions & 8 deletions panel/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
Conda env setup for development:

conda env create -f environment.yml
conda activate stringcalc-panel
pip install -e ../ --no-deps

For development:

panel serve --autoreload --show app.py
uv run panel serve --autoreload --show app.py

Create deployable HTML file
(first set env var `PYTHONUTF8` to `1` for Windows):

panel convert app.py --to pyodide
uv run panel convert app.py --to pyodide
21 changes: 15 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
license = {file = "LICENSE"}
classifiers = ["License :: OSI Approved :: MIT License"]
dynamic = ["version", "description"]
requires-python = "~=3.10"
requires-python = ">=3.10,<4"
dependencies = [
"numpy >=1.21",
"pandas",
Expand All @@ -23,6 +23,15 @@ Source = "https://github.com/zmoon/stringcalc"
Documentation = "https://stringcalc.readthedocs.io"

[project.optional-dependencies]
cli = [
"rich",
"typer",
]

[dependency-groups]
data = [
"requests",
]
test = [
"mypy",
"pandas-stubs",
Expand All @@ -32,10 +41,6 @@ test = [
dev = [
"ipython",
]
cli = [
"rich",
"typer",
]
doc = [
"matplotlib",
"myst-nb",
Expand All @@ -45,14 +50,18 @@ doc = [
"sphinx-click",
"sphinx-copybutton",
]
panel = [
"hvplot",
"panel ==1.*",
"watchfiles",
]

[project.scripts]
stringcalc = "stringcalc.cli:app"

[tool.flit.sdist]
exclude = ["data/", ".github/", "panel/", ".gitignore"]


[tool.black]
line-length = 100

Expand Down
1 change: 0 additions & 1 deletion stringcalc/data/daddario-stp.csv
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ XTNW042,0.00031405,0.042,Electric Guitar,Nickel Plated Steel,XTNW
XTNW046,0.00036969,0.046,Electric Guitar,Nickel Plated Steel,XTNW
XTNW049,0.00041459,0.049,Electric Guitar,Nickel Plated Steel,XTNW
XTNW052,0.00046223,0.052,Electric Guitar,Nickel Plated Steel,XTNW
XTNW059,0.00061817,0.059,Electric Guitar,Nickel Plated Steel,XTNW
XTPB022,9.7982e-05,0.022,Acoustic Guitar,Phosphor Bronze,XTPB
XTPB023,0.0001078,0.023,Acoustic Guitar,Phosphor Bronze,XTPB
XTPB024,0.00011612,0.024,Acoustic Guitar,Phosphor Bronze,XTPB
Expand Down