Skip to content

Use individual notebook requirements #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
47dc84e
astropy-coordinates: add missing requirements
jeffjennings Sep 26, 2024
01fb56e
position-velocity-diagrams: add missing requirements
jeffjennings Sep 26, 2024
db3619e
spectral-cube-reprojection: add missing requirements
jeffjennings Sep 26, 2024
a0c3bc7
SpectroscopicDataReductionBasics: add missing requirements
jeffjennings Sep 26, 2024
a958494
FITS-images: add missing requirements
jeffjennings Sep 26, 2024
572e9fe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 26, 2024
d12c0be
spectral-cube-reprojection requirements: pin numpy version
jeffjennings Sep 27, 2024
90c0393
add requirements cell to notebooks
jeffjennings Sep 27, 2024
a96e3d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 27, 2024
02a05d6
all notebooks: move requirements cell down; ensure preamable is in si…
jeffjennings Sep 27, 2024
f0fc52c
Revert "all notebooks: move requirements cell down; ensure preamable …
jeffjennings Sep 27, 2024
b0cfc3b
move requirements cell down
jeffjennings Sep 27, 2024
1dea047
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 27, 2024
c9286aa
move requirements cell down for notebooks that are not diff'ing corre…
jeffjennings Sep 27, 2024
643d454
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 27, 2024
adabae2
remove top-level requirements.txt
jeffjennings Oct 1, 2024
98241f8
comment requirements-dev.txt
jeffjennings Oct 1, 2024
d28cac4
Makefile: remove env_check command
jeffjennings Oct 1, 2024
0980b4e
Makefile: remove redundant install
jeffjennings Oct 1, 2024
f2b1ef2
Makefile: add requirement paths var
jeffjennings Oct 1, 2024
5e36fab
Makefile: rewrite execute and convert commands
jeffjennings Oct 1, 2024
fcf4b49
Merge branch 'main' into requirements
jeffjennings Oct 1, 2024
54b2dbd
pin minimum astroquery version in individual requirements files
jeffjennings Oct 1, 2024
7b48c9a
Makefile: loop for 'all' commands
jeffjennings Oct 2, 2024
5dcfe7b
get_modified_tutorials: add option to return all tutorial paths
jeffjennings Oct 2, 2024
772c4ec
notebooks: replace pylab and PIL requirements with matplotlib.pyplot …
jeffjennings Oct 2, 2024
190d956
new and updated notebook .fits and .png outputs
jeffjennings Oct 2, 2024
28a71e1
UVES tutorial: add overwrite flag to prevent build failure
jeffjennings Oct 2, 2024
a8effc2
Makefile: bash syntax
jeffjennings Oct 9, 2024
123394f
CI: force bash shell for 'make' steps
jeffjennings Oct 9, 2024
77ed929
bash test
jeffjennings Oct 10, 2024
de5b0d1
set shell in makefile
jeffjennings Oct 10, 2024
5b8553c
try solve notebook kernel issue
jeffjennings Oct 10, 2024
a4a6808
test add ipykernel to requirements
jeffjennings Oct 10, 2024
0a8fa60
make: suppress verbose install stdout
jeffjennings Oct 10, 2024
302e9af
test spectral-cube requirement
jeffjennings Oct 10, 2024
31f6b66
set spectral-cube requirement to current git repo
jeffjennings Oct 10, 2024
3277c57
force converted notebook overwrite
jeffjennings Oct 10, 2024
cc18cf2
makefile typo
jeffjennings Oct 10, 2024
efedb6a
makefile typo 2
jeffjennings Oct 10, 2024
2030aa0
test only using convert
jeffjennings Oct 10, 2024
dde73e1
update CI file to use `build` and `buildall`
jeffjennings Oct 10, 2024
7a68244
remove timout flag from convert
jeffjennings Oct 10, 2024
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
58 changes: 42 additions & 16 deletions .github/get_modified_tutorials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from git import Repo
from pathlib import Path


def main(repo_path, main_branch, **kw):
def get_all_tutorials():
paths = ""
for path in Path("./tutorials").rglob("*.ipynb"):
paths += f" {path}"
print(paths)


def main(repo_path, main_branch, return_all, **kw):
if return_all:
return get_all_tutorials()

repo = Repo(repo_path)

# Check committed changes on this branch against the main branch,
Expand All @@ -10,16 +21,20 @@ def main(repo_path, main_branch, **kw):
diff_lists = [
repo.commit(main_branch).diff(repo.head),
repo.head.commit.diff(),
repo.head.commit.diff(None)
repo.head.commit.diff(None),
]

files_changed = set()
for diffs in diff_lists:
files_changed = files_changed.union([
diff.b_path for diff in diffs
if diff.change_type in ['M', 'A', 'R'] # modified, added, renamed
and diff.b_path.endswith('.ipynb')
])
files_changed = files_changed.union(
[
diff.b_path
for diff in diffs
if diff.change_type
in ["M", "A", "R"] # modified, added, renamed
and diff.b_path.endswith(".ipynb")
]
)

if files_changed:
print(" ".join(files_changed))
Expand All @@ -30,17 +45,28 @@ def main(repo_path, main_branch, **kw):

parser = ArgumentParser()
parser.add_argument(
'-r', '--repo-path',
dest='repo_path',
default='.',
help='The path to the root of the astropy-tutorials repository folder.'
"-r",
"--repo-path",
dest="repo_path",
default=".",
help="The path to the root of the astropy-tutorials repository folder.",
)
parser.add_argument(
"--main-branch",
dest="main_branch",
default="main",
help=(
"The name of the main branch to compare against. Default is "
'"main" but on CI it should be origin/main.'
),
)
parser.add_argument(
'--main-branch',
dest='main_branch',
default='main',
help=('The name of the main branch to compare against. Default is '
'"main" but on CI it should be origin/main.')
"--return_all",
dest="return_all",
default=False,
help=(
"Whether to return all tutorials rather than just those modified."
),
)
args = parser.parse_args()
main(**vars(args))
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ jobs:
- name: Execute the notebooks
run: |
make executeall
shell: bash

- name: Convert the notebooks to HTML
run: |
make convertall
shell: bash

- name: Name artifact
id: nameartifact
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ jobs:
if: contains(github.event.pull_request.labels.*.name, 'Run all tutorials')
run: |
export TUTORIALS_MAIN_BRANCH=origin/main
make executeall
make convertall
make clean
make buildall
shell: bash

# Otherwise, only run tutorials that have been modified
- name: Run only modified tutorials
if: "!contains(github.event.pull_request.labels.*.name, 'Run all tutorials')"
run: |
export TUTORIALS_MAIN_BRANCH=origin/main
make execute
make convert
make build
shell: bash

- name: Name artifact
id: nameartifact
Expand Down
57 changes: 45 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
default: build

SHELL := /bin/bash

TUTORIALS_MAIN_BRANCH ?= main
MODIFIED := $(shell python .github/get_modified_tutorials.py --main-branch $(TUTORIALS_MAIN_BRANCH))

# paths to the individual notebooks that have been modified
MODIFIED_NOTEBOOKS := $(shell python .github/get_modified_tutorials.py --main-branch $(TUTORIALS_MAIN_BRANCH))
# paths to the individual requirements.txt files in the directories in which 1+ notebooks have been modified
MODIFIED_RQT_PATHS := $(foreach var,$(MODIFIED_NOTEBOOKS),$(addsuffix requirements.txt,$(dir $(var))))

ALL_NOTEBOOKS := $(shell python .github/get_modified_tutorials.py --main-branch $(TUTORIALS_MAIN_BRANCH) --return_all true)
ALL_RQT_PATHS := $(foreach var,$(ALL_NOTEBOOKS),$(addsuffix requirements.txt,$(dir $(var))))

FLAGS = --flatten --build-path=. -v
CONVERTFLAGS = --make-index --preprocessors=nbconvert.preprocessors.ExtractOutputPreprocessor --index-template=templates/index.tpl
CONVERTFLAGS = --make-index --preprocessors=nbconvert.preprocessors.ExtractOutputPreprocessor --index-template=templates/index.tpl --overwrite

init:
python -m pip install -U -r requirements-dev.txt
pre-commit install

build: envcheck execute convert
buildall: envcheck executeall convertall

envcheck:
python -c "import pkg_resources; pkg_resources.require(open('requirements.txt', mode='r')); print('Your environment is all set!')"
build: convert
buildall: convertall

execute:
nbcollection execute --timeout=600 ${FLAGS} ${MODIFIED}
i=0; \
_paths=($(MODIFIED_RQT_PATHS)); \
for notebook in ${MODIFIED_NOTEBOOKS}; do \
echo Installing requirements from $${_paths[i]}; \
python -m pip install --force-reinstall -r $${_paths[i]} > /dev/null; \
nbcollection execute --timeout=600 ${FLAGS} $$notebook; \
i=$$((i+1)); \
done

convert:
nbcollection convert ${CONVERTFLAGS} ${FLAGS} ${MODIFIED}
i=0; \
_paths=($(MODIFIED_RQT_PATHS)); \
for notebook in ${MODIFIED_NOTEBOOKS}; do \
echo Installing requirements from $${_paths[i]}; \
python -m pip install --force-reinstall -r $${_paths[i]} > /dev/null; \
nbcollection convert ${CONVERTFLAGS} ${FLAGS} $$notebook; \
i=$$((i+1)); \
done

executeall:
nbcollection execute --timeout=600 ${FLAGS} tutorials
i=0; \
_paths=(${ALL_RQT_PATHS}); \
for notebook in ${ALL_NOTEBOOKS}; do \
echo Installing requirements from $${_paths[i]}; \
python -m pip install --force-reinstall -r $${_paths[i]} > /dev/null; \
nbcollection execute --timeout=600 ${FLAGS} $$notebook; \
i=$$((i+1)); \
done

convertall:
nbcollection convert ${CONVERTFLAGS} ${FLAGS} tutorials
i=0; \
_paths=($(ALL_RQT_PATHS)); \
for notebook in ${ALL_NOTEBOOKS}; do \
echo Installing requirements from $${_paths[i]}; \
python -m pip install --force-reinstall -r $${_paths[i]} > /dev/null; \
nbcollection convert ${CONVERTFLAGS} ${FLAGS} $$notebook; \
i=$$((i+1)); \
done

clean:
rm -rf _build
Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-r requirements.txt
# Note: these are the requirements *in addition to* those listed in the unique
# requirements for each set of notebooks - see astropy-tutorials/tutorials/*/requirements.txt
gitpython
git+https://github.com/astropy/nbcollection
pre-commit
ipykernel
16 changes: 0 additions & 16 deletions requirements.txt

This file was deleted.

20 changes: 10 additions & 10 deletions tutorials/FITS-cubes/FITS-cubes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
"\n",
"The primary libraries we'll be using are: [astroquery](http://www.astropy.org/astroquery/), [spectral_cube](https://spectral-cube.readthedocs.io/en/latest/), [reproject](https://reproject.readthedocs.io/en/stable/#), [matplotlib](https://matplotlib.org/)) \n",
"\n",
"They can be installed using conda:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"They can be installed using conda:\n",
"\n",
"```\n",
"conda install -c conda-forge astroquery\n",
"conda install -c conda-forge spectral-cube\n",
"conda install -c conda-forge reproject\n",
"```"
"```\n",
"\n",
"Alternatively, if you don't use conda, you can use pip."
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Alternatively, if you don't use conda, you can use pip."
"with open('requirements.txt') as f:\n",
" print(f\"Required packages for this notebook:\\n{f.read()}\")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions tutorials/FITS-cubes/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
astropy
astroquery
astroquery>=0.4.8.dev9474 # 2024-09-24 pinned for Gaia column capitalization issue
matplotlib
numpy
reproject
spectral_cube
spectral_cube @ git+https://github.com/radio-astro-tools/spectral-cube # as of: 2024-10-10 for issue with 'distutils'
10 changes: 10 additions & 0 deletions tutorials/FITS-header/FITS-header.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"keyword."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open('requirements.txt') as f:\n",
" print(f\"Required packages for this notebook:\\n{f.read()}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file modified tutorials/FITS-header/input_file.fits
Binary file not shown.
10 changes: 10 additions & 0 deletions tutorials/FITS-images/FITS-images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
"This tutorial demonstrates the use of `astropy.utils.data` to download a data file, then uses `astropy.io.fits` to open the file, and lastly uses `matplotlib` to view the image with different color scales and stretches and to make histograms. In this tutorial we've also included a demonstration of simple image stacking."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open('requirements.txt') as f:\n",
" print(f\"Required packages for this notebook:\\n{f.read()}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
3 changes: 3 additions & 0 deletions tutorials/FITS-images/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
astropy
matplotlib
numpy
10 changes: 10 additions & 0 deletions tutorials/FITS-tables/FITS-tables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"This tutorial demonstrates the use of `astropy.utils.data` to download a data file, then uses `astropy.io.fits` and `astropy.table` to open the file. Lastly, `matplotlib` is used to visualize the data as a histogram."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open('requirements.txt') as f:\n",
" print(f\"Required packages for this notebook:\\n{f.read()}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
10 changes: 10 additions & 0 deletions tutorials/Models-Quick-Fit/Models-Quick-Fit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"In this tutorial, we will become familiar with the models available in [astropy.modeling](http://docs.astropy.org/en/stable/modeling/ ) and learn how to make a quick fit to our data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open('requirements.txt') as f:\n",
" print(f\"Required packages for this notebook:\\n{f.read()}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion tutorials/Models-Quick-Fit/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
astropy
astroquery
astroquery>=0.4.8.dev9474 # 2024-09-24 pinned for Gaia column capitalization issue
matplotlib
numpy
scipy
Loading
Loading