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

Merging Main Before Release #880

Merged
merged 6 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 4 additions & 47 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,22 @@
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#

version: 2

workflows:
version: 2
build:
jobs:
- test
- docs-build
- docs-build-deploy:
filters:
branches:
only: main

version: 2
jobs:
test:
docker:
- image: cimg/python:3.10

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v2-dependencies-python10-{{ checksum "requirements.txt" }}
# fallback to using the latest cache if no exact match is found
- v2-dependencies-python3.10-

- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt

- save_cache:
paths:
- ./venv
key: v2-dependencies-python3.10-{{ checksum "requirements.txt" }}

- run:
name: run tests
command: |
. venv/bin/activate
TESTING=1 pytest -rf test/

- run:
name: check linting
command: |
. venv/bin/activate
# E203 and W503 don't work well with black
flake8 parsons/ test/ useful_resources/ --extend-ignore=E203,W503
black --check parsons/ test/ useful_resources/

- store_artifacts:
path: test-reports
destination: test-reports

# Documentation CI
docs-build:
docker:
- image: cimg/python:3.10
Expand Down
22 changes: 22 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
changelog:
categories:
- title: New Features
labels:
- connector-update
- new-connector
- parsons-core
- title: Automated Testing
labels:
- testing
- title: Bug Fixes
labels:
- bug-fix
- title: Documentation
labels:
- documentation
# - title: New Contributors
# labels:
# -🎉-first-PR
- title: Other Changes
labels:
- "*"
51 changes: 51 additions & 0 deletions .github/workflows/test-linux-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: tests

on:
pull_request:
branches: ["main"]
push:
branches: ["main"]

env:
TESTING: 1

jobs:
build:
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
os: [ubuntu-latest] # add in windows-latest to add windows testing
include:
- os: ubuntu-latest
path: ~/.cache/pip
# - os: windows-latest
# path: ~\AppData\Local\pip\Cache
runs-on: ${{ matrix.os }}

steps:

- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v3
with:
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: python -m pip install -r requirements.txt

- name: Run tests
run: pytest -rf test/

- name: check linting
run: |
# E203 and W503 don't work well with black
flake8 parsons/ test/ useful_resources/ --extend-ignore=E203,W503
black --check parsons/ test/ useful_resources/
43 changes: 43 additions & 0 deletions .github/workflows/tests-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: tests for mac
# test mac on single python version as mac tests use 10x minutes/storage

on:
pull_request:
branches: ["main"]
push:
branches: ["main"]

env:
TESTING: 1

jobs:
build:
runs-on: macos-latest

steps:

- uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

- uses: actions/cache@v3
with:
path: ~/Library/Caches/pip
key: mac-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
mac-pip-

- name: Install dependencies
run: python -m pip install -r requirements.txt

- name: Run tests
run: TESTING=1 pytest -rf test/

- name: check linting
run: |
# E203 and W503 don't work well with black
flake8 parsons/ test/ useful_resources/ --extend-ignore=E203,W503
black --check parsons/ test/ useful_resources/
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
language_version: python3
args: [
'--extend-ignore=E203,W503',
'--max-line-length=100'
]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ Run the following commands from the root of the Parsons repository to lint your
> black parsons
```

Pre-commit hooks are available to enforce black and isort formatting on
commit. You can also set up your IDE to reformat using black and/or isort on
save.

To set up the pre-commit hooks, install pre-commit with `pip install
pre-commit`, and then run `pre-commit install`.

#### Coding Conventions

The following is a list of best practices to consider when writing code for the Parsons project:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Parsons offers simplified interactions with these services and tools, including

This project is maintained by [The Movement Cooperative](https://movementcooperative.org/) and is named after [Lucy Parsons](https://en.wikipedia.org/wiki/Lucy_Parsons). The Movement Cooperative is a member-led organization focused on providing data, tools, and strategic support for the progressive community.

Parsons is only compatible with Python 3.7-10
Parsons is only supported for Python 3.8-10.

## Table of Contents
- [License and Usage](#license-and-usage)
Expand Down
33 changes: 24 additions & 9 deletions parsons/action_network/action_network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import re
import warnings

from parsons import Table
from parsons.utilities import check_env
Expand Down Expand Up @@ -100,6 +101,7 @@ def upsert_person(
mobile_number=None,
mobile_status="subscribed",
background_processing=False,
identifiers=None,
**kwargs,
):
"""
Expand Down Expand Up @@ -153,6 +155,16 @@ def upsert_person(
an immediate success, with an empty JSON body, and send your request to the
background queue for eventual processing.
https://actionnetwork.org/docs/v2/#background-processing
identifiers:
List of strings to be used as globally unique
identifiers. Can be useful for matching contacts back
to other platforms and systems. If the identifier
provided is not globally unique in ActionNetwork, it will
simply be ignored and not added to the object. Action Network
also creates its own identifier for each new resouce.
https://actionnetwork.org/docs/v2/#resources
e.g.: ["foreign_system:1", "other_system:12345abcd"]

**kwargs:
Any additional fields to store about the person. Action Network allows
any custom field.
Expand Down Expand Up @@ -217,7 +229,8 @@ def upsert_person(
data["person"]["postal_addresses"] = postal_addresses
if tags is not None:
data["add_tags"] = tags

if identifiers:
data["person"]["identifiers"] = identifiers
data["person"]["custom_fields"] = {**kwargs}
url = f"{self.api_url}/people"
if background_processing:
Expand Down Expand Up @@ -321,21 +334,23 @@ def update_person(self, entry_id, background_processing=False, **kwargs):
logger.info(f"Person {entry_id} successfully updated")
return response

def get_tags(self, limit=None, per_page=25, page=None):
def get_tags(self, limit=None, per_page=None):
"""
`Args:`
limit:
The number of entries to return. When None, returns all entries.
per_page
The number of entries per page to return. 25 maximum.
page
Which page of results to return
per_page:
This is a deprecated argument.
`Returns:`
A list of JSONs of tags in Action Network.
"""
if page:
self.get_page("tags", page, per_page)
return self._get_entry_list("tags", limit, per_page)
if per_page:
warnings.warn(
"per_page is a deprecated argument on get_tags()",
DeprecationWarning,
stacklevel=2,
)
return self._get_entry_list("tags", limit)

def get_tag(self, tag_id):
"""
Expand Down
81 changes: 80 additions & 1 deletion parsons/pdi/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self):
self.calendars_url = self.base_url + "/calendars"
self.eventactivities_url = self.base_url + "/eventActivities"
self.activites_url = self.base_url + "/activities"
self.activityassignment_url = self.base_url + "/eventActivityAssignements"
self.activityassignment_url = self.base_url + "/eventActivityAssignments"

super().__init__()

Expand Down Expand Up @@ -506,3 +506,82 @@ def update_activity_assignment(
)

return response

def get_event_activity_assignments(self, start_date, end_date, expand, limit=None):
"""
Get a list of event activity assignments.
Relevant API docs:
https://api.bluevote.com/docs/index#/EventActivityAssignments

`Args`:
start_date: str
Earliest records to be returned in the API response
Per the API docs, use "YYYY-MM-DD" format

end_date: str
Latest records to be returned in the API response.
Per the API docs, use "YYYY-MM-DD" format

expand: bool
Parameter to determine if we return the list of shift assigments
expanded or not

limit: int
Specify limit to return (max=2000)

`Returns`:
Parsons Table with event activity assignment responses
"""

if limit and limit > 2000:
raise ValueError("Maximum allowed limit is 2000")

params = {"startDate": start_date, "endDate": end_date, "expand": expand}
return self._request(self.activityassignment_url, args=params, limit=limit)

def get_event_activities(self, start_date, end_date, limit=None):
"""
Get a list of event activities.
Relevant API docs:
https://api.bluevote.com/docs/index#!/EventActivities/EventActivities_GetAll

`Args`:
start_date: str
Earliest records to be returned in the API response
Per the API docs, use "YYYY-MM-DD" format

end_date: str
Latest records to be returned in the API response.
Per the API docs, use "YYYY-MM-DD" format

limit: int
Specify limit to return (max=2000)

`Returns`:
Parsons Table with event activity responses
"""

if limit and limit > 2000:
raise ValueError("Maximum allowed limit is 2000")

params = {"startDate": start_date, "endDate": end_date}
return self._request(self.eventactivities_url, args=params, limit=limit)

def get_calendars(self, limit=None):
"""
Gets a list of calendars.
Relevant API docs:
https://api.bluevote.com/docs/index#!/Calendars/Calendars_GetAll

`Args`:
limit: int
Specify limit to return (max=2000)

`Returns`:
Parsons Table object with id, name, description, and timeZone records
"""

if limit and limit > 2000:
raise ValueError("Maximum allowed limit is 2000")

return self._request(self.calendars_url, limit=limit)
Loading