Skip to content

Commit

Permalink
Fixes #1759
Browse files Browse the repository at this point in the history
Updated README.md to detail Python versions needed and how to set up local testing.
  • Loading branch information
rachel-lawrie committed Sep 4, 2024
1 parent 5e808ad commit 606ce92
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 19 deletions.
83 changes: 64 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ Currently, we don't typically assign contributors. If you see an open issue that

## Setting Up

1. Clone the repo
### 1. Clone the repo

```
git clone https://github.com/PolicyEngine/policyengine-api.git
```
To contribute, clone the repository instead of forking it and then request to be added as a contributor.

2. Activate your virtual environment
### 2. Activate your virtual environment

3. Install dependencies
### 3. Install dependencies

```
make install
```

4. In api.py, comment out
### 4. Start a server on localhost to see your changes

In api.py, comment out
```
CORS(app)
```
Expand All @@ -44,44 +46,87 @@ Add
CORS(app, resources={r"/*": {"origins": "*"}})
```

```
```
4. Start a server on localhost to see your changes
Then run:

```
make debug
```

Now you're ready to start developing!

5. To test in combination with policyengine-app:
In src/api/call.js, comment out
NOTE: If you are using Airpods or other Apple bluetooth products, you may get an error related to the port. If this is the case, define a specific port in the debug statement in the Makefile. For example:
```
debug:
FLASK_APP=policyengine_api.api FLASK_DEBUG=1 flask run --without-threads --port=5001
```

A simple API get call you can send in Postman to make sure it is working as expected is:
```
http://127.0.0.1:5001/us/policy/2
```

### 5. To test in combination with policyengine-app:

1. In policyengine-app/src/api/call.js, comment out
```
const POLICYENGINE_API = "https://api.policyengine.org";
```
And add
```
const POLICYENGINE_API = "http://127.0.0.1:5000" (or the relevant port where the server is running)
const POLICYENGINE_API = "http://127.0.0.1:5001" (or the relevant port where the server is running)
```
2. Start server as described above
3. Start app as described in policyengine-app/README.md

## Testing, Formatting, Changelogging
NOTE: Any output that needs to be calculated will not work. Therefore, only household output can be tested with this setup.

You've finished your contribution, but now what? Before opening a PR, we ask contributors to do three things.
### 6. Testing calculations

### Step 1: Testing
To test your changes against our series of automated tests, run
To test anything that utilizes Redis or the API's service workers (e.g. anything that requires calculations), you'll also need to complete the following steps:

1. Start Redis
- Install Redis:
```
make debug-test
brew install redis
```

If testing anything that utilizes Redis (unlikely) or the API's service workers (very unlikely), you'll also need to run one of the following:
- Start Redis:
```
redis-server
```
or
2. Start the API service worker
- This requires getting the POLICYENGINE_DB_PASSWORD from a teammate
- A teammate also must add you as a Google Cloud user and you will need to configure [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc#how-to) using your Google Account. Then complete the following steps:

3. Install Google Cloud CLI as described in the ADC documentation

4. Run the following to initialize it
```
gcloud init
```
When prompted "Pick cloud project to use:" Select the number that corresponds to "policyengine-api"
When prompted "Do you want to configure a default Compute Region and Zone? (Y/n)?" Select 'n'

Create the credentials:
```
gcloud auth application-default login
```

Return to policyengine-api folder and relevant python environment and run:
```
POLICYENGINE_DB_PASSWORD="" python policyengine_api/worker.py
```

NOTE: Calculations are not possible in the uk app without access to a specific dataset. Expect an error: "ValueError: Invalid response code 404 for url https://api.github.com/repos/policyengine/non-public-microdata/releases/tags/uk-2024-march-efo."

## Testing, Formatting, Changelogging

You've finished your contribution, but now what? Before opening a PR, we ask contributors to do three things.

### Step 1: Testing
To test your changes against our series of automated tests, run

```
python policyengine_api/worker.py
make debug-test
```

NOTE: Running the command `make test` will fail, as this command is utilized by the deployed app to run tests and requires passwords to the production database.
Expand Down
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
changed:
- README.md: Updated instructions for local testing and API configuration

0 comments on commit 606ce92

Please sign in to comment.