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

Publish openstate-core metadata #143

Merged
merged 15 commits into from
Oct 4, 2024
Merged
21 changes: 20 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,30 @@ jobs:
uses: snok/[email protected]
- name: configure pypi credentials
run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}"
- name: Publish package
- name: Publish core package
run: poetry publish --build
- name: install dependencies
run: poetry install
- name: update metadata
env:
DATABASE_URL: ${{ secrets.OPENSTATES_DATABASE_URL }}
run: poetry run os-initdb
# Add steps for openstates_metadata package
- name: Create directory and copy openstates_metadata
run: |
mkdir -p core_metadata
cp -r openstates/metadata core_metadata
- name: Change directory to core_metadata
run: cd core_metadata
- name: Move configuration files
run: |
mv metadata/pyproject.toml.sample pyproject.toml
mv metadata/.python-version.sample .python-version
mv metadata/README.md.sample README.md
mv metadata openstates_metadata
- name: Install dependencies for openstates_metadata
run: poetry install
- name: Configure pypi credentials for metadata package
run: poetry config pypi-token.pypi "${{ secrets.OPENSTATES_METADATA_PYPI_API_KEY }}"
- name: Publish openstates_metadata package
run: poetry publish --build
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.20.6 - Sept 18, 2024

* Add steps to publish lightweight openstates-metadata

## 6.20.5 - Sept 18, 2024

* Improve Event to Person matching
Expand Down
12 changes: 9 additions & 3 deletions openstates/importers/organizations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from django.db.models import Q
from ._types import _JsonDict
from .base import BaseImporter
Expand All @@ -12,13 +13,18 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict:
if spec.get("classification") != "party":
spec["jurisdiction_id"] = self.jurisdiction_id

org_name_prepositions = ["and", "at", "by", "for", "in", "on", "of", "the"]
name = spec.pop("name", None)
if name:
# __icontains doesn't work for JSONField ArrayField
# so other_name_lowercase_on follows "title" naming pattern
other_name_lowercase_on = name.title().replace(" On ", " on ")
# so name follows "title" naming pattern
name = name.title()
pattern = '(' + '|'.join(org_name_prepositions) + ')'
name = re.sub(pattern, lambda match: match.group(0).lower(), name, flags=re.IGNORECASE)
name = name.replace(" & ", " and ")

return Q(**spec) & (
Q(name__iexact=name)
| Q(other_names__contains=[{"name": other_name_lowercase_on}])
| Q(other_names__contains=[{"name": name}])
)
return spec
1 change: 1 addition & 0 deletions openstates/metadata/.python-version.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.15
35 changes: 35 additions & 0 deletions openstates/metadata/README.md.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# openstates_metadata

The `openstates_metadata` package provides a lightweight solution for accessing legislative metadata from the OpenStates project without needing to install the entire core OpenStates project. It is designed for external projects that rely on this specific subset of data.

## Motivation

There are a couple of key reasons for creating this separate package:

1. **Minimize Dependencies:** If your project only requires access to metadata, this package allows you to avoid installing the larger OpenStates core package.
2. **Simplify Dependency Management:** With a large project like OpenStates core, managing dependencies can be complex. By isolating metadata functionality, dependency resolution becomes much simpler and faster.

## Installation

To install the `openstates_metadata` package, simply run:

```bash
pip install openstates_metadata
```

## Usage

Here’s an example of how to use the openstates_metadata package:

```code
import openstates_metadata as metadata

jurisdiction_metadata = metadata.lookup(jurisdiction_id="ocd-jurisdiction/country:us/state:ak/government")
print(jurisdiction_metadata)
```

## Features

1. Access to legislative metadata from OpenStates.
2. Lightweight and easy to integrate into projects.
3. Avoid unnecessary dependencies and overhead from the full OpenStates core project.
17 changes: 17 additions & 0 deletions openstates/metadata/pyproject.toml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "openstates_metadata"
version = "2024.10.3"
description = "Openstates metadata"
authors = ["Alex Obaseki <[email protected]>"]
license = "MIT"


[tool.poetry.dependencies]
python = "^3.9"
attr = "^0.3.2"
attrs = "^24.2.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openstates"
version = "6.20.5"
version = "6.20.6"
description = "core infrastructure for the openstates project"
authors = ["James Turk <[email protected]>"]
license = "MIT"
Expand Down
Loading