Skip to content

Commit b9c6737

Browse files
committed
refactor
1 parent 5654435 commit b9c6737

13 files changed

Lines changed: 187 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v4
17+
18+
- name: Set up Python
19+
run: uv python install 3.12
20+
21+
- name: Install dependencies
22+
run: uv sync --dev
23+
24+
- name: Lint
25+
run: uv run ruff check structflo/ tests/
26+
27+
- name: Format
28+
run: uv run ruff format --check structflo/ tests/
29+
30+
- name: Test
31+
run: uv run pytest -q

.github/workflows/publish.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write # trusted publishing
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v4
18+
19+
- name: Set up Python
20+
run: uv python install 3.12
21+
22+
- name: Install dependencies
23+
run: uv sync --dev
24+
25+
- name: Lint
26+
run: uv run ruff check structflo/ tests/
27+
28+
- name: Test
29+
run: uv run pytest -q
30+
31+
- name: Build
32+
run: uv build
33+
34+
- name: Publish to PyPI
35+
uses: pypa/gh-action-pypi-publish@release/v1

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: install lint format check test clean build
2+
3+
## Install all dependencies (including dev)
4+
install:
5+
uv sync --dev
6+
7+
## Run ruff linter
8+
lint:
9+
uv run ruff check structflo/ tests/
10+
11+
## Auto-fix lint issues
12+
fix:
13+
uv run ruff check --fix structflo/ tests/
14+
15+
## Format code with ruff
16+
format:
17+
uv run ruff format structflo/ tests/
18+
19+
## Check formatting + lint (CI-friendly, no changes)
20+
check:
21+
uv run ruff format --check structflo/ tests/
22+
uv run ruff check structflo/ tests/
23+
24+
## Run tests
25+
test:
26+
uv run pytest -q
27+
28+
## Remove build artifacts
29+
clean:
30+
rm -rf dist/ build/ *.egg-info .pytest_cache
31+
find . -type d -name __pycache__ -exec rm -rf {} +
32+
33+
## Build package
34+
build:
35+
uv build

pyproject.toml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "structflo-ner"
3-
version = "0.1.0"
3+
dynamic = ["version"]
44
description = "Drug discovery NER wrapper around LangExtract — zero-config entity extraction for chemistry and biology."
55
readme = "README.md"
66
requires-python = ">=3.10"
@@ -14,14 +14,45 @@ dataframe = ["pandas>=1.5"]
1414
dev = [
1515
"pytest>=7",
1616
"pytest-mock>=3",
17+
"ruff>=0.8",
1718
]
1819

1920
[build-system]
2021
requires = ["hatchling"]
2122
build-backend = "hatchling.build"
2223

24+
[tool.hatch.version]
25+
path = "structflo/ner/__init__.py"
26+
2327
[tool.hatch.build.targets.wheel]
2428
packages = ["structflo"]
2529

2630
[tool.pytest.ini_options]
2731
testpaths = ["tests"]
32+
33+
# --------------------------------------------------------------------------- #
34+
# Ruff
35+
# --------------------------------------------------------------------------- #
36+
[tool.ruff]
37+
target-version = "py310"
38+
line-length = 100
39+
40+
[tool.ruff.lint]
41+
select = [
42+
"E", # pycodestyle errors
43+
"W", # pycodestyle warnings
44+
"F", # pyflakes
45+
"I", # isort
46+
"UP", # pyupgrade
47+
"B", # flake8-bugbear
48+
"SIM", # flake8-simplify
49+
]
50+
ignore = [
51+
"E501", # line length handled by formatter
52+
]
53+
54+
[tool.ruff.lint.isort]
55+
known-first-party = ["structflo"]
56+
57+
[tool.ruff.format]
58+
quote-style = "double"

structflo/ner/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
EntityProfile,
5454
)
5555

56+
__version__ = "0.1.0"
57+
5658
__all__ = [
5759
# Main class
5860
"NERExtractor",

structflo/ner/_entities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Typed entity dataclasses for drug discovery NER results."""
2+
23
from __future__ import annotations
34

45
import dataclasses
@@ -124,7 +125,7 @@ def to_dict(self) -> dict:
124125
"unclassified": [dataclasses.asdict(e) for e in self.unclassified],
125126
}
126127

127-
def to_dataframe(self) -> "pd.DataFrame":
128+
def to_dataframe(self) -> pd.DataFrame:
128129
"""Return all entities as a flat pandas DataFrame.
129130
130131
Requires pandas to be installed: pip install structflo-ner[dataframe]

structflo/ner/_examples.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
designed to give the LLM strong signal about what to extract and at what
55
granularity.
66
"""
7+
78
from __future__ import annotations
89

910
import langextract as lx
@@ -180,7 +181,11 @@
180181
lx.data.Extraction(
181182
extraction_class="assay",
182183
extraction_text="A549 (human lung adenocarcinoma) cell proliferation assay",
183-
attributes={"cell_line": "A549", "organism": "human", "assay_format": "cell proliferation"},
184+
attributes={
185+
"cell_line": "A549",
186+
"organism": "human",
187+
"assay_format": "cell proliferation",
188+
},
184189
),
185190
lx.data.Extraction(
186191
extraction_class="bioactivity",

structflo/ner/_mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Maps langextract Extraction objects to typed NEREntity instances."""
2+
23
from __future__ import annotations
34

45
import langextract as lx

structflo/ner/extractor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""NERExtractor: the main user-facing class for drug discovery NER."""
2+
23
from __future__ import annotations
34

45
import langextract as lx

structflo/ner/profiles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717
extractor.extract(text, profile=my_profile)
1818
"""
19+
1920
from __future__ import annotations
2021

2122
import dataclasses
@@ -42,7 +43,7 @@ class EntityProfile:
4243
prompt: str
4344
examples: list[lx.data.ExampleData]
4445

45-
def merge(self, other: "EntityProfile") -> "EntityProfile":
46+
def merge(self, other: EntityProfile) -> EntityProfile:
4647
"""Return a new profile combining this profile with another."""
4748
return EntityProfile(
4849
name=f"{self.name}+{other.name}",

0 commit comments

Comments
 (0)