Skip to content

Commit

Permalink
Revert black formatting on example scripts (#254)
Browse files Browse the repository at this point in the history
* Revert example formatting

* Use local code check

* Remove unneeded notebook processing code
  • Loading branch information
Andy-Grigg committed Dec 21, 2022
1 parent 13d2555 commit f197979
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 87 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/local_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ env:

jobs:
style:
name: Code style
name: Code Style Check
runs-on: ubuntu-latest

steps:
- name: PyAnsys code style checks
uses: pyansys/actions/code-style@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
python-version: ${{ matrix.python-version }}

- name: Install style requirements
run: pip install 'tox<4' poetry --disable-pip-version-check

- name: Spell, Lint and Type Check
run: tox -e style


docs-style:
name: Documentation Style Check
Expand Down
8 changes: 2 additions & 6 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,8 @@ def _copy_examples_and_convert_to_notebooks(source_dir, output_dir):
file_output_path = root_output_path / Path(file)
shutil.copy(file_source_path, file_output_path) # Copy everything
if file_source_path.suffix == ".py": # Also convert python scripts to jupyter notebooks
notebook = jupytext.read(file_source_path)

# Filter out cells to remove
notebook.cells = [c for c in notebook.cells if "remove_cell" not in c.metadata.get("tags", [])]

jupytext.write(notebook, file_output_path.with_suffix(".ipynb"))
ntbk = jupytext.read(file_source_path)
jupytext.write(ntbk, file_output_path.with_suffix(".ipynb"))


# If we already have a source/examples directory then don't do anything.
Expand Down
10 changes: 0 additions & 10 deletions examples/0_Getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,11 @@
# Fluent interfaces are designed to allow a complex object to be constructed in a single line of code. As such, you can
# consolidate the cells above into a single step:

# + tags=["remove_cell"]
# Turn off black formatting
# fmt: off
# -

# + tags=[]
query = queries.MaterialImpactedSubstancesQuery().with_material_ids(["plastic-abs-high-impact"]).with_legislations(["REACH - The Candidate List"]) # noqa: E501
query
# -

# + tags=["remove_cell"]
# Turn on black formatting
# fmt: on
# -

# Because the fluent interface can produce very long lines of code, it's necessary to break your query creation code
# into multiple lines. The following multi-line format is used throughout the examples. It is functionally equivalent to
# the preceding cell:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
from ansys.grantami.bomanalytics import queries

mat_query = (
queries.MaterialImpactedSubstancesQuery().with_material_ids([PPS_ID, PC_ID]).with_legislations([REACH, SIN_LIST])
queries.MaterialImpactedSubstancesQuery()
.with_material_ids([PPS_ID, PC_ID])
.with_legislations([REACH, SIN_LIST])
)
# -

Expand Down Expand Up @@ -90,9 +92,8 @@
# + tags=[]
from tabulate import tabulate

rows = [
(substance.cas_number, substance.max_percentage_amount_in_material) for substance in substances_by_material[PC_ID]
]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material)
for substance in substances_by_material[PC_ID]]

print(f'Substances impacted by "{SIN_LIST}" in "{PC_ID}" (10/{len(rows)})')
print(tabulate(rows[:10], headers=["CAS Number", "Amount (wt. %)"]))
Expand All @@ -108,7 +109,8 @@

# + tags=[]
material_substances_sin = results.impacted_substances_by_legislation[SIN_LIST]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material) for substance in material_substances_sin]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material)
for substance in material_substances_sin]
print(f'Substances impacted by "{SIN_LIST}" in all materials (10/{len(rows)})')
print(tabulate(rows[:10], headers=["CAS Number", "Amount (wt. %)"]))
# -
Expand All @@ -124,7 +126,8 @@

# + tags=[]
material_substances_all = results.impacted_substances
rows = [(substance.cas_number, substance.max_percentage_amount_in_material) for substance in material_substances_all]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material)
for substance in material_substances_all]
print(f"Impacted substances for all materials and legislations (10/{len(rows)})")
print(tabulate(rows[:10], headers=["CAS Number", "Amount (wt. %)"]))
# -
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
# + tags=[]
from ansys.grantami.bomanalytics import queries

part_query = queries.PartImpactedSubstancesQuery().with_part_numbers([DRILL, WING]).with_legislations([SIN_LIST, REACH])
part_query = (
queries.PartImpactedSubstancesQuery()
.with_part_numbers([DRILL, WING])
.with_legislations([SIN_LIST, REACH])
)
# -

# Finally, run the query. Passing a ``PartImpactedSubstancesQuery`` object to the ``Connection.run()`` method returns a
Expand Down Expand Up @@ -98,7 +102,8 @@
# + tags=[]
from tabulate import tabulate

rows = [(substance.cas_number, substance.max_percentage_amount_in_material) for substance in substances_by_part[WING]]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material)
for substance in substances_by_part[WING]]

print(f'Substances impacted by "{SIN_LIST}" in "{WING}"')
print(tabulate(rows, headers=["CAS Number", "Amount (wt. %)"]))
Expand All @@ -114,7 +119,8 @@

# + tags=[]
part_substances_sin = part_result.impacted_substances_by_legislation[SIN_LIST]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material) for substance in part_substances_sin]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material)
for substance in part_substances_sin]
print(f'Substances impacted by "{SIN_LIST}" in all parts (10/{len(rows)})')
print(tabulate(rows[:10], headers=["CAS Number", "Amount (wt. %)"]))
# -
Expand All @@ -130,7 +136,8 @@

# + tags=[]
part_substances_all = part_result.impacted_substances
rows = [(substance.cas_number, substance.max_percentage_amount_in_material) for substance in part_substances_all]
rows = [(substance.cas_number, substance.max_percentage_amount_in_material)
for substance in part_substances_all]
print(f'Impacted substances across all legislations in "DRILL" (10/{len(rows)})')
print(tabulate(rows[:10], headers=["CAS Number", "Amount (wt. %)"]))
# -
14 changes: 9 additions & 5 deletions examples/2_Compliance_Queries/2-1_Substance_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
legislation_names=["REACH - The Candidate List"],
default_threshold_percentage=0.1,
)
sin = indicators.WatchListIndicator(name="SIN", legislation_names=["The SIN List 2.1 (Substitute It Now!)"])
sin = indicators.WatchListIndicator(
name="SIN",
legislation_names=["The SIN List 2.1 (Substitute It Now!)"]
)
# -

# + [markdown] tags=[]
Expand All @@ -70,9 +73,10 @@
from ansys.grantami.bomanalytics import queries

sub_query = queries.SubstanceComplianceQuery().with_indicators([svhc, sin])
sub_query = sub_query.with_cas_numbers_and_amounts(
[("50-00-0", 10), ("110-00-9", 25), ("302-17-0", 100), ("7440-23-5", 100)]
)
sub_query = sub_query.with_cas_numbers_and_amounts([("50-00-0", 10),
("110-00-9", 25),
("302-17-0", 100),
("7440-23-5", 100)])
# -

# Finally, run the query. Passing a ``SubstanceComplianceQuery`` object to the ``Connection.run()`` method returns a
Expand Down Expand Up @@ -104,7 +108,7 @@
threshold = svhc.available_flags.WatchListAboveThreshold

for substance in sub_result.compliance_by_substance_and_indicator:
if substance.indicators["SVHC"] >= threshold:
if (substance.indicators["SVHC"] >= threshold):
non_compliant_substances.append(substance)
else:
compliant_substances.append(substance)
Expand Down
28 changes: 20 additions & 8 deletions examples/2_Compliance_Queries/2-2_Material_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
legislation_names=["REACH - The Candidate List"],
default_threshold_percentage=0.1,
)
sin = indicators.WatchListIndicator(name="SIN", legislation_names=["The SIN List 2.1 (Substitute It Now!)"])
sin = indicators.WatchListIndicator(
name="SIN",
legislation_names=["The SIN List 2.1 (Substitute It Now!)"]
)
# -

# + [markdown] tags=[]
Expand All @@ -69,9 +72,9 @@
from ansys.grantami.bomanalytics import queries

mat_query = queries.MaterialComplianceQuery().with_indicators([svhc, sin])
mat_query = mat_query.with_material_ids(
["plastic-pa66-60glassfiber", "zinc-pb-cdlow-alloy-z21220-rolled", "stainless-316h"]
)
mat_query = mat_query.with_material_ids(["plastic-pa66-60glassfiber",
"zinc-pb-cdlow-alloy-z21220-rolled",
"stainless-316h"])
# -

# Finally, run the query. Passing a ``MaterialComplianceQuery`` object to the ``Connection.run()`` method returns a
Expand Down Expand Up @@ -113,7 +116,9 @@

# + tags=[]
above_threshold_flag = svhc.available_flags.WatchListAboveThreshold
pa_66_svhcs = [sub for sub in pa_66.substances if sub.indicators["SVHC"] >= above_threshold_flag]
pa_66_svhcs = [sub for sub in pa_66.substances
if sub.indicators["SVHC"] >= above_threshold_flag
]
print(f"{len(pa_66_svhcs)} SVHCs")
for sub in pa_66_svhcs:
print(f"Substance record history identity: {sub.record_history_identity}")
Expand All @@ -137,10 +142,13 @@

# + tags=[]
below_threshold_flag = svhc.available_flags.WatchListBelowThreshold
zn_svhcs_below_threshold = [sub for sub in zn_pb_cd.substances if sub.indicators["SVHC"].flag == below_threshold_flag]
zn_svhcs_below_threshold = [sub for sub in zn_pb_cd.substances
if sub.indicators["SVHC"].flag == below_threshold_flag]
print(f"{len(zn_svhcs_below_threshold)} SVHCs below threshold")
for substance in zn_svhcs_below_threshold:
print(f"Substance record history identity: {substance.record_history_identity}")
print(
f"Substance record history identity: {substance.record_history_identity}"
)
# -

# Finally, look at the stainless steel record.
Expand All @@ -157,7 +165,11 @@

# + tags=[]
not_impacted_flag = svhc.available_flags.WatchListNotImpacted
ss_not_impacted = [sub for sub in ss_316h.substances if sub.indicators["SVHC"].flag == not_impacted_flag]
ss_not_impacted = [
sub
for sub in ss_316h.substances
if sub.indicators["SVHC"].flag == not_impacted_flag
]
print(f"{len(ss_not_impacted)} non-SVHC substances")
for sub in ss_not_impacted:
print(f"Substance record history identity: {sub.record_history_identity}")
Expand Down
44 changes: 23 additions & 21 deletions examples/2_Compliance_Queries/2-3_Part_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
legislation_names=["REACH - The Candidate List"],
default_threshold_percentage=0.1,
)
sin = indicators.WatchListIndicator(name="SIN", legislation_names=["The SIN List 2.1 (Substitute It Now!)"])
sin = indicators.WatchListIndicator(
name="SIN",
legislation_names=["The SIN List 2.1 (Substitute It Now!)"]
)
# -

# + [markdown] tags=[]
Expand All @@ -68,7 +71,11 @@
# + tags=[]
from ansys.grantami.bomanalytics import queries

part_query = queries.PartComplianceQuery().with_part_numbers(["asm_flap_mating", "DRILL"]).with_indicators([svhc])
part_query = (
queries.PartComplianceQuery()
.with_part_numbers(["asm_flap_mating", "DRILL"])
.with_indicators([svhc])
)
# -

# Finally, run the query. Passing a ``PartComplianceQuery`` object to the ``Connection.run()`` method returns a
Expand Down Expand Up @@ -116,7 +123,8 @@

# + tags=[]
above_threshold_flag = svhc.available_flags.WatchListAboveThreshold
parts_contain_svhcs = [part for part in wing.parts if part.indicators["SVHC"] >= above_threshold_flag]
parts_contain_svhcs = [part for part in wing.parts
if part.indicators["SVHC"] >= above_threshold_flag]
print(f"{len(parts_contain_svhcs)} parts that contain SVHCs")
for part in parts_contain_svhcs:
print(f"Part: {part.record_history_identity}")
Expand All @@ -129,12 +137,11 @@

# + tags=[]
def recursively_print_parts_with_svhcs(parts, depth=0):
parts_contain_svhcs = [part for part in parts if part.indicators["SVHC"] >= above_threshold_flag]
parts_contain_svhcs = [part for part in parts
if part.indicators["SVHC"] >= above_threshold_flag]
for part in parts_contain_svhcs:
print(f"{' '*depth}- Part: {part.record_history_identity}")
recursively_print_parts_with_svhcs(part.parts, depth + 1)


# -


Expand All @@ -148,59 +155,54 @@ def recursively_print_parts_with_svhcs(parts, depth=0):

# + tags=[]
def recursively_print_parts_with_svhcs(parts, depth=0):
parts_contain_svhcs = [part for part in parts if part.indicators["SVHC"] >= above_threshold_flag]
parts_contain_svhcs = [part for part in parts
if part.indicators["SVHC"] >= above_threshold_flag]
for part in parts_contain_svhcs:
print(f"{' '*depth}- Part: {part.record_history_identity}")
recursively_print_parts_with_svhcs(part.parts, depth + 1)
print_materials_with_svhcs(part.materials, depth + 1)
print_specifications_with_svhcs(part.specifications, depth + 1)
print_substances_with_svhcs(part.substances, depth + 1)


# -


# + tags=[]
def print_materials_with_svhcs(materials, depth=0):
mats_contain_svhcs = [m for m in materials if m.indicators["SVHC"] >= above_threshold_flag]
mats_contain_svhcs = [m for m in materials
if m.indicators["SVHC"] >= above_threshold_flag]
for mat in mats_contain_svhcs:
print(f"{' '*depth}- Material: {mat.record_history_identity}")
print_substances_with_svhcs(mat.substances, depth + 1)


# -


# + tags=[]
def print_specifications_with_svhcs(specifications, depth=0):
specs_contain_svhcs = [s for s in specifications if s.indicators["SVHC"] >= above_threshold_flag]
specs_contain_svhcs = [s for s in specifications
if s.indicators["SVHC"] >= above_threshold_flag]
for spec in specs_contain_svhcs:
print(f"{' '*depth}- Specification: {spec.record_history_identity}")
print_coatings_with_svhcs(spec.coatings, depth + 1)
print_substances_with_svhcs(spec.substances, depth + 1)


# -


# + tags=[]
def print_coatings_with_svhcs(coatings, depth=0):
coatings_contain_svhcs = [c for c in coatings if c.indicators["SVHC"] >= above_threshold_flag]
coatings_contain_svhcs = [c for c in coatings
if c.indicators["SVHC"] >= above_threshold_flag]
for coating in coatings_contain_svhcs:
print(f"{' '*depth}- Coating: {coating.record_history_identity}")
print_substances_with_svhcs(coating.substances, depth + 1)


# -


# + tags=[]
def print_substances_with_svhcs(substances, depth=0):
subs_contain_svhcs = [sub for sub in substances if sub.indicators["SVHC"] >= above_threshold_flag]
subs_contain_svhcs = [sub for sub in substances
if sub.indicators["SVHC"] >= above_threshold_flag]
for sub in subs_contain_svhcs:
print(f"{' '*depth}- Substance: {sub.record_history_identity}")


# -


Expand Down
Loading

0 comments on commit f197979

Please sign in to comment.