Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
50 lines (39 loc) · 2.05 KB
/
Copy pathMakefile
File metadata and controls
50 lines (39 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
PROJECT_NAME = PoliticalAlignmentCaseStudy
PYTHON_INTERPRETER = python
## mamba solves this environment much faster than conda; use conda if that is
## what you have
CONDA = mamba
.PHONY: default create_environment update_environment delete_environment requirements clean tests tests-clean format
default:
@echo "No command specified. Please specify a target."
create_environment:
$(CONDA) env create -f environment.yml
@echo ">>> conda env created. Activate with:\nconda activate $(PROJECT_NAME)"
update_environment:
$(CONDA) env update -f environment.yml --prune
delete_environment:
conda env remove --name $(PROJECT_NAME)
requirements:
$(PYTHON_INTERPRETER) -m pip install -U pip setuptools wheel
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
clean:
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete
## The notebooks that read the committed gss_pacs_resampled.hdf
tests:
pytest --nbmake 0[2345]*.ipynb
## 01_clean downloads the GssExtract source and writes gss_pacs_clean.hdf and
## gss_pacs_resampled.hdf into its working directory, so run it in a copy
## under build/ to keep it from replacing the committed files. Then check that
## the rebuilt files match the committed ones.
tests-clean:
python -c "import os, shutil; os.makedirs('build/clean', exist_ok=True); shutil.copy('01_clean.ipynb', 'build/clean')"
cd build/clean && pytest --nbmake 01_clean.ipynb
python -c "import pandas as pd; [pd.testing.assert_frame_equal(pd.read_hdf('build/clean/' + f, k), pd.read_hdf(f, k)) for f, ks in [('gss_pacs_clean.hdf', ['gss']), ('gss_pacs_resampled.hdf', ['gss0', 'gss1', 'gss2'])] for k in ks]; print('rebuilt data match the committed files')"
## Format the notebooks listed in ruff.toml, then list lines still over the
## limit (strings and comments, which the formatter doesn't wrap). Afterwards,
## regenerate 02_polviews.ipynb: cp 02_polviews_soln.ipynb 02_polviews.ipynb
## && python remove_soln.py (build.sh does that too, but also pushes).
format:
ruff format
ruff check --select E501 --output-format concise || true