-
Notifications
You must be signed in to change notification settings - Fork 76
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
Make Web API optional #703
Conversation
This actually doesn't work, because... of pip! Ha ha, who could have guessed? Looking to find a better solution tomorrow, but that's not blocking for the review, as there is not much we can do on this repo about that. |
Error message when running
|
e7df364
to
37591a4
Compare
CHANGELOG.md
Outdated
- Transparent for users of the `openfisca serve` command. | ||
- Users who used to manually import `openfisca_web_api_preview` must know import `openfisca_web_api`. | ||
|
||
##### Rename development dependencies to `dev`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make
test
dependencies tag update more discoverable? : ##### Rename test dependencies todev
README.md
Outdated
@@ -6,7 +6,9 @@ This package contains the core features of OpenFisca, which are meant to be used | |||
|
|||
## Environment | |||
|
|||
This package requires Python 2.7 | |||
OpenFisca runs on Python 3.6, or more recent versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.6 🙌
And remove , or more recent versions
according to recent issues when moving between 3.* versions
README.md
Outdated
@@ -17,7 +19,7 @@ If you want to contribute to OpenFisca-Core itself, welcome! To install it local | |||
```bash | |||
git clone https://github.com/openfisca/openfisca-core.git | |||
cd openfisca-core | |||
pip install --editable ".[test]" | |||
pip install --editable ".[api, dev]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to say that the API comes from api
tag while it also comes with dev
that installs openfisca-country-template
(as openfisca-country-template
comes with 'OpenFisca-Core[api] >= 24.0, < 25.0',
in its next version). 😕
I don't know exactly what's better; make a new tag in country-template that depends on Core without api and call it in dev?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to say that the API comes from api tag while it also comes with dev that installs openfisca-country-template (as openfisca-country-template comes with 'OpenFisca-Core[api] >= 24.0, < 25.0', in its next version). 😕
Does this cause any concrete issue?
The way pip probably sees it is:
- Install the extra dependency
api
- Install the extra dependency
dev
- Install
OpenFisca-Country-Template
- This requires
OpenFisca-Core[api]
, but this is already installed, so doing nothing.
- This requires
- Install
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not comfortable with this solution for multiple reasons :
api
isn't really useful here- it might be confusing for a user that removes
api
frompip install --editable ".[api, dev]"
to find api dependencies installed - we are changing
pip install -e .
definition for everyone
To imitate an opt-out @fpagnoux, what do you think of the following code for setup.py
? :
import os
api_requirements = [
'flask == 0.12',
'flask-cors == 3.0.2',
'gunicorn >= 19.7.1',
]
OPENFISCA_API = os.environ.get('OPENFISCA_API')
if OPENFISCA_API == "no":
api_requirements = []
and :
install_requires = [
'Biryani[datetimeconv] >= 0.10.8',
'dpath == 1.4.0',
'enum34 >= 1.1.6',
'future',
'numpy >= 1.11, < 1.15',
'psutil == 5.4.6',
'PyYAML >= 3.10',
'sortedcontainers == 1.5.9',
api_requirements
],
where OPENFISCA_API
environment variable would only be needed for opt-out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm interesting, I didn't think about tweaking the setup.py
that way.
Let me check if that really works, but if it does I'm happy to switch to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, while tweaking the setup.py
is definitely a great idea (and will solve Anna-Livia's concern) , the environment variable doesn't work in real conditions.
If I run OPT_OUT_API=true pip install -e .
, everything works as expected and the API dependencies are not installed.
However, if I run:
OPT_OUT_API=true pip install 'OpenFisca-Core >= 24.0.0.dev2, < 25'
, the environment variable is ignored, and the API dependencies are installed.
I think the setup.py
file is executed only:
- when installing Core locally with
pip install .
- when publishing with
python setup.py bdist_wheel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I included api
dependencies into dev
, which should address your two first concerns, as well as @Anna-Livia's.
However, yes:
we are changing
pip install -e .
definition for everyone
but, as of today, we didn't find a way to implement an "opt-out" dependency. We reached this conclusion in June, and while your suggestion was definitely welcome and worth trying, it didn't work.
The only approach I could see to keep the API included by default would be to publish alternative packages OpenFisca-Core-Lite
and OpenFisca-France-Lite
that don't include the API, but that's really heavy.
So, unless someone has a better solution, making the API installation an opt-in, while opting in by default in the country template seems the most reasonable thing to do if we want to make it possible to install OpenFisca without the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these tests. Would it be ok for you to give us 24 more hours to figure something out? With @Anna-Livia, we are looking into pip options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok 🙂. Keep me posted if you find something!
@@ -1,5 +1,7 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
from __future__ import print_function | |||
from __future__ import unicode_literals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1,3 +1,4 @@ | |||
from __future__ import unicode_literals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part comes from #702, which this PR depends on.
For consistency, we chose to import all __future__
backports in all files.
openfisca_core/variables.py
Outdated
@@ -358,6 +358,9 @@ def get_introspection_data(cls, tax_benefit_system): | |||
source_file_path = absolute_file_path.replace(tax_benefit_system.get_package_metadata()['location'], '') | |||
try: | |||
source_lines, start_line_number = inspect.getsourcelines(cls) | |||
# Python 2 backward compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed here
openfisca_web_api/loader/spec.py
Outdated
@@ -16,7 +16,7 @@ def build_openAPI_specification(tax_benefit_system, country_package_metadata): | |||
country_package_name = country_package_metadata['name'].title() | |||
spec['info']['title'] = spec['info']['title'].replace("{COUNTRY_PACKAGE_NAME}", country_package_name) | |||
spec['info']['description'] = spec['info']['description'].replace("{COUNTRY_PACKAGE_NAME}", country_package_name) | |||
spec['host'] = os.environ.get('SERVER_NAME') | |||
spec['info']['version'] = country_package_metadata['version'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
setup.py
Outdated
'nose', | ||
'flake8 >= 3.4.0, < 3.5.0', | ||
'openfisca-country-template >= 3.2.2rc0, < 4.0.0', | ||
'openfisca-country-template >= 3.2.3, < 4.0.0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>= 3.3.0, 4.0.0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary to pass the tests, and I'd rather not do it to avoid the complexity of releasing inter-dependent packages with rc0
versions.
tests/core/test_scenarios.py
Outdated
@@ -1,3 +1,4 @@ | |||
from __future__ import unicode_literals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part comes from #702, which this PR depends on.
For consistency, we chose to import all __future__
backports in all files.
CHANGELOG.md
Outdated
#### New features | ||
|
||
- In the `/spec` route: | ||
- Indicate the country package version instead of `0.1.0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indicate served country package version as API version
?
Sorry, it was probably not super clear that part of the diff is from another PR. |
It was very strange as a developper to have |
So, I looked into the Env Vars. The reason it works with There is a way to pass env vars, but very specific Anywho, in my mind, we have two options : Looking forward to have your opinion on this :) |
I don't think this makes sense for the people who asked to make the Web API install optional. Economists who install OpenFisca in a secure environment don't want to install Core in editable mode. That would actually prevent them from relying on versioning.
I think api should be in the dependency title. What about making it fully explicit: |
.circleci/config.yml
Outdated
@@ -22,7 +22,7 @@ jobs: | |||
name: Install dependencies | |||
command: | | |||
pip install --upgrade pip twine wheel | |||
pip install --editable .[test] --upgrade | |||
pip install --editable ".[api, dev]" --upgrade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the lastest changes, shouldn't it be pip install --editable ".[dev]" --upgrade
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, forgot that one!
|
||
To run it with the mock country package `openfisca_country_template` and another port value as `5000`, run: | ||
To run it with the mock country package `openfisca_country_template` and another port value such as `2000`, run: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we should mention that openfisca_country_template
should be installed with the api extra requirements.
proposition :
To serve the Web-API, you need to install a country package with the [web_api] extra require.
e.g.
pip install openfisca-country-template[web_api]
To run it with the mock country package openfisca_country_template
and another port value such as 2000
, run:
[...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, in the country template PR there is no web_api
extra dependencies and it is required by default.
Also it is not possible to install the web api with something like pip install Openfisca-France[web-api]
that would require Openfisca-Core[web-api]
.
7db48a0
to
49ff624
Compare
And rename test -> dev
49ff624
to
7e39a95
Compare
7e39a95
to
b8c3a4d
Compare
Depends on #702
Fixes #641
Fixes #592
Fixes #665
Fixes #663 (by integrating @MattiSG's changes from the
openapi
branch)Breaking changes
Only install the Web API dependencies as an opt-in:
pip install OpenFisca-Core
will not install the Web API anymore.pip install OpenFisca-Core[api]
will.Country package maintainers who still want to provide the Web API by default with their package (recommended) should update their
setup.py
:install_requires
section, replace'OpenFisca-Core >= 23.3, < 24.0'
by'OpenFisca-Core[api] >= 24.0, < 25.0'
Country package maintainers who want to provide the Web API as an opt-in of their package should update theirsetup.py
:In theextras_require
section, add anapi
block containing['OpenFisca-Core[api]']
See exampleNOTE: This doesn't work, there is no way to "forward" the extra dependency from france to core
Change default Web API port to 5000:
openfisca serve
will now serve by default on the5000
port instead of6000
(blocked by Chrome).Rename OpenFisca Web Api package to
openfisca_web_api
:openfisca serve
command.openfisca_web_api_preview
must know importopenfisca_web_api
.New features
/spec
route:0.1.0
.SERVER_NAME
environnement variable.SERVER_NAME
environnement variable is therefore deprecated and without effect.