Skip to content

Commit

Permalink
Merge from grantami-bomanalytics-private (#386)
Browse files Browse the repository at this point in the history
* Remove outdated typevars

* Include finishing processes in summary

* Update example BoM

* Create 4-2_BoM_Sustainability.py

* Add example to docs

* Sustainability example changes

* Fix server name

* Tweak working

* Change BoM naming convention

* Add API link and minor formatting tweaks

* Change legend position

* Uncomment integration tests job

* Make sure this class isn't collected by pytest

* Rename with_legislations to with_legislation_ids

* Add trailing space

* Rename external_id on part to external_identity

* Enforce keywords for indicator constructors

* Run black

* Copy check_server from recordlists

* Add variable to disable vm state management

* Fix error message

* Fix typo

* Use absolute masses for secondary processes and use floats

* Draft bom builder example

* Add example to docs

* Fix typing

* Remove some boms

* Improve sustainability integration tests

* Fix error message

* PR feedback

* Apply language suggestions from code review

Co-authored-by: Andy Grigg <[email protected]>

* Add delimiters and fix comments

* Fix GUID field name

* Use method for record references

* Fix test assertions (due to mass changes in BoM)

* Change plotly renderer in examples tests [skip-ci]

* Update BillOfMaterialsEco2301.xsd

* Add category enum

* Update sus. tests to reflect aggregation changes

* Remove outdated todo

* Fix error message

* Fix missing database test

* Add initial docs for BoM Types

- Add rst
- Move init docstrings to class. I hate this, the docstring then says that a class takes a parameter. It does not. The init does.
- Add docstrings for protocols.

* Update files for 2024 R1

* Ignore deserialization

* Exclude the right thing

* Move a docstring and update the other ignorewords...

* Try without tildes

* Pin vale?

* There is no 2.28

* Update index.rst

* Update README.rst

* Clarify aggregation methodology

* Add links to online docs

* Add record identification documentation

* Remove id notes

* Remove "do not instantiate" notes

* Fix message typing

* Update summary results docstrings

* Bump openapi package

* Remove sustainability blank coatings

* Remove sustainability from specifications

* Remove substances from MaterialWithSustainability

* Fix issues with Quantity

- Treat $ as a special case and never handle namespaces
- Handle attributes with no namespace if no default namespace is present

* Add name to transport results

* Update examples.py

* Update unit tests

* Use merge commit ref

* Update tests/test_item_results.py

Co-authored-by: Doug Addy <[email protected]>

* Create BillOfMaterialsEco1711.xsd

* Schemas sub-package

* Remove schemas from examples

* Review comments

* Expect warnings in tests

* Make inputs mandatory

* Naive support for multiple BoM versions

* Add notes about schemas and schemas to docs

* Rename sample bom

* Delete unused test helpers

* Update test_integration_tests.py

* Modify invalid bom to pass client side validation

* Fix fixture name

* Add custom tables for sustainability

* Fix failing integration tests

* Minor feedback

* Fix database key

* Fix vale vocab

* Remove use of regex

* Remove messages assertions

* Update docs

* Remove results classes

* Update tests

* Remove from docs

* Update PartWithSustainability docstring

* Compose record references

* Add part number

* Update tests

* Correct typing

* Update mock responses and associated tests

* Update dependency

* Make mixin into base class

* Use merge commit ref

* Warn on multiple root parts in sust. query result

* Update warning

* Add part and transport references to docs

* Update docs homepage

* Update GitHub org name

* Update MI version requirements

* Add note about product licensing

* Update Process properties names and docs

* Update BoM builder example

* Update example bom

* Remove duplicated BoM

* Rename test BoMs

* Remove duplicated BoM

* Rename paths variables

* Add variables for extra boms

* Use newer version of vale

* Convert to dataclasses

* Update bom types docs

Remove protocols and base class

* Fix bom types issues

* Comment out troublesome properties

NonMIPartReference and BoM annotations

* Add test

* Fix typing and formatting

* Apply suggestions from code review

Co-authored-by: Andy Grigg <[email protected]>

* Remove special handling for ids

* Comment out annotations

* Address more small issues

Remove typical content on materials

* Add comment about BoM "update"

* Add TODOs with issue ID

* Ignore numpydoc warning

* Add missing docstrings

* Address vale issues

* Update accept.txt

* Update accept.txt

* Add test for unexpected args

* Script tweaks

* Update .vale.ini

* Update common identifiers documentation

* Add missing punctuation

* Wording feedback

* Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Remove test bom

* Fix doc header

* Add badges to README

* Sustainability docs tweaks

* Fix/ignore reference warnings

* Typo in example

* Clarify env. footprint hierarchy

* Remove TODO

* Updates to bom builder example script

* Update package index

* Add note about item expansion

* Fix error message

* Document aggregation criteria

* Flake8

* Add space

* Language feedback

* Re-ordering

* Add missing mian dependencies

* Poetry lock with update

* Update emails

* Use openapi PR ref

* Drop Python 3.8

* Support Python 3.12

* Fix tox config

* Use merge commit ref

* Update docs dependencies

* Update comment

* Loosen specifications

* Bump pandas from 2.0.3 to 2.1.3

Bumps [pandas](https://github.com/pandas-dev/pandas) from 2.0.3 to 2.1.3.
- [Release notes](https://github.com/pandas-dev/pandas/releases)
- [Commits](pandas-dev/pandas@v2.0.3...v2.1.3)

---
updated-dependencies:
- dependency-name: pandas
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Remove with_stk_records (#123)

* Fix: add repr and example formatting (#122)

* Fix formatting

* Update 4-2_BoM_Sustainability.py

* Add sustainability query repr

* Maint: Update docs deps (#127)

* Feat: Single part in BoM sustainability (#130)

* Expose single part

* Raise error on no parts

* Docs: PM feedback (#132)

* Reduce output

* Add note about relevance of items

* Update accept.txt

* Apply suggestions from code review

Co-authored-by: Andy Grigg <[email protected]>

* Make vale happy

---------

Co-authored-by: Andy Grigg <[email protected]>

* Bump jupytext from 1.15.2 to 1.16.0 (#133)

Bumps [jupytext](https://github.com/mwouts/jupytext) from 1.15.2 to 1.16.0.
- [Release notes](https://github.com/mwouts/jupytext/releases)
- [Changelog](https://github.com/mwouts/jupytext/blob/main/CHANGELOG.md)
- [Commits](mwouts/jupytext@v1.15.2...v1.16.0)

---
updated-dependencies:
- dependency-name: jupytext
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Docs: review feedback (#142)

* RS and Compliance updates

* Sustainability updates

* BoM types updates

* Examples updates

* Fix typo

* Fix typo [skip-ci]

Co-authored-by: Andy Grigg <[email protected]>

---------

Co-authored-by: Andy Grigg <[email protected]>

* Allow null material identity and reference

* Add first draft of general improvements to documentation

* Vale fixes

* Add note to compliance API page

* Move license note to end

* Fix BoM query descriptions

* Fix typo

* Documentation review feedback

* Point at public bomanalytics-openapi

* Fix cname

* Clean up workflows

* Use public bomanalytics-openapi

* Maint/codacy fixes (#388)

* Codacy fixes

* Add dummy variable

* Add metapackage instructions (#390)

* Docs: update product help links (#391)

* Fix broken reference

* Update Product Docs URL

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Ludovic Steinbach <[email protected]>
Co-authored-by: Doug Addy <[email protected]>
Co-authored-by: Doug Addy <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Jan 16, 2024
1 parent 21e7709 commit da1f2fe
Show file tree
Hide file tree
Showing 128 changed files with 37,801 additions and 3,569 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ jobs:
needs: local_checks
if: ${{ !startsWith( github.event.pull_request.head.ref, 'dependabot/') }}
uses: ./.github/workflows/server_checks.yml
secrets:
AZURE_APP_ID: ${{ secrets.AZURE_APP_ID }}
AZURE_SECRET: ${{ secrets.AZURE_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
AZURE_VM_NAME: ${{ secrets.AZURE_VM_NAME }}
TEST_SERVER_URL: ${{ secrets.TEST_SERVER_URL }}
TEST_SERVER_READ_USER: ${{ secrets.TEST_SERVER_READ_USER }}
TEST_SERVER_READ_PASS: ${{ secrets.TEST_SERVER_READ_PASS }}
TEST_SERVER_WRITE_USER: ${{ secrets.TEST_SERVER_WRITE_USER }}
TEST_SERVER_WRITE_PASS: ${{ secrets.TEST_SERVER_WRITE_PASS }}
with:
skip-vm-management: ${{ vars.SKIP_VM_MANAGEMENT == 'true' }}
secrets: inherit

doc-deploy-dev:
name: "Deploy development documentation"
Expand Down
32 changes: 8 additions & 24 deletions .github/workflows/local_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ env:
MAIN_PYTHON_VERSION: '3.9'

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

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.MAIN_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

- uses: ansys/actions/code-style@v4

docs-style:
name: Documentation Style Check
Expand All @@ -35,19 +22,22 @@ jobs:
uses: ansys/actions/doc-style@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
vale-version: "2.29.6"

unit_tests:
name: Unit tests
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
steps:
- uses: actions/checkout@v4

- name: Install kerberos headers
run: sudo apt install libkrb5-dev
run: |
sudo apt-get update
sudo apt install libkrb5-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand All @@ -60,12 +50,6 @@ jobs:
- name: Test with tox (no integration tests)
run: tox -- -m "not integration"

- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

package:
name: Build package
runs-on: ubuntu-latest
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/server_checks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
on:
workflow_call:
inputs:
skip-vm-management:
description: >
Whether to skip or not the start up of the virtual machine. Default
value is ``false``.
required: false
default: false
type: boolean
secrets:
AZURE_APP_ID:
required: true
Expand Down Expand Up @@ -38,6 +46,7 @@ jobs:
- name: Start VM with Azure CLI
id: azure_cli
uses: azure/CLI@v1
if: ${{ !(inputs.skip-vm-management)}}
with:
azcliversion: 2.32.0
inlineScript: |
Expand Down Expand Up @@ -73,7 +82,9 @@ jobs:

- name: Install kerberos headers (ubuntu only)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt install libkrb5-dev
run: |
sudo apt-get update
sudo apt install libkrb5-dev
- name: Install dependencies
run: pip install poetry 'tox<4' --disable-pip-version-check
Expand Down Expand Up @@ -141,7 +152,7 @@ jobs:
name: Stop Azure VM
runs-on: ubuntu-latest
needs: docs
if: always()
if: ${{ always() && !(inputs.skip-vm-management)}}

steps:
- name: Stop Azure VM
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ test-output.xml
# Docs builds
doc/build

.ipython/profile_default/history.sqlite

# ipynb (generated from py files on docs build)
*.ipynb

# Pypi things
deps

venv/
46 changes: 24 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ repos:
rev: 23.7.0
hooks:
- id: black
exclude: ^examples/|doc/|.ipython/

# ISORT should be activated at some point
#
# - repo: https://github.com/pycqa/isort
# rev: 5.10.1
# hooks:
# - id: isort

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
Expand All @@ -21,23 +21,25 @@ repos:
rev: v2.2.5
hooks:
- id: codespell
args: ["--ignore-words", "doc/styles/Vocab/ANSYS/accept.txt", "--skip", "poetry.lock"]

# MYPY also not really working...
#
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.991 # Use the sha / tag you want to point at
# hooks:
# - id: mypy
# args: ["--config-file", "pyproject.toml", ./src/ ]

# To be activated after quick dev cycles
#
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
# additional_dependencies: [toml]
# exclude: "tests/"
- repo: local
hooks:
- id: mypy-code
name: "mypy: checks on code"
entry: mypy
language: python
types: [python]
require_serial: true
files: "^(src/)"
additional_dependencies: ["mypy==1.5.1"]

#- repo: https://github.com/pycqa/pydocstyle
# rev: 6.3.0
# hooks:
# - id: pydocstyle
# additional_dependencies: [tomli]
# files: "^(src/)"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down
55 changes: 48 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
|pyansys| |python| |pypi| |GH-CI| |codecov| |MIT| |black|

.. |pyansys| image:: https://img.shields.io/badge/Py-Ansys-ffc107.svg?labelColor=black&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABDklEQVQ4jWNgoDfg5mD8vE7q/3bpVyskbW0sMRUwofHD7Dh5OBkZGBgW7/3W2tZpa2tLQEOyOzeEsfumlK2tbVpaGj4N6jIs1lpsDAwMJ278sveMY2BgCA0NFRISwqkhyQ1q/Nyd3zg4OBgYGNjZ2ePi4rB5loGBhZnhxTLJ/9ulv26Q4uVk1NXV/f///////69du4Zdg78lx//t0v+3S88rFISInD59GqIH2esIJ8G9O2/XVwhjzpw5EAam1xkkBJn/bJX+v1365hxxuCAfH9+3b9/+////48cPuNehNsS7cDEzMTAwMMzb+Q2u4dOnT2vWrMHu9ZtzxP9vl/69RVpCkBlZ3N7enoDXBwEAAA+YYitOilMVAAAAAElFTkSuQmCC
:target: https://docs.pyansys.com/
:alt: PyAnsys

.. |python| image:: https://img.shields.io/pypi/pyversions/ansys-grantami-bomanalytics?logo=pypi
:target: https://pypi.org/project/ansys-grantami-bomanalytics/
:alt: Python

.. |pypi| image:: https://img.shields.io/pypi/v/ansys-grantami-bomanalytics.svg?logo=python&logoColor=white
:target: https://pypi.org/project/ansys-grantami-bomanalytics
:alt: PyPI

.. |codecov| image:: https://codecov.io/gh/ansys/grantami-bomanalytics/branch/main/graph/badge.svg
:target: https://codecov.io/gh/ansys/grantami-bomanalytics
:alt: Codecov

.. |GH-CI| image:: https://github.com/ansys/grantami-bomanalytics/actions/workflows/ci_cd.yml/badge.svg
:target: https://github.com/ansys/grantami-bomanalytics/actions/workflows/ci_cd.yml
:alt: GH-CI

.. |MIT| image:: https://img.shields.io/badge/License-MIT-yellow.svg
:target: https://opensource.org/licenses/MIT
:alt: MIT

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=flat
:target: https://github.com/psf/black
:alt: Black


ansys-grantami-bomanalytics
###########################

Project Overview
----------------
PyGranta BoM Analytics is part of the larger `PyAnsys <https://github.com/pyansys>`_
PyGranta BoM Analytics is part of the larger `PyAnsys <https://docs.pyansys.com>`_
effort to facilitate the use of Ansys technologies directly from Python.

The Granta MI Restricted Substances solution includes a REST API for
evaluating compliance of products, assemblies, specifications, and
materials against legislations. This package abstracts automatically-
generated code into an easy-to-use client library.
The MI Restricted Substances and MI Sustainability solutions for Granta MI include REST APIs for:

- Evaluating compliance of products, assemblies, specifications, and
materials against legislations.
- Evaluating the environmental performance of products, assemblies, materials and processes.

This package abstracts automatically-generated code into an easy-to-use client library.


Installation
Expand All @@ -20,11 +54,18 @@ Install the ``ansys-grantami-bomanalytics`` package with this code:
pip install ansys-grantami-bomanalytics
To install a release compatible with a specific version of Granta MI, use the
`PyGranta <https://grantami.docs.pyansys.com/>`_ meta-package with a requirement specifier:

.. code::
pip install pygranta==2023.2.0
Alternatively, clone and install this package with this code:

.. code::
git clone https://github.com/pyansys/grantami-bomanalytics
git clone https://github.com/ansys/grantami-bomanalytics
cd grantami-bomanalytics
pip install .
Expand All @@ -49,7 +90,7 @@ Here's a brief example of how to use PyGranta BoM Analytics:
>>> query = (
... queries.MaterialImpactedSubstancesQuery()
... .with_material_ids(['plastic-abs-pvc-flame'])
... .with_legislations(['EU REACH - The Candidate List'])
... .with_legislation_ids(['Candidate_AnnexXV'])
... )
# Print out the result from the query.
Expand Down
35 changes: 25 additions & 10 deletions cicd/check_server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import requests
from requests.auth import HTTPBasicAuth
import os
import json
import time
from functools import wraps
import json
import logging
import os
import platform
import time

import requests
from requests.auth import HTTPBasicAuth

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
Expand Down Expand Up @@ -34,12 +36,25 @@ def wrapper(*args, **kwargs):

@block_until_server_is_ok
def check_status(url: str, auth_header: HTTPBasicAuth) -> bool:
python_implementation = platform.python_implementation()
python_version = platform.python_version()
os_version = platform.platform()
user_agent = f"check_server.py {python_implementation}/{python_version} ({os_version})"

try:
response = requests.get(url + "/Health/v2.svc/", auth=auth_header)
except requests.exceptions.RequestException:
# This generally won't happen in normal operation. But if a RequestException happens we want to make sure we
# handle it and try again.
# If MI isn't running we'll generally get a 5xx status from the gateway instead, which is handled below.
response = requests.get(
url + "/Health/v2.svc/",
auth=auth_header,
headers={
"User-Agent": user_agent,
},
)
except requests.exceptions.RequestException as e:
# This generally won't happen in normal operation. But if a RequestException happens we want
# to make sure we handle it and try again.
# If MI isn't running we'll generally get a 5xx status from the gateway instead, which is
# handled below.
logger.error(e)
return False
logger.info(f"Received {response.status_code} response.")
if response.status_code != 200:
Expand Down
Loading

0 comments on commit da1f2fe

Please sign in to comment.