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

Move flake8, black, and pytest configs to pyproject.toml #1013

Merged
merged 4 commits into from
Apr 4, 2024
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
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test-linux-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
- name: Run tests
run: pytest -rf test/

- name: check linting
- name: Check linting
run: |
# E203 and W503 don't work well with black
flake8 parsons/ test/ useful_resources/ --extend-ignore=E203,W503
flake8 parsons/ test/ useful_resources/
black --check parsons/ test/ useful_resources/
6 changes: 3 additions & 3 deletions .github/workflows/tests-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
python -m pip install -r requirements-dev.txt

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

- name: check linting
- name: Check linting
run: |
# E203 and W503 don't work well with black
flake8 parsons/ test/ useful_resources/ --extend-ignore=E203,W503
flake8 parsons/ test/ useful_resources/
black --check parsons/ test/ useful_resources/
12 changes: 5 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
repos:
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
language_version: python3
args: [
'--extend-ignore=E203,W503',
'--max-line-length=100'
]
'--extend-ignore=E203,W503',
'--max-line-length=100'
]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.2.0
hooks:
- id: black
language_version: python3
111 changes: 78 additions & 33 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

49 changes: 35 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
# Parsons

[![Downloads](https://pepy.tech/badge/parsons)](https://pepy.tech/project/parsons)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/parsons)](https://pypi.org/project/parsons/)
[![PyPI](https://img.shields.io/pypi/v/parsons?color=blue)](https://pypi.org/project/parsons/)
[![CircleCI](https://circleci.com/gh/move-coop/parsons/tree/main.svg?style=shield)](https://circleci.com/gh/move-coop/parsons/tree/main)

A Python package that provides a simple interface to a variety of utilities and tools frequently used by progressive organizations, political and issue campaigns, activists, and other allied actors.
A Python package that provides a simple interface to a variety of utilities and tools frequently used by progressive
organizations, political and issue campaigns, activists, and other allied actors.

Parsons offers simplified interactions with these services and tools, including a growing number of CRMs, organizing tools, cloud compute service providers, as well as tools to easily transform data in transit.
Parsons offers simplified interactions with these services and tools, including a growing number of CRMs, organizing
tools, cloud compute service providers, as well as tools to easily transform data in transit.

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.
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 supported for Python 3.8-10.

## Table of Contents

- [License and Usage](#license-and-usage)
- [Documentation](#documentation)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [Community](#community)
- [Community](#community)

## License and Usage
Usage of Parsons is governed by a [modified Apache License with author attribution statement](https://github.com/move-coop/parsons/blob/main/LICENSE.md).

Usage of Parsons is governed by
a [modified Apache License with author attribution statement](https://github.com/move-coop/parsons/blob/main/LICENSE.md).

## Documentation
To gain a full understanding of all of the features of Parsons, please review the Parsons [documentation](https://move-coop.github.io/parsons/html/index.html).

## Installation
To gain a full understanding of all of the features of Parsons, please review the
Parsons [documentation](https://move-coop.github.io/parsons/html/index.html).

## Installation

### PYPI
You can install the most recent release by running: `pip install parsons[all]`

You can install the most recent release by running: `pip install parsons[all]`

### Install from Github

To access the most recent code base that may contain features not yet included in the latest release, download this repository and then run `python setup.py develop`.
To access the most recent code base that may contain features not yet included in the latest release, download this
repository and then run `python setup.py develop`.

### Docker Container
We have a Parsons Docker container hosted on [DockerHub](https://hub.docker.com/r/movementcooperative/parsons) for each release of Parsons, including the `latest`.

We have a Parsons Docker container hosted on [DockerHub](https://hub.docker.com/r/movementcooperative/parsons) for each
release of Parsons, including the `latest`.

## Quickstart

For this Quickstart, we are looking to generate a list of voters with cell phones using a [dummy data file](docs/quickstart.csv). We use the `assert` statements to verify that the data has been loaded correctly.
For this Quickstart, we are looking to generate a list of voters with cell phones using
a [dummy data file](docs/quickstart.csv). We use the `assert` statements to verify that the data has been loaded
correctly.

```python
# Download the Census data from the Parsons GitHub repository
from parsons import GitHub

github = GitHub()
dummy_data = github.download_table('move-coop/parsons', 'docs/quickstart.csv')
assert dummy_data.num_rows == 1000 # Check that we got all 1,000 people
Expand All @@ -56,20 +71,26 @@ assert people_with_cell_phones.num_rows == 498 # Check that we filtered down to

# Extract only the columns we need (first name, last name, phone number)
people_with_cell_phones = people_with_cell_phones.cut('first_name', 'last_name', 'phone_number')
assert people_with_cell_phones.columns == ['first_name', 'last_name', 'phone_number'] # Check columns
assert people_with_cell_phones.columns == ['first_name', 'last_name', 'phone_number'] # Check columns

# Output the list to a local CSV file
filename = people_with_cell_phones.to_csv() # filename will be the path to the local CSV file

# In order to upload data to a Google Sheet, you will need to set the GOOGLE_DRIVE_CREDENTIALS
# environment variable
from parsons import GoogleSheets

sheets = GoogleSheets()
sheet_id = sheets.create_spreadsheet('Voter Cell Phones')
sheets.append_to_sheet(sheet_id, people_with_cell_phones)
```

## Community
We hope to foster a strong and robust community of individuals who use and contribute to further development. Individuals are encouraged to submit issues with bugs, suggestions and feature requests. [Here](https://github.com/move-coop/parsons/blob/main/CONTRIBUTING.md) are the guidelines and best practices for contributing to Parsons.

You can also stay up to date by joining the Parsons Slack group, an active community of Parsons contributors and progressive data engineers. For an invite, just reach out to engineering+parsons@movementcooperative.org!
We hope to foster a strong and robust community of individuals who use and contribute to further development.
Individuals are encouraged to submit issues with bugs, suggestions and feature
requests. [Here](https://github.com/move-coop/parsons/blob/main/CONTRIBUTING.md) are the guidelines and best practices
for contributing to Parsons.

You can also stay up to date by joining the Parsons Slack group, an active community of Parsons contributors and
progressive data engineers. For an invite, just reach out to engineering+parsons@movementcooperative.org!
4 changes: 1 addition & 3 deletions parsons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@
("parsons.zoom.zoom", "Zoom"),
):
try:
globals()[connector_name] = getattr(
importlib.import_module(module_path), connector_name
)
globals()[connector_name] = getattr(importlib.import_module(module_path), connector_name)
__all__.append(connector_name)
except ImportError:
logger.debug(f"Could not import {module_path}.{connector_name}; skipping")
23 changes: 6 additions & 17 deletions parsons/actblue/actblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ class ActBlue(object):
visit https://secure.actblue.com/docs/csv_api#authentication.
"""

def __init__(
self, actblue_client_uuid=None, actblue_client_secret=None, actblue_uri=None
):
self.actblue_client_uuid = check_env.check(
"ACTBLUE_CLIENT_UUID", actblue_client_uuid
)
self.actblue_client_secret = check_env.check(
"ACTBLUE_CLIENT_SECRET", actblue_client_secret
)
def __init__(self, actblue_client_uuid=None, actblue_client_secret=None, actblue_uri=None):
self.actblue_client_uuid = check_env.check("ACTBLUE_CLIENT_UUID", actblue_client_uuid)
self.actblue_client_secret = check_env.check("ACTBLUE_CLIENT_SECRET", actblue_client_secret)
self.uri = (
check_env.check("ACTBLUE_URI", actblue_uri, optional=True)
or ACTBLUE_API_ENDPOINT
check_env.check("ACTBLUE_URI", actblue_uri, optional=True) or ACTBLUE_API_ENDPOINT
)
self.headers = {
"accept": "application/json",
Expand Down Expand Up @@ -86,9 +79,7 @@ def post_request(self, csv_type=None, date_range_start=None, date_range_end=None
"date_range_start": date_range_start,
"date_range_end": date_range_end,
}
logger.info(
f"Requesting {csv_type} from {date_range_start} up to {date_range_end}."
)
logger.info(f"Requesting {csv_type} from {date_range_start} up to {date_range_end}.")
response = self.client.post_request(url="csvs", json=body)
return response

Expand Down Expand Up @@ -160,9 +151,7 @@ def get_contributions(self, csv_type, date_range_start, date_range_end):
Contents of the generated contribution CSV as a Parsons table.
"""

post_request_response = self.post_request(
csv_type, date_range_start, date_range_end
)
post_request_response = self.post_request(csv_type, date_range_start, date_range_end)
csv_id = post_request_response["id"]
download_url = self.poll_for_download_url(csv_id)
table = Table.from_csv(download_url)
Expand Down
41 changes: 13 additions & 28 deletions parsons/action_builder/action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def _get_page(self, campaign, object_name, page, per_page=25, filter=None):

return self.api.get_request(url=url, params=params)

def _get_all_records(
self, campaign, object_name, limit=None, per_page=25, filter=None
):
def _get_all_records(self, campaign, object_name, limit=None, per_page=25, filter=None):
# Returns a list of entries for a given object, such as people, tags, or connections.
# See Action Builder API docs for more: https://www.actionbuilder.org/docs/v1/index.html

Expand All @@ -72,9 +70,7 @@ def _get_all_records(
# Keep getting the next page until record limit is exceeded or an empty result returns
while True:
# Get this page and increase page number to the next one
response = self._get_page(
campaign, object_name, page, per_page, filter=filter
)
response = self._get_page(campaign, object_name, page, per_page, filter=filter)
page = page + 1

# Check that there's actually data
Expand Down Expand Up @@ -237,9 +233,7 @@ def update_entity_record(self, identifier, data, campaign=None):
identifier = [identifier]

# Default to assuming identifier comes from Action Builder and add prefix if missing
identifiers = [
f"action_builder:{id}" if ":" not in id else id for id in identifier
]
identifiers = [f"action_builder:{id}" if ":" not in id else id for id in identifier]

if not isinstance(data, dict):
data = {}
Expand All @@ -252,9 +246,7 @@ def update_entity_record(self, identifier, data, campaign=None):

return self._upsert_entity(data=data, campaign=campaign)

def add_section_field_values_to_record(
self, identifier, section, field_values, campaign=None
):
def add_section_field_values_to_record(self, identifier, section, field_values, campaign=None):
"""
Add one or more tags (i.e. custom field value) to an existing entity record in Action
Builder. The tags, along with their field and section, must already exist (except for
Expand Down Expand Up @@ -285,9 +277,7 @@ def add_section_field_values_to_record(

data = {"add_tags": tag_data}

return self.update_entity_record(
identifier=identifier, data=data, campaign=campaign
)
return self.update_entity_record(identifier=identifier, data=data, campaign=campaign)

def remove_tagging(
self,
Expand Down Expand Up @@ -329,9 +319,7 @@ def remove_tagging(
raise ValueError("Please supply a tag_name or tag_id!")

if {identifier, tagging_id} == {None}:
raise ValueError(
"Please supply an entity or connection identifier, or a tagging id!"
)
raise ValueError("Please supply an entity or connection identifier, or a tagging id!")

campaign = self._campaign_check(campaign)
endpoint = "tags/{}/taggings"
Expand All @@ -354,10 +342,11 @@ def remove_tagging(
if tag_id and not tagging_id:
taggings = self._get_all_records(self.campaign, endpoint.format(tag_id))
taggings_filtered = taggings.select_rows(
lambda row: identifier
in row["_links"]["action_builder:connection"]["href"]
if row["item_type"] == "connection"
else identifier in row["osdi:person"]["href"]
lambda row: (
identifier in row["_links"]["action_builder:connection"]["href"]
if row["item_type"] == "connection"
else identifier in row["osdi:person"]["href"]
)
)
tagging_id = [
x.split(":")[1]
Expand All @@ -370,9 +359,7 @@ def remove_tagging(
f"campaigns/{campaign}/{endpoint.format(tag_id)}/{tagging_id}"
)

def upsert_connection(
self, identifiers, tag_data=None, campaign=None, reactivate=True
):
def upsert_connection(self, identifiers, tag_data=None, campaign=None, reactivate=True):
"""
Load or update a connection record in Action Builder between two existing entity records.
Only one connection record is allowed per pair of entities, so if the connection already
Expand Down Expand Up @@ -457,9 +444,7 @@ def deactivate_connection(

# Check that either connection or second entity identifier are provided
if {connection_identifier, to_identifier} == {None}:
raise ValueError(
"Must provide a connection ID or an ID for the second entity"
)
raise ValueError("Must provide a connection ID or an ID for the second entity")

campaign = self._campaign_check(campaign)

Expand Down
Loading