Skip to content

Commit 3af6fce

Browse files
authored
Improved CI/CD pipeline, added dependencies, and other miscellaneous improvements (#211)
* Enable workflow_dispatch for pr_code_changes * trying to get action to run * changing workflow to require Python 3.12 * adding MinimalInstallCheck * pyproject.toml * Readme updates and Windows smoke test * adding back the actions space * comment out __file__ override * dynamically getting yaml file. Removing commented code * workflow updates * Token work, matrix OS testing * lints * environment variables are put back * Windows encodings fixed for documentation. Github code reset * updated clean function and docs * Makefile changes * getting rid of workflow comments * added comma * taking out 3.10 * getting rid of growth factors * trying a different dependency naming
1 parent f1b33e5 commit 3af6fce

File tree

12 files changed

+93
-289
lines changed

12 files changed

+93
-289
lines changed

.github/workflows/code_changes.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
with:
3939
workload_identity_provider: "projects/322898545428/locations/global/workloadIdentityPools/policyengine-research-id-pool/providers/prod-github-provider"
4040
service_account: "policyengine-research@policyengine-research.iam.gserviceaccount.com"
41-
4241
- name: Install package
4342
run: uv pip install -e .[dev] --system
4443
- name: Download data inputs
@@ -57,4 +56,4 @@ jobs:
5756
env:
5857
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
5958
- name: Test documentation builds
60-
run: make documentation
59+
run: make documentation

.github/workflows/pr_code_changes.yaml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
paths:
1010
- policyengine_us_data/**
1111
- tests/**
12+
- .github/workflows/**
1213

1314
jobs:
1415
Lint:
@@ -19,32 +20,68 @@ jobs:
1920
uses: "lgeiger/black-action@master"
2021
with:
2122
args: ". -l 79 --check"
23+
24+
SmokeTestForMultipleVersions:
25+
name: Test Minimal Install & Import (${{ matrix.os }}, py${{ matrix.python-version }})
26+
runs-on: ${{ matrix.os }}
27+
needs: Lint
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
os: [ubuntu-latest, windows-latest]
32+
python-version: ['3.11', '3.12']
33+
steps:
34+
- name: Checkout repo
35+
uses: actions/checkout@v4
36+
37+
- name: Set up Python ${{ matrix.python-version }}
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: ${{ matrix.python-version }}
41+
42+
- name: Install package ONLY (no dev deps)
43+
run: python -m pip install .
44+
45+
- name: Test basic import
46+
run: python -c "import policyengine_us_data; print('Minimal import OK')"
47+
48+
- name: Test specific core import
49+
run: python -c "from policyengine_core.data import Dataset; print('Core import OK')"
50+
2251
Test:
23-
runs-on: ubuntu-latest
52+
runs-on: ${{ matrix.os }}
53+
needs: Lint
54+
strategy:
55+
matrix:
56+
os: [ubuntu-latest, windows-latest]
57+
env:
58+
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
2459
steps:
2560
- name: Checkout repo
2661
uses: actions/checkout@v2
62+
2763
- name: Install uv
2864
uses: astral-sh/setup-uv@v5
2965

3066
- name: Set up Python
3167
uses: actions/setup-python@v2
3268
with:
3369
python-version: '3.11'
34-
3570
- name: Install package
3671
run: uv pip install -e .[dev] --system
72+
3773
- name: Download data inputs
3874
run: make download
3975
env:
4076
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
41-
POLICYENGINE_US_DATA_GITHUB_TOKEN: ${{ secrets.POLICYENGINE_US_DATA_GITHUB_TOKEN }}
77+
4278
- name: Build datasets
4379
run: make data
4480
env:
4581
TEST_LITE: true
4682
PYTHON_LOG_LEVEL: INFO
4783
- name: Run tests
4884
run: pytest
85+
4986
- name: Test documentation builds
50-
run: make documentation
87+
run: make documentation

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ documentation:
3535

3636

3737
data:
38+
python policyengine_us_data/utils/uprating.py
3839
python policyengine_us_data/datasets/acs/acs.py
3940
python policyengine_us_data/datasets/cps/cps.py
4041
python policyengine_us_data/datasets/puf/irs_puf.py
@@ -43,8 +44,9 @@ data:
4344
python policyengine_us_data/datasets/cps/enhanced_cps.py
4445

4546
clean:
46-
rm -f policyengine_us_data/storage/puf_2015.csv
47-
rm -f policyengine_us_data/storage/demographics_2015.csv
47+
rm -f policyengine_us_data/storage/*.h5
48+
git clean -fX -- '*.csv'
49+
rm -rf policyengine_us_data/docs/_build
4850

4951
build:
5052
python -m build

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
## Installation
44

5+
While it is possible to install via PyPi:
56
```bash
67
pip install policyengine-us-data
78
```
9+
the recommended installion is
10+
```
11+
pip install -e .[dev]
12+
```
13+
which installs the development dependencies in a reference-only manner (so that changes
14+
to the package code will be reflected immediately); `policyengine-us-data` is a dev package
15+
and not intended for direct access.
816

917
## Building the Paper
1018

docs/add_plotly_to_book.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
book_folder = Path(args.book_path)
1515

1616
for html_file in book_folder.glob("**/*.html"):
17-
with open(html_file, "r") as f:
17+
with open(html_file, "r", encoding="utf-8") as f:
1818
html = f.read()
1919

2020
# Add the script tag to the start of the <head> tag.
@@ -23,5 +23,5 @@
2323
'<head><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>',
2424
)
2525

26-
with open(html_file, "w") as f:
26+
with open(html_file, "w", encoding="utf-8") as f:
2727
f.write(html)

policyengine_us_data/datasets/cps/cps.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from importlib.resources import files
12
from policyengine_core.data import Dataset
23
from policyengine_us_data.storage import STORAGE_FOLDER
34
import h5py
@@ -529,10 +530,13 @@ def add_personal_income_variables(
529530
year (int): The CPS year
530531
"""
531532
# Get income imputation parameters.
532-
yamlfilename = os.path.join(
533-
os.path.abspath(os.path.dirname(__file__)),
534-
"imputation_parameters.yaml",
533+
yamlfilename = (
534+
files("policyengine_us_data")
535+
/ "datasets"
536+
/ "cps"
537+
/ "imputation_parameters.yaml"
535538
)
539+
536540
with open(yamlfilename, "r", encoding="utf-8") as yamlfile:
537541
p = yaml.safe_load(yamlfile)
538542
assert isinstance(p, dict)

policyengine_us_data/datasets/puf/uprate_puf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
from policyengine_us_data.storage import STORAGE_FOLDER
44

5+
56
ITMDED_GROW_RATE = 0.02 # annual growth rate in itemized deduction amounts
67

78
USE_VARIABLE_SPECIFIC_POPULATION_GROWTH_DIVISORS = False
@@ -95,7 +96,6 @@ def get_soi_aggregate(variable, year, is_count):
9596
if variable == "adjusted_gross_income" and is_count:
9697
# AGI isn't treated like the other variables
9798
return get_soi_aggregate("count", year, True)
98-
9999
is_variable = soi.Variable == variable
100100
is_year = soi.Year == year
101101
filing_status = soi["Filing status"] == "All"

policyengine_us_data/storage/uprating_factors.csv

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

0 commit comments

Comments
 (0)