Skip to content

Commit d9d83d9

Browse files
authored
Building docs on Read the Docs, adding pre-commit formatting (#219)
1 parent 6108cf3 commit d9d83d9

30 files changed

Lines changed: 500 additions & 489 deletions

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cirrus_wheels_macos_arm64_task:
55
PATH: /opt/homebrew/opt/python@3.10/bin:$PATH
66
CIBW_ENVIRONMENT: >
77
MACOSX_DEPLOYMENT_TARGET=12.0
8-
_PYTHON_HOST_PLATFORM="macosx-12.0-arm64"
8+
_PYTHON_HOST_PLATFORM="macosx-12.0-arm64"
99
SPS_HOME="${CIRRUS_WORKING_DIR}/src/fsps/libfsps"
1010
PKG_CONFIG_PATH: /opt/arm64-builds/lib/pkgconfig
1111
CMAKE_PREFIX_PATH: /opt/arm64-builds/

.github/workflows/build_docs.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
name: Release
22
on:
3-
release:
4-
types: [published]
53
push:
6-
branches: [main]
7-
pull_request:
4+
branches:
5+
- main
6+
tags:
7+
- "*"
8+
# pull_request:
9+
workflow_dispatch:
10+
inputs:
11+
prerelease:
12+
description: "Run a pre-release, testing the build"
13+
required: false
14+
type: boolean
15+
default: false
816

917
concurrency:
1018
group: ${{ github.workflow }}-${{ github.ref }}
@@ -17,7 +25,7 @@ jobs:
1725
strategy:
1826
fail-fast: false
1927
matrix:
20-
os:
28+
os:
2129
- "ubuntu-latest"
2230
- "macos-latest"
2331
# - "windows-latest"
@@ -64,20 +72,27 @@ jobs:
6472
with:
6573
task: cirrus_wheels_macos_arm64
6674
commit: ${{ github.event.pull_request.head.sha || github.sha }}
67-
timeout-minutes: 15
75+
timeout-minutes: 15
6876
- run: ls dist
6977

70-
upload_pypi:
78+
publish:
79+
environment:
80+
name: pypi
81+
url: https://pypi.org/p/fsps
82+
permissions:
83+
id-token: write
7184
needs: [build_wheels, build_sdist]
7285
runs-on: ubuntu-latest
73-
if: github.event_name == 'release' && github.event.action == 'published'
86+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
7487
steps:
88+
- name: Get macOS arm64 wheels from Cirrus CI
89+
uses: getsentry/action-wait-for-cirrus@v1.0.0
90+
with:
91+
task: cirrus_wheels_macos_arm64
92+
commit: ${{ github.event.pull_request.head.sha || github.sha }}
93+
timeout-minutes: 15
7594
- uses: actions/download-artifact@v3
7695
with:
7796
name: artifact
7897
path: dist
7998
- uses: pypa/gh-action-pypi-publish@v1.8.7
80-
with:
81-
user: __token__
82-
password: ${{ secrets.pypi_password }}
83-
# To test: repository_url: https://test.pypi.org/legacy/

.github/workflows/tests.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,3 @@ jobs:
7070
run: python -m nox --non-interactive --no-error-on-missing-interpreters -s ${{ matrix.nox-session }}-${{ matrix.python-version }}
7171
env:
7272
SPS_HOME: ${{ github.workspace }}/src/fsps/libfsps
73-
74-
docs:
75-
if: github.event_name != 'pull_request'
76-
name: "docs"
77-
runs-on: ubuntu-latest
78-
steps:
79-
- name: Clone the repo
80-
uses: actions/checkout@v3
81-
with:
82-
fetch-depth: 0
83-
submodules: recursive
84-
- name: Set up Python
85-
uses: actions/setup-python@v4
86-
with:
87-
python-version: "3.9"
88-
- name: Install dependencies
89-
run: |
90-
python -m pip install -U pip sphinx
91-
python -m pip install .
92-
- name: Build documentation
93-
run: .github/workflows/build_docs.sh
94-
env:
95-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96-
SPS_HOME: ${{ github.workspace }}/src/fsps/libfsps
97-
STABLE: ${{ github.event_name == 'release' && github.event.action == 'published' }}

.github/workflows/update-fsps.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
with:
1313
submodules: true
1414
fetch-depth: 0
15-
15+
1616
- name: Update the submodule
1717
run: git submodule foreach git pull origin master
18-
18+
1919
- name: Create a PR
2020
uses: peter-evans/create-pull-request@v5
2121
with:
@@ -25,5 +25,5 @@ jobs:
2525
title: Updating FSPS
2626
body: |
2727
Automatically updating the FSPS submodule
28-
28+
2929
**Maintainers should close and then re-open this PR to get the tests to run.**

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: "v4.4.0"
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
exclude_types: [json, binary]
8+
- id: check-yaml
9+
- repo: https://github.com/psf/black
10+
rev: "23.1.0"
11+
hooks:
12+
- id: black-jupyter
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: "v0.0.277"
15+
hooks:
16+
- id: ruff
17+
args: [--fix, --exit-non-zero-on-fix]

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ find_package(
88

99
# Find the f2py headers
1010
execute_process(
11-
COMMAND "${PYTHON_EXECUTABLE}"
11+
COMMAND "${PYTHON_EXECUTABLE}"
1212
"${CMAKE_CURRENT_SOURCE_DIR}/tools/f2py_include.py"
1313
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
1414
OUTPUT_STRIP_TRAILING_WHITESPACE)

LICENSE.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2013-2021 Python-FSPS developers.
1+
Copyright 2013-2023 Python-FSPS developers.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of
44
this software and associated documentation files (the "Software"), to deal in

demos/dao69.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from __future__ import (division, print_function, absolute_import,
5-
unicode_literals)
6-
import pyfits
7-
import numpy as np
4+
from __future__ import absolute_import, division, print_function, unicode_literals
5+
86
import matplotlib.pyplot as pl
7+
import numpy as np
8+
import pyfits
9+
910
import fsps
1011

1112
# Measurements of cluster parameters.
12-
tage = 10. ** (8.04 - 9)
13+
tage = 10.0 ** (8.04 - 9)
1314
logmass = 4.09
1415
dist_mod = 24.5
1516

1617
# Set up the stellar population model.
1718
sp = fsps.StellarPopulation(imf_type=2, dust_type=1, mwr=3.1, dust2=0.3)
1819

1920
# The measured magnitudes from the literature.
20-
data = {"wfc3_f160w": 16.386,
21-
"wfc3_f275w": 17.398,
22-
"wfc_acs_f814w": 17.155}
21+
data = {"wfc3_f160w": 16.386, "wfc3_f275w": 17.398, "wfc_acs_f814w": 17.155}
2322

2423
# There are also a few filters that we have data for but aren't included in
2524
# the standard FSPS install:
@@ -39,15 +38,14 @@
3938

4039
# Compute the model magnitudes.
4140
for b, v in data.iteritems():
42-
print(b, v, sp.get_mags(zmet=20, tage=tage, band=b) - 2.5 * logmass
43-
+ dist_mod)
41+
print(b, v, sp.get_mags(zmet=20, tage=tage, band=b) - 2.5 * logmass + dist_mod)
4442

4543
# Compute the model spectrum in ``L_sun / A``.
4644
lam, spec = sp.get_spectrum(zmet=20, tage=tage, peraa=True)
47-
spec *= 3.839e33 * 10. ** (logmass - dist_mod / 2.5)
45+
spec *= 3.839e33 * 10.0 ** (logmass - dist_mod / 2.5)
4846

4947
f = 1.0 # obs_spec[0, obs_lambda < 5000.][-1] / spec[lam < 5000.][-1]
50-
print(obs_spec[0, obs_lambda < 5000.][-1] / spec[lam < 5000.][-1])
48+
print(obs_spec[0, obs_lambda < 5000.0][-1] / spec[lam < 5000.0][-1])
5149

5250
pl.loglog(obs_lambda, obs_spec[0], "k")
5351
pl.loglog(lam, spec * f, "r")

demos/feature_demo.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import os
10-
import numpy as np
10+
1111
import matplotlib.pyplot as pl
1212
from matplotlib.backends.backend_pdf import PdfPages
1313

@@ -18,19 +18,19 @@ def makefig(sps, tage=13.7, oldspec=None, **plotkwargs):
1818
w, spec = sps.get_spectrum(tage=tage)
1919
fig, ax = pl.subplots()
2020
if oldspec is not None:
21-
ax.plot(w, oldspec / w * 1e19, color='gray', linewidth=2, alpha=0.5)
22-
ax.plot(w, spec / w * 1e19, 'C2', linewidth=2)
21+
ax.plot(w, oldspec / w * 1e19, color="gray", linewidth=2, alpha=0.5)
22+
ax.plot(w, spec / w * 1e19, "C2", linewidth=2)
2323
return fig, ax, spec
2424

2525

2626
def prettify(fig, ax, label=None):
2727
ax.set_xlim(0.9e3, 1e6)
28-
ax.set_xscale('log')
28+
ax.set_xscale("log")
2929
ax.set_ylim(0.01, 2)
30-
#ax.set_yscale('log')
31-
ax.set_xlabel(r'rest-frame $\lambda$ ($\AA$)', fontsize=20)
32-
ax.set_ylabel(r'$\lambda \, f_\lambda$', fontsize=20)
33-
ax.tick_params(axis='both', which='major', labelsize=16)
30+
# ax.set_yscale('log')
31+
ax.set_xlabel(r"rest-frame $\lambda$ ($\AA$)", fontsize=20)
32+
ax.set_ylabel(r"$\lambda \, f_\lambda$", fontsize=20)
33+
ax.tick_params(axis="both", which="major", labelsize=16)
3434
if label is not None:
3535
ax.text(0.63, 0.85, label, transform=ax.transAxes, fontsize=16)
3636

@@ -39,94 +39,93 @@ def prettify(fig, ax, label=None):
3939

4040

4141
if __name__ == "__main__":
42-
43-
pl.rc('text', usetex=True)
44-
pl.rc('font', family='serif')
45-
pl.rc('axes', grid=False)
46-
pl.rc('xtick', direction='in')
47-
pl.rc('ytick', direction='in')
48-
pl.rc('xtick', top=True)
49-
pl.rc('ytick', right=True)
42+
pl.rc("text", usetex=True)
43+
pl.rc("font", family="serif")
44+
pl.rc("axes", grid=False)
45+
pl.rc("xtick", direction="in")
46+
pl.rc("ytick", direction="in")
47+
pl.rc("xtick", top=True)
48+
pl.rc("ytick", right=True)
5049

5150
sps = fsps.StellarPopulation(zcontinuous=1)
5251
ilib, slib, dlib = sps.libraries
5352
print(ilib, slib)
5453
os.makedirs("./figures", exist_ok=True)
55-
pdf = PdfPages('./figures/features.pdf')
54+
pdf = PdfPages("./figures/features.pdf")
5655

5756
# Basic spectrum
58-
sps.params['sfh'] = 4
59-
sps.params['tau'] = 5.0
60-
sps.params['logzsol'] = 0.0
61-
sps.params['dust_type'] = 4 # kriek and Conroy
62-
sps.params['imf_type'] = 2 # kroupa
63-
sps.params['imf3'] = 2.3
57+
sps.params["sfh"] = 4
58+
sps.params["tau"] = 5.0
59+
sps.params["logzsol"] = 0.0
60+
sps.params["dust_type"] = 4 # kriek and Conroy
61+
sps.params["imf_type"] = 2 # kroupa
62+
sps.params["imf3"] = 2.3
6463
fig, ax, spec = makefig(sps)
6564
fig, ax = prettify(fig, ax, label=r"$\tau=5$, Age$=13.7$,\\n$\log Z/Z_\odot=0.0$")
6665
pdf.savefig(fig)
6766
pl.close(fig)
6867

6968
# change IMF
70-
sps.params['imf3'] = 2.5
69+
sps.params["imf3"] = 2.5
7170
fig, ax, spec = makefig(sps, oldspec=spec)
7271
fig, ax = prettify(fig, ax, label=r"IMF slope")
7372
pdf.savefig(fig)
7473

7574
# Attenuate
76-
sps.params['add_dust_emission'] = False
77-
sps.params['dust2'] = 0.2
75+
sps.params["add_dust_emission"] = False
76+
sps.params["dust2"] = 0.2
7877
fig, ax, spec = makefig(sps, oldspec=spec)
7978
fig, ax = prettify(fig, ax, label=r"Dust Attenuation")
8079
pdf.savefig(fig)
8180
pl.close(fig)
8281

8382
# Dust emission
84-
sps.params['add_dust_emission'] = True
83+
sps.params["add_dust_emission"] = True
8584
fig, ax, spec = makefig(sps, oldspec=spec)
8685
fig, ax = prettify(fig, ax, label=r"Dust Emission")
8786
pdf.savefig(fig)
8887
pl.close(fig)
8988

9089
# Dust temperature
91-
sps.params['duste_umin'] = 10
90+
sps.params["duste_umin"] = 10
9291
fig, ax, spec = makefig(sps, oldspec=spec)
9392
fig, ax = prettify(fig, ax, label=r"Dust SED\\n({})".format(dlib))
9493
pdf.savefig(fig)
9594
pl.close(fig)
9695

9796
# AGN emission
98-
sps.params['fagn'] = 0.3
97+
sps.params["fagn"] = 0.3
9998
fig, ax, spec = makefig(sps, oldspec=spec)
10099
fig, ax = prettify(fig, ax, label=r"AGN dust\\n(Nenkova)")
101100
pdf.savefig(fig)
102101
pl.close(fig)
103102

104103
# Nebular emission
105-
sps.params['add_neb_emission'] = True
106-
sps.params['gas_logu'] = -3.5
104+
sps.params["add_neb_emission"] = True
105+
sps.params["gas_logu"] = -3.5
107106
fig, ax, spec = makefig(sps, oldspec=spec)
108107
fig, ax = prettify(fig, ax, label=r"Neb. emission\\n(Byler)")
109108
pdf.savefig(fig)
110109
pl.close(fig)
111110

112111
# change logu
113-
sps.params['gas_logu'] = -1.0
112+
sps.params["gas_logu"] = -1.0
114113
fig, ax, spec = makefig(sps, oldspec=spec)
115114
fig, ax = prettify(fig, ax, label=r"Change U$_{neb}$")
116115
pdf.savefig(fig)
117116
pl.close(fig)
118117

119118
# change logz
120-
sps.params['logzsol'] = -0.5
121-
sps.params['gas_logz'] = -0.5
119+
sps.params["logzsol"] = -0.5
120+
sps.params["gas_logz"] = -0.5
122121
fig, ax, spec = makefig(sps, oldspec=spec)
123122
fig, ax = prettify(fig, ax, label=r"$\log Z/Z_\odot=-0.5$")
124123
pdf.savefig(fig)
125124
pl.close(fig)
126125

127126
# IGM absorption
128-
sps.params['zred'] = 6.0
129-
sps.params['add_igm_absorption'] = True
127+
sps.params["zred"] = 6.0
128+
sps.params["add_igm_absorption"] = True
130129
fig, ax, spec = makefig(sps, oldspec=spec)
131130
fig, ax = prettify(fig, ax, label=r"IGM attenuation\\n(Madau, $z=6$)")
132131
pdf.savefig(fig)

0 commit comments

Comments
 (0)