Skip to content

Commit 231506e

Browse files
authored
Merge pull request #143 from openstates/create-os-core-metadata-package
Publish openstate-core metadata
2 parents f409059 + c7bb6fc commit 231506e

File tree

7 files changed

+87
-5
lines changed

7 files changed

+87
-5
lines changed

.github/workflows/release.yml

+20-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,30 @@ jobs:
2626
uses: snok/[email protected]
2727
- name: configure pypi credentials
2828
run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}"
29-
- name: Publish package
29+
- name: Publish core package
3030
run: poetry publish --build
3131
- name: install dependencies
3232
run: poetry install
3333
- name: update metadata
3434
env:
3535
DATABASE_URL: ${{ secrets.OPENSTATES_DATABASE_URL }}
3636
run: poetry run os-initdb
37+
# Add steps for openstates_metadata package
38+
- name: Create directory and copy openstates_metadata
39+
run: |
40+
mkdir -p core_metadata
41+
cp -r openstates/metadata core_metadata
42+
- name: Change directory to core_metadata
43+
run: cd core_metadata
44+
- name: Move configuration files
45+
run: |
46+
mv metadata/pyproject.toml.sample pyproject.toml
47+
mv metadata/.python-version.sample .python-version
48+
mv metadata/README.md.sample README.md
49+
mv metadata openstates_metadata
50+
- name: Install dependencies for openstates_metadata
51+
run: poetry install
52+
- name: Configure pypi credentials for metadata package
53+
run: poetry config pypi-token.pypi "${{ secrets.OPENSTATES_METADATA_PYPI_API_KEY }}"
54+
- name: Publish openstates_metadata package
55+
run: poetry publish --build

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 6.20.6 - Sept 18, 2024
4+
5+
* Add steps to publish lightweight openstates-metadata
6+
37
## 6.20.5 - Sept 18, 2024
48

59
* Improve Event to Person matching

openstates/importers/organizations.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from django.db.models import Q
23
from ._types import _JsonDict
34
from .base import BaseImporter
@@ -12,13 +13,18 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict:
1213
if spec.get("classification") != "party":
1314
spec["jurisdiction_id"] = self.jurisdiction_id
1415

16+
org_name_prepositions = ["and", "at", "by", "for", "in", "on", "of", "the"]
1517
name = spec.pop("name", None)
1618
if name:
1719
# __icontains doesn't work for JSONField ArrayField
18-
# so other_name_lowercase_on follows "title" naming pattern
19-
other_name_lowercase_on = name.title().replace(" On ", " on ")
20+
# so name follows "title" naming pattern
21+
name = name.title()
22+
pattern = '(' + '|'.join(org_name_prepositions) + ')'
23+
name = re.sub(pattern, lambda match: match.group(0).lower(), name, flags=re.IGNORECASE)
24+
name = name.replace(" & ", " and ")
25+
2026
return Q(**spec) & (
2127
Q(name__iexact=name)
22-
| Q(other_names__contains=[{"name": other_name_lowercase_on}])
28+
| Q(other_names__contains=[{"name": name}])
2329
)
2430
return spec
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.9.15

openstates/metadata/README.md.sample

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# openstates_metadata
2+
3+
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.
4+
5+
## Motivation
6+
7+
There are a couple of key reasons for creating this separate package:
8+
9+
1. **Minimize Dependencies:** If your project only requires access to metadata, this package allows you to avoid installing the larger OpenStates core package.
10+
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.
11+
12+
## Installation
13+
14+
To install the `openstates_metadata` package, simply run:
15+
16+
```bash
17+
pip install openstates_metadata
18+
```
19+
20+
## Usage
21+
22+
Here’s an example of how to use the openstates_metadata package:
23+
24+
```code
25+
import openstates_metadata as metadata
26+
27+
jurisdiction_metadata = metadata.lookup(jurisdiction_id="ocd-jurisdiction/country:us/state:ak/government")
28+
print(jurisdiction_metadata)
29+
```
30+
31+
## Features
32+
33+
1. Access to legislative metadata from OpenStates.
34+
2. Lightweight and easy to integrate into projects.
35+
3. Avoid unnecessary dependencies and overhead from the full OpenStates core project.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tool.poetry]
2+
name = "openstates_metadata"
3+
version = "2024.10.3"
4+
description = "Openstates metadata"
5+
authors = ["Alex Obaseki <[email protected]>"]
6+
license = "MIT"
7+
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.9"
11+
attr = "^0.3.2"
12+
attrs = "^24.2.0"
13+
14+
15+
[build-system]
16+
requires = ["poetry-core"]
17+
build-backend = "poetry.core.masonry.api"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openstates"
3-
version = "6.20.5"
3+
version = "6.20.6"
44
description = "core infrastructure for the openstates project"
55
authors = ["James Turk <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)