Skip to content

Commit 33492d3

Browse files
davenquinngithub-actions[bot]
authored andcommitted
Format code and sort imports
1 parent 6f5099b commit 33492d3

File tree

9 files changed

+91
-49
lines changed

9 files changed

+91
-49
lines changed

py-modules/cli/macrostrat/cli/entrypoint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
from pathlib import Path
33

44
import typer
5-
from macrostrat.app_frame import CommandBase
6-
from macrostrat.utils.shell import run
75
from rich import print
86
from rich.traceback import install
97
from typer import Argument, Typer
108

9+
from macrostrat.app_frame import CommandBase
1110
from macrostrat.core import app
1211
from macrostrat.core.exc import MacrostratError
1312
from macrostrat.core.main import env_text, set_app_state
13+
from macrostrat.utils.shell import run
14+
1415
from .database import db_app, db_subsystem
1516
from .schema_management import schema_app
1617
from .subsystems.dev import dev_app
@@ -274,6 +275,7 @@ def update_weaver(db):
274275

275276
try:
276277
from macrostrat.column_ingestion import app as column_app
278+
277279
main.add_typer(
278280
column_app,
279281
name="columns",
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
from pathlib import Path
22

3-
from typer import Typer, Argument
3+
from typer import Argument, Typer
44

55
app = Typer(
66
no_args_is_help=True,
77
help="Column ingestion subsystem for Macrostrat",
88
)
99

10+
1011
@app.command(name="ingest")
11-
def ingest_columns(data_file: Path = Argument(..., help="Path to the data file to ingest")):
12+
def ingest_columns(
13+
data_file: Path = Argument(..., help="Path to the data file to ingest")
14+
):
1215
"""Ingest columns tabular data."""
1316
from .ingest import ingest_columns_from_file
1417

1518
ingest_columns_from_file(data_file)
16-
17-
18-
19-
20-
21-
22-
23-

py-modules/column-ingestion/macrostrat/column_ingestion/columns.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from datetime import datetime
33

44
import polars as pl
5-
from macrostrat.database import Database
65
from sqlalchemy.dialects.postgresql import insert
76

7+
from macrostrat.database import Database
8+
89
from .database import get_macrostrat_table
910
from .units import Unit
1011

py-modules/column-ingestion/macrostrat/column_ingestion/database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import re
22
from typing import Optional
33

4-
from macrostrat.core.database import get_database
54
from pydantic import BaseModel
65

6+
from macrostrat.core.database import get_database
7+
78

89
class ProjectIdentifier(BaseModel):
910
id: Optional[int] = None

py-modules/column-ingestion/macrostrat/column_ingestion/ingest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from macrostrat.core.database import get_database
21
from openpyxl import load_workbook
32

3+
from macrostrat.core.database import get_database
4+
45
from .columns import (
56
get_column_data,
67
get_or_create_column,
7-
get_or_create_section,
88
get_or_create_column_group,
9+
get_or_create_section,
910
)
1011
from .database import get_or_create_project
1112
from .metadata import get_metadata

py-modules/column-ingestion/macrostrat/column_ingestion/lithologies.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22

3-
from .database import get_all_liths, get_all_lith_attributes
3+
from .database import get_all_lith_attributes, get_all_liths
44

55

66
@dataclass
@@ -11,6 +11,7 @@ class LithAtt:
1111
def __hash__(self):
1212
return hash(self.id)
1313

14+
1415
@dataclass
1516
class Lithology:
1617
name: str
@@ -21,6 +22,7 @@ def __hash__(self):
2122
"""Hash the lithology based on its id and attributes. This allows us to compare lithologies in tests without worrying about object identity."""
2223
return hash((self.id, frozenset(self.attributes) if self.attributes else None))
2324

25+
2426
class LithsProcessor:
2527
liths = []
2628
atts = []
@@ -37,30 +39,39 @@ def match_lith_attribute(self, name) -> LithAtt | None:
3739

3840
def find_lith_attribute(self, text) -> tuple[LithAtt | None, str]:
3941
"""Start consuming text word by word, and check for matches at each step.
40-
This allows us to match multi-word attributes like "cross-bedded" or "brownish gray"""
42+
This allows us to match multi-word attributes like "cross-bedded" or "brownish gray
43+
"""
4144
res, remaining_text = _find_target(text, self.atts)
4245
if res is not None:
43-
res = LithAtt(name=res.name, id=res.id) # create a new LithAtt object without attributes for now
46+
res = LithAtt(
47+
name=res.name, id=res.id
48+
) # create a new LithAtt object without attributes for now
4449
return res, remaining_text
4550

4651
def find_lith(self, text) -> tuple[Lithology | None, str]:
4752
"""Start consuming text word by word, and check for matches at each step.
48-
This allows us to match multi-word lithologies like "mixed carbonate-siliciclastic"."""
53+
This allows us to match multi-word lithologies like "mixed carbonate-siliciclastic".
54+
"""
4955
res, remaining_text = _find_target(text, self.liths)
5056
if res is not None:
51-
res = Lithology(name=res.name, id=res.id) # create a new Lithology object without attributes for now
57+
res = Lithology(
58+
name=res.name, id=res.id
59+
) # create a new Lithology object without attributes for now
5260
return res, remaining_text
5361

62+
5463
def _match_target(name, liths):
5564
for lith in liths:
5665
if lith.name == name:
5766
return lith
5867
return None
5968

69+
6070
def _find_target(text, target_list) -> tuple[Lithology | LithAtt | None, str]:
6171
"""Start consuming text word by word, and check for matches at each step.
6272
Return the first match found, along with remaining text that was not part of the match.
63-
This allows us to match multi-word lithologies like "mixed carbonate-siliciclastic" or attributes like "brownish gray"."""
73+
This allows us to match multi-word lithologies like "mixed carbonate-siliciclastic" or attributes like "brownish gray".
74+
"""
6475
remaining_words = text.split()
6576
text_to_match = []
6677
while len(remaining_words) > 0:
@@ -72,16 +83,19 @@ def _find_target(text, target_list) -> tuple[Lithology | LithAtt | None, str]:
7283
# Return None if no match was found, along with an empty string for remaining text
7384
return None, text
7485

86+
7587
liths_processor = LithsProcessor()
7688

7789
split_words = {"and", "or"}
7890

91+
7992
def split_domains(text) -> list[str]:
8093
"""Splits text into parts within which we will search for lithologies and attributes."""
8194
for split_word in split_words:
8295
text = text.replace(f" {split_word} ", ";")
8396
return text.split(";")
8497

98+
8599
def process_liths_text(lith) -> set[Lithology]:
86100
# Process the lithology string to extract information about the rock type, grainsize, color, etc.
87101
split_lith = split_domains(lith)
@@ -91,7 +105,8 @@ def process_liths_text(lith) -> set[Lithology]:
91105
output.update(res)
92106
return output
93107

94-
def process_lith_domain(lith_text) -> set[Lithology] :
108+
109+
def process_lith_domain(lith_text) -> set[Lithology]:
95110
"""
96111
This function processes a single lithology block that doesn't have a strong separator (semicolon) from other lithologies.
97112
It looks for a single lithology and any attributes that are associated with it.

py-modules/column-ingestion/macrostrat/column_ingestion/test_lithologies.py

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pytest import mark
44

5-
from .lithologies import Lithology, LithAtt, process_liths_text
5+
from .lithologies import LithAtt, Lithology, process_liths_text
66

77

88
@dataclass
@@ -11,22 +11,19 @@ class LithologyTestCase:
1111
output: set[Lithology]
1212
expect_error: bool = False
1313

14+
1415
sandstone = Lithology(name="sandstone", id=10)
1516
limestone = Lithology(name="limestone", id=30)
1617
cross_bedded_sandstone = Lithology(
17-
name="sandstone",
18-
id=10,
19-
attributes={LithAtt(name="cross-bedded", id=17)}
18+
name="sandstone", id=10, attributes={LithAtt(name="cross-bedded", id=17)}
2019
)
2120
cross_bedded_red_sandstone = Lithology(
2221
name="sandstone",
2322
id=10,
24-
attributes={LithAtt(name="cross-bedded", id=17), LithAtt(name="red", id=112)}
23+
attributes={LithAtt(name="cross-bedded", id=17), LithAtt(name="red", id=112)},
2524
)
2625
stromatolitic_dolomite = Lithology(
27-
name="dolomite",
28-
id=31,
29-
attributes={LithAtt(name="stromatolitic", id=78)}
26+
name="dolomite", id=31, attributes={LithAtt(name="stromatolitic", id=78)}
3027
)
3128
dolomite = Lithology(name="dolomite", id=31)
3229
chert = Lithology(name="chert", id=45)
@@ -37,31 +34,59 @@ class LithologyTestCase:
3734
LithologyTestCase("sandstone", {sandstone}),
3835
LithologyTestCase("limestone; sandstone", {sandstone, limestone}),
3936
LithologyTestCase("cross-bedded sandstone", {cross_bedded_sandstone}),
40-
LithologyTestCase("limestone; cross-bedded sandstone", {limestone, cross_bedded_sandstone}),
37+
LithologyTestCase(
38+
"limestone; cross-bedded sandstone", {limestone, cross_bedded_sandstone}
39+
),
4140
LithologyTestCase("cross-bedded, red sandstone", {cross_bedded_red_sandstone}),
42-
LithologyTestCase("cross-bedded, red sandstone; stromatolitic dolomite",
43-
{cross_bedded_red_sandstone, stromatolitic_dolomite}),
41+
LithologyTestCase(
42+
"cross-bedded, red sandstone; stromatolitic dolomite",
43+
{cross_bedded_red_sandstone, stromatolitic_dolomite},
44+
),
4445
LithologyTestCase("stromatolitic dolomite", {stromatolitic_dolomite}),
4546
# "stromatoporoid" is not a valid attribute right now)
4647
# TODO: print a warning for unrecognized attributes, or return them
4748
LithologyTestCase("stromatoporoid dolomite", {dolomite}),
4849
# Handle common case where multiple liths are listed with commas instead of semicolons
49-
LithologyTestCase("dolomite, limestone, chert, cross-bedded sandstone", {dolomite, limestone, chert, cross_bedded_sandstone}),
50+
LithologyTestCase(
51+
"dolomite, limestone, chert, cross-bedded sandstone",
52+
{dolomite, limestone, chert, cross_bedded_sandstone},
53+
),
5054
# Play around with some special cases for separators
51-
LithologyTestCase("dolomite; limestone; chert; cross-bedded, red sandstone", {dolomite, limestone, chert, cross_bedded_red_sandstone}),
52-
LithologyTestCase("dolomite, limestone, chert; cross-bedded, red sandstone", {dolomite, limestone, chert, cross_bedded_red_sandstone}),
53-
LithologyTestCase("dolomite, limestone, chert, cross-bedded, red sandstone", {dolomite, limestone, chert, cross_bedded_red_sandstone}),
54-
LithologyTestCase("cross-bedded sandstone and chert", {cross_bedded_sandstone, chert}),
55+
LithologyTestCase(
56+
"dolomite; limestone; chert; cross-bedded, red sandstone",
57+
{dolomite, limestone, chert, cross_bedded_red_sandstone},
58+
),
59+
LithologyTestCase(
60+
"dolomite, limestone, chert; cross-bedded, red sandstone",
61+
{dolomite, limestone, chert, cross_bedded_red_sandstone},
62+
),
63+
LithologyTestCase(
64+
"dolomite, limestone, chert, cross-bedded, red sandstone",
65+
{dolomite, limestone, chert, cross_bedded_red_sandstone},
66+
),
67+
LithologyTestCase(
68+
"cross-bedded sandstone and chert", {cross_bedded_sandstone, chert}
69+
),
5570
LithologyTestCase("mixed carbonate-siliciclastic", {mixed_carbonate}),
5671
LithologyTestCase("some rocks and stuff", set()),
57-
LithologyTestCase("fractured, brownish gray siltstone, sand, and mixed carbonate-siliciclastic", {
58-
mixed_carbonate,
59-
sand,
60-
Lithology(name="siltstone", id=9, attributes={LithAtt(name="fractured", id=169), LithAtt(name="brownish gray", id=133)})
61-
}),
62-
72+
LithologyTestCase(
73+
"fractured, brownish gray siltstone, sand, and mixed carbonate-siliciclastic",
74+
{
75+
mixed_carbonate,
76+
sand,
77+
Lithology(
78+
name="siltstone",
79+
id=9,
80+
attributes={
81+
LithAtt(name="fractured", id=169),
82+
LithAtt(name="brownish gray", id=133),
83+
},
84+
),
85+
},
86+
),
6387
]
6488

89+
6590
@mark.parametrize("test_case", test_cases)
6691
def test_process_liths_text(test_case):
6792
liths = process_liths_text(test_case.input)

py-modules/core/macrostrat/core/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
from dotenv import load_dotenv
55
from dynaconf import Dynaconf, Validator
6-
from macrostrat.app_frame.control_command import BackendType
7-
from macrostrat.utils import get_logger
86
from sqlalchemy.engine import make_url
97
from sqlalchemy.engine.url import URL
108
from toml import load as load_toml
119

10+
from macrostrat.app_frame.control_command import BackendType
11+
from macrostrat.utils import get_logger
12+
1213
from .resolvers import cast_sources, setup_source_roots_environment
1314
from .utils import convert_to_string, find_macrostrat_config, path_list_resolver
1415

py-modules/core/macrostrat/core/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import toml
66
from dynaconf import Dynaconf
7+
from rich.console import Console
8+
from typer import Context, Option, get_app_dir
9+
710
from macrostrat.app_frame import (
811
Application,
912
ControlCommand,
@@ -12,8 +15,6 @@
1215
)
1316
from macrostrat.app_frame.control_command import CommandBase
1417
from macrostrat.utils import get_logger
15-
from rich.console import Console
16-
from typer import Context, Option, get_app_dir
1718

1819
from .console import console_theme
1920
from .exc import MacrostratError

0 commit comments

Comments
 (0)