Skip to content
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

[4/4] [test-built] Test against packaged version #1037

Draft
wants to merge 3 commits into
base: orga-pack
Choose a base branch
from

Conversation

bonjourmauko
Copy link
Member

@bonjourmauko bonjourmauko commented Aug 25, 2021

Depends on #1059
Fixes #1064

See openfisca/country-template#59

Technical changes

  • Test openfisca-core against its packaged version
    • Doing so allows to prevent publishing corrupted versions
    • What we test is what the user gets when installing openfisca-core

@bonjourmauko bonjourmauko added the kind:devops Continuous ops, integration & deployment label Aug 25, 2021
Copy link
Member

@MattiSG MattiSG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @maukoquiroga! I definitely see the value of testing against the packaged version.

However, I am not 100% of the implementation. I understand it mirrors the one in OpenFisca-France, which already seemed very convoluted to me.

I have many questions, which I added as comments here. Until they are addressed, I am not even certain I can request specific changes.

In terms of implementation, I am a bit concerned that this effort seems to overlap with #1030, #1031 and openfisca/openfisca-france#1663, but I don't see good reason to hold from improving the situation even just for a few days. As discussed yesterday over video, I will try to consolidate a vision for where different steps should be described (CI config vs makefile vs OpenFisca CLI).

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
.circleci/config.yml Outdated Show resolved Hide resolved
Makefile Outdated
@## of openfisca-core, the same we put in the hands of users and reusers.
pip install --upgrade pip wheel
python $< bdist_wheel
find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we reinstall with dev dependencies if this is supposed to be the “packaged” version? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the find dist -name "*.whl" step more appropriately expressed as find dist -name "*.whl" -exec rm in the clean target, and pip install run after the clean when we want to publish?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we're doing it wrong at the outset: we're using pip install .[x] to install dependencies, which is actually to install openfisca core and the dependencies. Those need to be separate steps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, replaced with a more proper -yet not perfect- way of doing it, in the absence of requirement files:

python setup.py egg_info  # Create a requirements file.
pip install `grep -v "^\[" *.egg-info/requires.txt`  # Install openfisca's dependencies.

Note that this is going to install openfisca-core via country-template and extension-template, so we're forced to reinstall openfisca-core.

But, we will reinstall only openfisca-core:

python setup.py bdist_wheel
find dist -name "*.whl" -exec pip install --force-reinstall --no-dependencies {} \;

Copy link
Member

@MattiSG MattiSG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for having answered my questions, and thank you for having refined this PR! It seems to grow, which is good in terms of features but bad in terms of review duration 😅

The current implementation goes against RFC #1040, as it adds many specific commands to the CI. It seems necessary to now converge to having everything in the task manager (which is currently make, for better or for worse). This will enable testing the packaged version and publishing from any machine that can execute the Makefile. The CI should only call it.

I am not sure I understand why this changeset:

  1. Moves all test files and splits them between core and web_api.
  2. Changes some type hints.

@@ -17,21 +17,34 @@ jobs:
python -m venv /tmp/venv/openfisca_core
echo "source /tmp/venv/openfisca_core/bin/activate" >> $BASH_ENV

- run:
name: Install base utils
command: pip install --upgrade pip setuptools wheel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since #1040, this should be a make target.

Comment on lines 39 to 41
command: |
python setup.py bdist_wheel
find dist -name "*.whl" -exec pip install --force-reinstall --no-dependencies {} \; # https://github.com/openfisca/openfisca-core/pull/1015#discussion_r687051988
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since #1040, this should be a make target.

name: Run openfisca-core tests
command: |
make clean check-syntax-errors check-style check-types
PYTEST_ADDOPTS="$PYTEST_ADDOPTS --cov=openfisca_core --exitfirst" pytest --pyargs openfisca_core.tests openfisca_web_api.tests # Run the tests on the built & installed version of openfisca.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use pytest instead of calling the make target?
Since #1040, this should be a make target.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this is outdated.

conftest.py Outdated
Comment on lines 2 to 5
"tests.fixtures.appclient",
"tests.fixtures.entities",
"tests.fixtures.simulations",
"tests.fixtures.taxbenefitsystems",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand why this was deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because otherwise we can't predictably test the built packages in an isolated way.

PyTest decided to forbid users to have more than one conftest per project. I don't know why they did that, but it forces us to remove it if we want isolation as we actually ship two packages independently, core and web-api.

One alternative is to ship all together, which makes a bit more sense.

Today we have:

openfisca_core
openfisca_web_api
tests (not shipped)

With this PR we will have:

openfisca_core
openfisca_core.tests
etc.

In order for this file to be kept, we would have to do something like

src/openfisca_core
str/openfisca_web_api

It is my preferred approach, but it seemed too much of a change.

Comment on lines 27 to 28
python setup.py egg_info # Create a requirements file.
pip install `grep -v "^\[" *.egg-info/requires.txt` # Install openfisca's dependencies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since #1040, this should be a make target.

@bonjourmauko
Copy link
Member Author

Thank you very much for having answered my questions, and thank you for having refined this PR! It seems to grow, which is good in terms of features but bad in terms of review duration 😅

The current implementation goes against RFC #1040, as it adds many specific commands to the CI. It seems necessary to now converge to having everything in the task manager (which is currently make, for better or for worse). This will enable testing the packaged version and publishing from any machine that can execute the Makefile. The CI should only call it.

I am not sure I understand why this changeset:

  1. Changes some type hints.

Yes, this predates that conversation, I'll modify the things on that sense.

  1. Moves all test files and splits them between core and web_api.

Because, currently, the tests module is not being packaged, hence there is no possible way to run the tests against the built package —in a way the user would do it, which is the whole idea of the thing.

What ensues is indeed a more standard and opinionated way of structuring a package, as country-template already does.

  1. Changes some type hints.

Me neither: mypy is supposed to ignore the tests module, it can be safely removed.

@MattiSG
Copy link
Member

MattiSG commented Sep 24, 2021

Thank you for these clarifications. Let's have a synchronous discussion on the only outstanding issue: packaging the tests 🙂

@bonjourmauko bonjourmauko modified the milestone: Improve testing & releases Sep 29, 2021
@bonjourmauko bonjourmauko added the kind:roadmap A group of issues, constituting a delivery roadmap label Sep 29, 2021
@bonjourmauko bonjourmauko added this to the Improved releases milestone Sep 29, 2021
@bonjourmauko bonjourmauko changed the title Test against packaged version [2/2] Test against packaged version Sep 29, 2021
@bonjourmauko bonjourmauko changed the title [2/2] Test against packaged version [3/3] Test against packaged version Oct 1, 2021
@bonjourmauko bonjourmauko changed the base branch from master to fix-build October 1, 2021 15:32
@bonjourmauko bonjourmauko changed the title [3/3] Test against packaged version [3/3] [test-built] Test against packaged version Oct 1, 2021
@bonjourmauko bonjourmauko changed the title [3/3] [test-built] Test against packaged version [4/4] [test-built] Test against packaged version Oct 1, 2021
@bonjourmauko bonjourmauko changed the base branch from fix-build to orga-pack October 1, 2021 17:15
@bonjourmauko bonjourmauko removed the kind:roadmap A group of issues, constituting a delivery roadmap label Oct 7, 2021
@bonjourmauko bonjourmauko marked this pull request as draft December 9, 2022 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:devops Continuous ops, integration & deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants