Skip to content

Commit

Permalink
Add setup code
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Aug 9, 2021
1 parent c56e8c0 commit 7435ed3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
48 changes: 11 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,23 @@
all: test stats
all: microdata

uninstall:
pip freeze | grep -v "^-e" | xargs pip uninstall -y
install:
pip install -e .

clean:
rm -rf build dist
find . -name '*.pyc' -exec rm \{\} \;
microdata:
python openfisca_uk/initial_setup.py

deps:
pip install --upgrade pip twine wheel

install: deps
@# Install OpenFisca-Extension-Template for development.
@# `make install` installs the editable version of OpenFisca-France.
@# This allows contributors to test as they code.
pip install --editable .[dev] --upgrade

build: clean deps
@# Install OpenFisca-Extension-Template for deployment and publishing.
@# `make build` allows us to be be sure tests are run against the packaged version
@# of OpenFisca-Extension-Template, the same we put in the hands of users and reusers.
python setup.py bdist_wheel
find dist -name "*.whl" -exec pip install --upgrade {}[dev] \;

check-syntax-errors:
python -m compileall -q .

format-style:
@# Do not analyse .gitignored files.
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
autopep8 `git ls-files | grep "\.py$$"`

check-style:
@# Do not analyse .gitignored files.
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
flake8 `git ls-files | grep "\.py$$"`
format:
black . -l 79

test:
openfisca test tests/baseline
openfisca test tests/reforms/with_postcode_features -r openfisca_uk.config.postcode_lookup.with_postcode_features
pytest tests/setup
openfisca test -c openfisca_uk tests/baseline
openfisca test -c openfisca_uk tests/reforms/with_postcode_features -r openfisca_uk.config.postcode_lookup.with_postcode_features
pytest tests/code
pytest tests/with_microdata
black . -l 79 --check

serve-local: build
serve: build
openfisca serve --country-package openfisca_uk

stats:
Expand Down
3 changes: 3 additions & 0 deletions openfisca_uk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
reported_benefits,
reported,
)
from pathlib import Path

REPO = Path(__file__).parent

COUNTRY_DIR = os.path.dirname(os.path.abspath(__file__))

Expand Down
5 changes: 4 additions & 1 deletion openfisca_uk/situation_examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def single_person_UC_two_children(sim):
sim.add_person(name="child", age=4)
sim.add_person(name="child_2", age=6)
sim.add_benunit(
adults=["adult"], children=["child", "child_2"], claims_UC=True
adults=["adult"],
children=["child", "child_2"],
claims_UC=True,
claims_CB=True,
)
sim.add_household(adults=["adult"], children=["child", "child_2"])
return sim
Expand Down
22 changes: 19 additions & 3 deletions openfisca_uk/tools/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@
import microdf as mdf
from tqdm import trange
import warnings
from openfisca_uk_data import FRS, BaseFRS
from openfisca_uk.tools.parameters import backdate_parameters
from openfisca_data import UK_DATASETS, SynthFRS
import yaml
from pathlib import Path

with open(Path(__file__).parent / "datasets.yml") as f:
datasets = yaml.safe_load(f)
DEFAULT_DATASET = list(
filter(lambda ds: ds.name == datasets["default"], UK_DATASETS)
)[0]


warnings.filterwarnings("ignore")

Expand Down Expand Up @@ -212,11 +221,18 @@ def vary(self, var, min=0, max=200000, step=100, index=0, period=None):


class Microsimulation:
def __init__(self, *reforms: Tuple[Reform], year: int = None, dataset=FRS):
def __init__(
self,
*reforms: Tuple[Reform],
year: int = None,
dataset=DEFAULT_DATASET,
):
self.dataset = dataset
self.passed_reforms = reforms
if dataset == SynthFRS and len(SynthFRS.years) == 0:
SynthFRS.save()
if year is None:
self.year = max(dataset().years)
self.year = max(dataset.years)
else:
self.year = year
self.reforms = (
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"pyyaml>=5.3.1",
"pytest>=5.4.3",
"OpenFisca-Core>=35.4.1",
"openfisca-uk-data @ git+https://github.com/nikhilwoodruff/openfisca-uk-data",
"openfisca-data @ git+https://github.com/ubicenter/openfisca-uk-data",
"tqdm>=4.59.0",
"microdf @ git+https://github.com/PSLmodels/microdf",
"plotly>=4.14.3",
Expand All @@ -45,5 +45,10 @@
"pycodestyle >=2.3.0,<2.6.0", # To avoid incompatibility with flake
]
},
entry_points={
"console_scripts": [
"openfisca-uk-setup=openfisca_uk.initial_setup:main"
],
},
packages=find_packages(),
)

0 comments on commit 7435ed3

Please sign in to comment.