diff --git a/.github/workflows/publish-package-prod.yaml b/.github/workflows/publish-package-prod.yaml new file mode 100644 index 000000000..cada7fe92 --- /dev/null +++ b/.github/workflows/publish-package-prod.yaml @@ -0,0 +1,34 @@ +name: Publish Packages to Prod +on: + push: + branches: + - 'main' + +jobs: + Publish: + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v3 + - name: Install dependencies + run: | + python -m pip install twine build + python -m pip install keyrings.google-artifactregistry-auth + - name: Capture build tag + run: | + echo "COMMIT_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Make dists + run: | + python -m build + - name: Show output + run: tree . + - name: Setup gcloud + uses: google-github-actions/setup-gcloud@v0.6.0 + with: + service_account_key: ${{ secrets.GCP_SA_KEY_PROD }} + project_id: ganymede-core + export_default_credentials: true + - name: Publish package + run: | + python3 -m twine upload --verbose --repository-url https://us-central1-python.pkg.dev/ganymede-core/ganymede-py/ dist/* diff --git a/.github/workflows/publish-package-staging.yaml b/.github/workflows/publish-package-staging.yaml new file mode 100644 index 000000000..affb12ce7 --- /dev/null +++ b/.github/workflows/publish-package-staging.yaml @@ -0,0 +1,34 @@ +name: Publish Packages to Staging +on: + push: + branches: + - 'main' + +jobs: + Publish: + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v3 + - name: Install dependencies + run: | + python -m pip install twine build + python -m pip install keyrings.google-artifactregistry-auth + - name: Capture build tag + run: | + echo "COMMIT_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Make dists + run: | + python -m build + - name: Show output + run: tree . + - name: Setup gcloud + uses: google-github-actions/setup-gcloud@v0.6.0 + with: + service_account_key: ${{ secrets.GCP_SA_KEY_STAGING}} + project_id: ganymede-core-staging + export_default_credentials: true + - name: Publish package + run: | + python3 -m twine upload --verbose --repository-url https://us-central1-python.pkg.dev/ganymede-core-staging/ganymede-py/ dist/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0c52cf2f..e39fc8820 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,6 @@ name: test on: push: branches: [ main ] - pull_request: - types: [opened, edited, synchronize] permissions: contents: read diff --git a/.vscode/settings.json b/.vscode/settings.json index 8e1129ea2..0bf66ece7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,27 +12,19 @@ "editor.autoIndent": "keep" }, - // Use flake8, not pylint - "python.linting.pylintEnabled": false, - "python.linting.flake8Enabled": true, - "python.linting.mypyEnabled": true, // Disable Python tests for now. "python.testing.pytestEnabled": false, "python.testing.unittestEnabled": false, - // isort - "isort.path": ["ruff"], - "isort.args": ["--quiet"], - // Use Black for formatting - "python.formatting.provider": "black", - "python.formatting.blackArgs": ["--config", "${workspaceRoot}/pyproject.toml"], + "[python]": { "editor.formatOnPaste": false, "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": "explicit" - } + }, + "editor.defaultFormatter": "ms-python.black-formatter" }, + "black-formatter.args": ["--line-length", "110"], "search.useIgnoreFiles": true, - "python.linting.enabled": true, } diff --git a/src/allotropy/allotrope/models/cell_counting_benchling_2023_09_cell_counting.py b/src/allotropy/allotrope/models/cell_counting_benchling_2023_09_cell_counting.py index fe72c64d1..5fcb01c77 100644 --- a/src/allotropy/allotrope/models/cell_counting_benchling_2023_09_cell_counting.py +++ b/src/allotropy/allotrope/models/cell_counting_benchling_2023_09_cell_counting.py @@ -102,18 +102,14 @@ class ProcessedDataDocument: viability__cell_counter_: TQuantityValuePercent viable_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter total_cell_count: TQuantityValueCell - total_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter | None = ( - None - ) + total_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter | None = None dead_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter | None = ( None ) average_total_cell_diameter: TQuantityValueMicrometer | None = None average_live_cell_diameter__cell_counter_: TQuantityValueMicrometer | None = None average_dead_cell_diameter__cell_counter_: TQuantityValueMicrometer | None = None - total_cell_diameter_distribution_data_cube: TotalCellDiameterDistributionDataCube | None = ( - None - ) + total_cell_diameter_distribution_data_cube: TotalCellDiameterDistributionDataCube | None = None viable_cell_count: TQuantityValueCell | None = None dead_cell_count: TQuantityValueCell | None = None average_total_cell_circularity: TQuantityValueUnitless | None = None diff --git a/src/allotropy/allotrope/models/cell_counting_benchling_2023_11_cell_counting.py b/src/allotropy/allotrope/models/cell_counting_benchling_2023_11_cell_counting.py index 0291f9e83..f78f0b8b3 100644 --- a/src/allotropy/allotrope/models/cell_counting_benchling_2023_11_cell_counting.py +++ b/src/allotropy/allotrope/models/cell_counting_benchling_2023_11_cell_counting.py @@ -318,9 +318,7 @@ class ProcessedDataDocumentItem1: data_processing_document: DataProcessingDocument | None = None data_source_aggregate_document: DataSourceAggregateDocument | None = None processed_data_identifier: TStringValue | None = None - fluorescent_tag_positive_cell_density: TQuantityValueMillionCellsPerMilliliter | None = ( - None - ) + fluorescent_tag_positive_cell_density: TQuantityValueMillionCellsPerMilliliter | None = None fluorescent_tag_positive_percentage: TQuantityValuePercent | None = None field_index: int | None = None @@ -429,9 +427,7 @@ class ProcessedDataDocumentItem: data_processing_document: DataProcessingDocument | None = None data_source_aggregate_document: DataSourceAggregateDocument | None = None processed_data_identifier: TStringValue | None = None - total_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter | None = ( - None - ) + total_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter | None = None dead_cell_density__cell_counter_: TQuantityValueMillionCellsPerMilliliter | None = ( None ) diff --git a/src/allotropy/allotrope/models/cell_culture_analyzer_benchling_2023_09_cell_culture_analyzer.py b/src/allotropy/allotrope/models/cell_culture_analyzer_benchling_2023_09_cell_culture_analyzer.py index a396f60c8..51ba403a0 100644 --- a/src/allotropy/allotrope/models/cell_culture_analyzer_benchling_2023_09_cell_culture_analyzer.py +++ b/src/allotropy/allotrope/models/cell_culture_analyzer_benchling_2023_09_cell_culture_analyzer.py @@ -43,9 +43,7 @@ class SampleDocument: @dataclass class AnalyteDocumentItem: analyte_name: TStringValue - molar_concentration: TNullableQuantityValueMillimolePerLiter | TNullableQuantityValueGramPerLiter | TNullableQuantityValueUnitPerLiter | None = ( - None - ) + molar_concentration: TNullableQuantityValueMillimolePerLiter | TNullableQuantityValueGramPerLiter | TNullableQuantityValueUnitPerLiter | None = None @dataclass @@ -66,21 +64,11 @@ class MeasurementDocumentItem: pH: TNullableQuantityValuePH | None = None osmolality: TNullableQuantityValueMilliOsmolesPerKilogram | None = None viability__cell_counter_: TNullableQuantityValuePercent | None = None - total_cell_density__cell_counter_: TNullableQuantityValueMillionCellsPerMilliliter | None = ( - None - ) - viable_cell_density__cell_counter_: TNullableQuantityValueMillionCellsPerMilliliter | None = ( - None - ) - average_live_cell_diameter__cell_counter_: TNullableQuantityValueMicrometer | None = ( - None - ) - average_total_cell_diameter__cell_counter_: TNullableQuantityValueMicrometer | None = ( - None - ) - total_cell_diameter_distribution__cell_counter_: TNullableQuantityValueTODO | None = ( - None - ) + total_cell_density__cell_counter_: TNullableQuantityValueMillionCellsPerMilliliter | None = None + viable_cell_density__cell_counter_: TNullableQuantityValueMillionCellsPerMilliliter | None = None + average_live_cell_diameter__cell_counter_: TNullableQuantityValueMicrometer | None = None + average_total_cell_diameter__cell_counter_: TNullableQuantityValueMicrometer | None = None + total_cell_diameter_distribution__cell_counter_: TNullableQuantityValueTODO | None = None viable_cell_count__cell_counter_: TNullableQuantityValueCell | None = None total_cell_count__cell_counter_: TNullableQuantityValueCell | None = None diff --git a/src/allotropy/allotrope/models/liquid_chromatography_rec_2023_03_liquid_chromatography.py b/src/allotropy/allotrope/models/liquid_chromatography_rec_2023_03_liquid_chromatography.py index c76a453a4..827dd1804 100644 --- a/src/allotropy/allotrope/models/liquid_chromatography_rec_2023_03_liquid_chromatography.py +++ b/src/allotropy/allotrope/models/liquid_chromatography_rec_2023_03_liquid_chromatography.py @@ -68,12 +68,8 @@ class DeviceControlDocumentItem: detection_type: TStringValue | None = None electronic_absorbance_wavelength_setting: TQuantityValueNanometer | None = None electronic_absorbance_bandwidth_setting: TQuantityValueNanometer | None = None - electronic_absorbance_reference_bandwidth_setting: TQuantityValueNanometer | None = ( - None - ) - electronic_absorbance_reference_wavelength_setting: TQuantityValueNanometer | None = ( - None - ) + electronic_absorbance_reference_bandwidth_setting: TQuantityValueNanometer | None = None + electronic_absorbance_reference_wavelength_setting: TQuantityValueNanometer | None = None detector_offset_setting: TQuantityValue | None = None detector_sampling_rate_setting: TQuantityValueHertz | None = None field_index: int | None = None @@ -148,7 +144,5 @@ class LiquidChromatographyAggregateDocument: @dataclass class Model: - liquid_chromatography_aggregate_document: LiquidChromatographyAggregateDocument | None = ( - None - ) + liquid_chromatography_aggregate_document: LiquidChromatographyAggregateDocument | None = None manifest: str = "http://purl.allotrope.org/manifests/liquid-chromatography/REC/2023/03/liquid-chromatography.manifest" diff --git a/src/allotropy/allotrope/models/multi_analyte_profiling_benchling_2024_01_multi_analyte_profiling.py b/src/allotropy/allotrope/models/multi_analyte_profiling_benchling_2024_01_multi_analyte_profiling.py index 9c0e64ca1..b0cba4f6f 100644 --- a/src/allotropy/allotrope/models/multi_analyte_profiling_benchling_2024_01_multi_analyte_profiling.py +++ b/src/allotropy/allotrope/models/multi_analyte_profiling_benchling_2024_01_multi_analyte_profiling.py @@ -234,6 +234,4 @@ class MultiAnalyteProfilingAggregateDocument: @dataclass class Model(Asm): field_asm_manifest: str | Manifest - multi_analyte_profiling_aggregate_document: MultiAnalyteProfilingAggregateDocument | None = ( - None - ) + multi_analyte_profiling_aggregate_document: MultiAnalyteProfilingAggregateDocument | None = None diff --git a/src/allotropy/allotrope/models/plate_reader_benchling_2023_09_plate_reader.py b/src/allotropy/allotrope/models/plate_reader_benchling_2023_09_plate_reader.py index bf299ca47..fc91fe0b4 100644 --- a/src/allotropy/allotrope/models/plate_reader_benchling_2023_09_plate_reader.py +++ b/src/allotropy/allotrope/models/plate_reader_benchling_2023_09_plate_reader.py @@ -423,12 +423,8 @@ class UltravioletAbsorbancePointDetectionDeviceControlDocumentItem( detector_bandwidth_setting: TQuantityValueNanometer | None = None electronic_absorbance_wavelength_setting: TQuantityValueNanometer | None = None electronic_absorbance_bandwidth_setting: TQuantityValueNanometer | None = None - electronic_absorbance_reference_bandwidth_setting: TQuantityValueNanometer | None = ( - None - ) - electronic_absorbance_reference_wavelength_setting: TQuantityValueNanometer | None = ( - None - ) + electronic_absorbance_reference_bandwidth_setting: TQuantityValueNanometer | None = None + electronic_absorbance_reference_wavelength_setting: TQuantityValueNanometer | None = None field_index: int | None = None diff --git a/src/allotropy/allotrope/models/shared/components/liquid_chromatography.py b/src/allotropy/allotrope/models/shared/components/liquid_chromatography.py index 83f0dadb7..a95148d08 100644 --- a/src/allotropy/allotrope/models/shared/components/liquid_chromatography.py +++ b/src/allotropy/allotrope/models/shared/components/liquid_chromatography.py @@ -51,35 +51,17 @@ class PeakItem: chromatographic_peak_asymmetry_factor: TQuantityValueUnitless | None = None asymmetry_factor_measured_at_baseline: TQuantityValueUnitless | None = None chromatographic_peak_resolution: TQuantityValueUnitless | None = None - chromatographic_peak_resolution_using_baseline_peak_widths: TQuantityValueUnitless | None = ( - None - ) - chromatographic_peak_resolution_using_peak_width_at_half_height: TQuantityValueUnitless | None = ( - None - ) - chromatographic_peak_resolution_using_statistical_moments: TQuantityValueUnitless | None = ( - None - ) + chromatographic_peak_resolution_using_baseline_peak_widths: TQuantityValueUnitless | None = None + chromatographic_peak_resolution_using_peak_width_at_half_height: TQuantityValueUnitless | None = None + chromatographic_peak_resolution_using_statistical_moments: TQuantityValueUnitless | None = None number_of_theoretical_plates__chromatography_: TQuantityValueUnitless | None = None - number_of_theoretical_plates_measured_at_60_7___of_peak_height: TQuantityValueUnitless | None = ( - None - ) - number_of_theoretical_plates_measured_at_32_4___of_peak_height: TQuantityValueUnitless | None = ( - None - ) - number_of_theoretical_plates_measured_at_13_4___of_peak_height: TQuantityValueUnitless | None = ( - None - ) - number_of_theoretical_plates_measured_at_4_4___of_peak_height: TQuantityValueUnitless | None = ( - None - ) + number_of_theoretical_plates_measured_at_60_7___of_peak_height: TQuantityValueUnitless | None = None + number_of_theoretical_plates_measured_at_32_4___of_peak_height: TQuantityValueUnitless | None = None + number_of_theoretical_plates_measured_at_13_4___of_peak_height: TQuantityValueUnitless | None = None + number_of_theoretical_plates_measured_at_4_4___of_peak_height: TQuantityValueUnitless | None = None number_of_theoretical_plates_by_tangent_method: TQuantityValueUnitless | None = None - number_of_theoretical_plates_by_peak_width_at_half_height: TQuantityValueUnitless | None = ( - None - ) - number_of_theoretical_plates_by_peak_width_at_half_height__JP14_: TQuantityValueUnitless | None = ( - None - ) + number_of_theoretical_plates_by_peak_width_at_half_height: TQuantityValueUnitless | None = None + number_of_theoretical_plates_by_peak_width_at_half_height__JP14_: TQuantityValueUnitless | None = None def __post_init__(self) -> None: any_of_keys = [ diff --git a/src/allotropy/allotrope/models/shared/definitions/definitions.py b/src/allotropy/allotrope/models/shared/definitions/definitions.py index eff49ebfc..35a3524cc 100644 --- a/src/allotropy/allotrope/models/shared/definitions/definitions.py +++ b/src/allotropy/allotrope/models/shared/definitions/definitions.py @@ -2,7 +2,6 @@ from dataclasses import dataclass from enum import Enum -from typing import Union from allotropy.exceptions import AllotropeConversionError @@ -27,16 +26,16 @@ class TStringValueItem: TBooleanArray = list[bool] TBooleanOrNullArray = list[bool | None] -TBooleanValue = Union[bool, TBooleanValueItem] +TBooleanValue = bool | TBooleanValueItem TClass = str -TDateTimeValue = Union[str, TDateTimeValueItem] +TDateTimeValue = str | TDateTimeValueItem # TODO(brian): inline this TDateTimeStampValue = TDateTimeValue TNumberArray = list[float] TNumberOrNullArray = list[float | None] TStringArray = list[str] TStringOrNullArray = list[str | None] -TStringValue = Union[str, TStringValueItem] +TStringValue = str | TStringValueItem TTupleData = list[float | bool | str | None] TUnit = str @@ -62,7 +61,7 @@ class InvalidJsonFloat(Enum): field_Infinity_1 = "-Infinity" -JsonFloat = Union[float, InvalidJsonFloat] +JsonFloat = float | InvalidJsonFloat @dataclass @@ -125,10 +124,10 @@ class TDatacubeComponent: field_asm_fill_value: str | float | int | bool | None = None -TDimensionArray = Union[TNumberArray, TBooleanArray, TStringArray] +TDimensionArray = TNumberArray | TBooleanArray | TStringArray -TMeasureArray = Union[TNumberOrNullArray, TBooleanOrNullArray, TStringOrNullArray] +TMeasureArray = TNumberOrNullArray | TBooleanOrNullArray | TStringOrNullArray @dataclass diff --git a/src/allotropy/allotrope/models/spectrophotometry_benchling_2023_12_spectrophotometry.py b/src/allotropy/allotrope/models/spectrophotometry_benchling_2023_12_spectrophotometry.py index c6bf55347..80d7e749b 100644 --- a/src/allotropy/allotrope/models/spectrophotometry_benchling_2023_12_spectrophotometry.py +++ b/src/allotropy/allotrope/models/spectrophotometry_benchling_2023_12_spectrophotometry.py @@ -356,9 +356,7 @@ class ProcessedDataDocumentItem: data_processing_document: DataProcessingDocument | None = None data_source_aggregate_document: DataSourceAggregateDocument | None = None processed_data_identifier: TStringValue | None = None - mass_concentration: TQuantityValueNanogramPerMicroliter | TQuantityValueMicrogramPerMicroliter | TQuantityValuePicogramPerMilliliter | TQuantityValueNanogramPerMilliliter | TQuantityValueMicrogramPerMilliliter | TQuantityValueMilligramPerMilliliter | None = ( - None - ) + mass_concentration: TQuantityValueNanogramPerMicroliter | TQuantityValueMicrogramPerMicroliter | TQuantityValuePicogramPerMilliliter | TQuantityValueNanogramPerMilliliter | TQuantityValueMicrogramPerMilliliter | TQuantityValueMilligramPerMilliliter | None = None field_index: int | None = None @@ -393,12 +391,8 @@ class UltravioletAbsorbancePointDetectionDeviceControlDocumentItem( detector_bandwidth_setting: TQuantityValueNanometer | None = None electronic_absorbance_wavelength_setting: TQuantityValueNanometer | None = None electronic_absorbance_bandwidth_setting: TQuantityValueNanometer | None = None - electronic_absorbance_reference_bandwidth_setting: TQuantityValueNanometer | None = ( - None - ) - electronic_absorbance_reference_wavelength_setting: TQuantityValueNanometer | None = ( - None - ) + electronic_absorbance_reference_bandwidth_setting: TQuantityValueNanometer | None = None + electronic_absorbance_reference_wavelength_setting: TQuantityValueNanometer | None = None field_index: int | None = None diff --git a/src/allotropy/allotrope/schema_parser/backup_manager.py b/src/allotropy/allotrope/schema_parser/backup_manager.py index 3edcb36f5..3a89d34a5 100644 --- a/src/allotropy/allotrope/schema_parser/backup_manager.py +++ b/src/allotropy/allotrope/schema_parser/backup_manager.py @@ -3,9 +3,8 @@ from itertools import zip_longest from pathlib import Path import shutil -from typing import Union -PathType = Union[Path, str] +PathType = Path | str def _files_equal(path1: PathType, path2: PathType) -> bool: diff --git a/src/allotropy/allotrope/schema_parser/generate_schemas.py b/src/allotropy/allotrope/schema_parser/generate_schemas.py index 354acc60f..e3fbbd12c 100644 --- a/src/allotropy/allotrope/schema_parser/generate_schemas.py +++ b/src/allotropy/allotrope/schema_parser/generate_schemas.py @@ -55,10 +55,14 @@ def lint_file(model_path: str) -> None: ) # The second call to ruff checks for additional rules. subprocess.check_call( - f"ruff {model_path} --fix", shell=True, stdout=subprocess.DEVNULL # noqa: S602 + f"ruff {model_path} --fix", + shell=True, # noqa: S602 + stdout=subprocess.DEVNULL, ) subprocess.check_call( - f"black {model_path}", shell=True, stderr=subprocess.DEVNULL # noqa: S602 + f"black {model_path}", + shell=True, # noqa: S602 + stderr=subprocess.DEVNULL, ) diff --git a/src/allotropy/parser_factory.py b/src/allotropy/parser_factory.py index fa962767e..554d6c511 100644 --- a/src/allotropy/parser_factory.py +++ b/src/allotropy/parser_factory.py @@ -1,6 +1,5 @@ from datetime import tzinfo from enum import Enum -from typing import Union from allotropy.exceptions import AllotropeConversionError from allotropy.parsers.agilent_gen5.agilent_gen5_parser import AgilentGen5Parser @@ -56,7 +55,7 @@ class Vendor(Enum): UNCHAINED_LABS_LUNATIC = "UNCHAINED_LABS_LUNATIC" -VendorType = Union[Vendor, str] +VendorType = Vendor | str _VENDOR_TO_PARSER: dict[Vendor, type[VendorParser]] = { diff --git a/src/allotropy/parsers/beckman_vi_cell_blu/vi_cell_blu_parser.py b/src/allotropy/parsers/beckman_vi_cell_blu/vi_cell_blu_parser.py index 7d386efe7..2970c9c2b 100644 --- a/src/allotropy/parsers/beckman_vi_cell_blu/vi_cell_blu_parser.py +++ b/src/allotropy/parsers/beckman_vi_cell_blu/vi_cell_blu_parser.py @@ -131,7 +131,9 @@ def _get_cell_counting_document_item( sample.get_value_not_none("Analysis date/time") ), measurement_identifier=random_uuid_str(), - sample_document=SampleDocument(sample_identifier=sample.get_value("Sample ID")), # type: ignore[arg-type] + sample_document=SampleDocument( + sample_identifier=sample.get_value("Sample ID") + ), # type: ignore[arg-type] device_control_aggregate_document=CellCountingDetectorDeviceControlAggregateDocument( device_control_document=[ DeviceControlDocumentItemModel( diff --git a/src/allotropy/parsers/beckman_vi_cell_xr/vi_cell_xr_parser.py b/src/allotropy/parsers/beckman_vi_cell_xr/vi_cell_xr_parser.py index b05df68d4..70669663d 100644 --- a/src/allotropy/parsers/beckman_vi_cell_xr/vi_cell_xr_parser.py +++ b/src/allotropy/parsers/beckman_vi_cell_xr/vi_cell_xr_parser.py @@ -144,7 +144,9 @@ def _get_cell_counting_document_item( processed_data_document=[ ProcessedDataDocumentItem( data_processing_document=DataProcessingDocument( - cell_type_processing_method=sample.get("Cell type"), # type: ignore[arg-type] + cell_type_processing_method=sample.get( + "Cell type" + ), # type: ignore[arg-type] cell_density_dilution_factor=get_property_from_sample( sample, SampleProperty.DILUTION_FACTOR, diff --git a/src/allotropy/parsers/chemometec_nucleoview/nucleoview_reader.py b/src/allotropy/parsers/chemometec_nucleoview/nucleoview_reader.py index 671ab7967..024df9757 100644 --- a/src/allotropy/parsers/chemometec_nucleoview/nucleoview_reader.py +++ b/src/allotropy/parsers/chemometec_nucleoview/nucleoview_reader.py @@ -28,7 +28,7 @@ def read(cls, contents: IOType) -> pd.DataFrame: if "Time zone offset" in raw_data.columns and "Date time" in raw_data.columns: raw_data.loc[ ~raw_data["Time zone offset"].str.startswith("-"), "Time zone offset" - ] = ("+" + raw_data["Time zone offset"]) + ] = "+" + raw_data["Time zone offset"] # combine date time and UTC offset raw_data["datetime"] = pd.to_datetime( diff --git a/src/allotropy/parsers/novabio_flex2/constants.py b/src/allotropy/parsers/novabio_flex2/constants.py index de3905ff2..8e60c2371 100644 --- a/src/allotropy/parsers/novabio_flex2/constants.py +++ b/src/allotropy/parsers/novabio_flex2/constants.py @@ -1,4 +1,4 @@ -from typing import Any, Union +from typing import Any from allotropy.allotrope.models.shared.definitions.custom import ( TNullableQuantityValueCell, @@ -22,11 +22,13 @@ "or SampleResultsYYYY-MM-DD_HHMMSS.csv where is defined in Settings" ) -MOLAR_CONCENTRATION_CLASSES = Union[ - TNullableQuantityValueMillimolePerLiter, - TNullableQuantityValueGramPerLiter, - TNullableQuantityValueUnitPerLiter, -] +MOLAR_CONCENTRATION_CLASSES = ( + TNullableQuantityValueMillimolePerLiter + | TNullableQuantityValueGramPerLiter + | TNullableQuantityValueUnitPerLiter +) + + ALL_MOLAR_CONCENTRATION_CLASSES: list[ type[TNullableQuantityValueMillimolePerLiter] | type[TNullableQuantityValueGramPerLiter] diff --git a/src/allotropy/parsers/perkin_elmer_envision/perkin_elmer_envision_parser.py b/src/allotropy/parsers/perkin_elmer_envision/perkin_elmer_envision_parser.py index 8daca881f..787de8883 100644 --- a/src/allotropy/parsers/perkin_elmer_envision/perkin_elmer_envision_parser.py +++ b/src/allotropy/parsers/perkin_elmer_envision/perkin_elmer_envision_parser.py @@ -1,6 +1,6 @@ from collections import defaultdict from enum import Enum -from typing import Any, cast, TypeVar, Union +from typing import Any, cast, TypeVar from allotropy.allotrope.models.plate_reader_benchling_2023_09_plate_reader import ( CalculatedDataAggregateDocument, @@ -63,18 +63,17 @@ class ReadType(Enum): LUMINESCENCE = "Luminescence" -MeasurementDocumentItems = Union[ - UltravioletAbsorbancePointDetectionMeasurementDocumentItems, - FluorescencePointDetectionMeasurementDocumentItems, - LuminescencePointDetectionMeasurementDocumentItems, -] - +MeasurementDocumentItems = ( + UltravioletAbsorbancePointDetectionMeasurementDocumentItems + | FluorescencePointDetectionMeasurementDocumentItems + | LuminescencePointDetectionMeasurementDocumentItems +) -DeviceControlAggregateDocument = Union[ - UltravioletAbsorbancePointDetectionDeviceControlAggregateDocument, - FluorescencePointDetectionDeviceControlAggregateDocument, - LuminescencePointDetectionDeviceControlAggregateDocument, -] +DeviceControlAggregateDocument = ( + UltravioletAbsorbancePointDetectionDeviceControlAggregateDocument + | FluorescencePointDetectionDeviceControlAggregateDocument + | LuminescencePointDetectionDeviceControlAggregateDocument +) def safe_value(cls: type[T], value: Any | None) -> T | None: diff --git a/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py b/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py index e76dffd39..7c2f182b0 100644 --- a/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py +++ b/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py @@ -185,5 +185,8 @@ def create(reader: RocheCedexBiohtReader) -> Data: return Data( title=Title.create(reader.title_data), - samples=[Sample.create(name, batch, reader.samples_data) for name, batch in sample_groups], # type: ignore[has-type, misc] + samples=[ + Sample.create(name, batch, reader.samples_data) + for name, batch in sample_groups + ], # type: ignore[has-type, misc] ) diff --git a/src/allotropy/parsers/thermo_fisher_nanodrop_eight/nanodrop_eight_parser.py b/src/allotropy/parsers/thermo_fisher_nanodrop_eight/nanodrop_eight_parser.py index bc6d88210..5105a47a1 100644 --- a/src/allotropy/parsers/thermo_fisher_nanodrop_eight/nanodrop_eight_parser.py +++ b/src/allotropy/parsers/thermo_fisher_nanodrop_eight/nanodrop_eight_parser.py @@ -1,5 +1,4 @@ from collections.abc import Mapping -from typing import Union import pandas as pd @@ -46,22 +45,23 @@ from allotropy.parsers.utils.values import assert_not_none from allotropy.parsers.vendor_parser import VendorParser -ConcentrationType = Union[ - TQuantityValueMicrogramPerMicroliter, - TQuantityValueMicrogramPerMilliliter, - TQuantityValueMilligramPerMilliliter, - TQuantityValueNanogramPerMicroliter, - TQuantityValueNanogramPerMilliliter, - TQuantityValuePicogramPerMilliliter, -] -ConcentrationClassType = Union[ - type[TQuantityValueMicrogramPerMicroliter], - type[TQuantityValueMicrogramPerMilliliter], - type[TQuantityValueMilligramPerMilliliter], - type[TQuantityValueNanogramPerMicroliter], - type[TQuantityValueNanogramPerMilliliter], - type[TQuantityValuePicogramPerMilliliter], -] +ConcentrationType = ( + TQuantityValueMicrogramPerMicroliter + | TQuantityValueMicrogramPerMilliliter + | TQuantityValueMilligramPerMilliliter + | TQuantityValueNanogramPerMicroliter + | TQuantityValueNanogramPerMilliliter + | TQuantityValuePicogramPerMilliliter +) + +ConcentrationClassType = ( + type[TQuantityValueMicrogramPerMicroliter] + | type[TQuantityValueMicrogramPerMilliliter] + | type[TQuantityValueMilligramPerMilliliter] + | type[TQuantityValueNanogramPerMicroliter] + | type[TQuantityValueNanogramPerMilliliter] + | type[TQuantityValuePicogramPerMilliliter] +) CONCENTRATION_UNIT_TO_TQUANTITY: Mapping[str, ConcentrationClassType] = { "ug/ul": TQuantityValueMicrogramPerMicroliter, diff --git a/src/allotropy/parsers/utils/values.py b/src/allotropy/parsers/utils/values.py index ff135128a..6fd27fe9f 100644 --- a/src/allotropy/parsers/utils/values.py +++ b/src/allotropy/parsers/utils/values.py @@ -1,13 +1,13 @@ from __future__ import annotations import re -from typing import Any, TypeVar, Union +from typing import Any, TypeVar import pandas as pd from allotropy.exceptions import AllotropeConversionError -PrimitiveValue = Union[str, int, float] +PrimitiveValue = str | int | float def try_int(value: str | None, value_name: str) -> int: diff --git a/src/allotropy/types.py b/src/allotropy/types.py index 93de00c65..e71a8647a 100644 --- a/src/allotropy/types.py +++ b/src/allotropy/types.py @@ -1,3 +1,3 @@ -from typing import IO, Union +from typing import IO -IOType = Union[IO[bytes], IO[str]] +IOType = IO[bytes] | IO[str] diff --git a/tests/allotrope/schema_parser/generate_schemas_test.py b/tests/allotrope/schema_parser/generate_schemas_test.py index 3385c9039..4e2160a42 100644 --- a/tests/allotrope/schema_parser/generate_schemas_test.py +++ b/tests/allotrope/schema_parser/generate_schemas_test.py @@ -6,6 +6,4 @@ def test_generate_schemas_runs_to_completion() -> None: root_dir = Path(__file__).parent.parent.parent.parent models_changed = generate_schemas(root_dir, dry_run=True) - assert ( - not models_changed - ), f"Expected no models files to have changed by generate-schemas script, found changes in: {models_changed}.\nPlease run 'hatch run scripts:generate-schemas' and validate the changes." + assert not models_changed, f"Expected no models files to have changed by generate-schemas script, found changes in: {models_changed}.\nPlease run 'hatch run scripts:generate-schemas' and validate the changes." diff --git a/tests/parsers/appbio_quantstudio/appbio_quantstudio_structure_test.py b/tests/parsers/appbio_quantstudio/appbio_quantstudio_structure_test.py index 16a138220..df265d636 100644 --- a/tests/parsers/appbio_quantstudio/appbio_quantstudio_structure_test.py +++ b/tests/parsers/appbio_quantstudio/appbio_quantstudio_structure_test.py @@ -145,7 +145,6 @@ def test_header_builder_no_header_then_raise() -> None: @pytest.mark.short def test_results_builder() -> None: - data = pd.DataFrame( { "Well": [1], diff --git a/tests/parsers/beckman_vi_cell_blu/vi_cell_blu_data.py b/tests/parsers/beckman_vi_cell_blu/vi_cell_blu_data.py index 7757088f0..9b7d30c32 100644 --- a/tests/parsers/beckman_vi_cell_blu/vi_cell_blu_data.py +++ b/tests/parsers/beckman_vi_cell_blu/vi_cell_blu_data.py @@ -96,7 +96,9 @@ def get_model() -> Model: CellCountingDetectorMeasurementDocumentItem( measurement_identifier="", measurement_time="2022-03-21T16:56:00+00:00", - sample_document=SampleDocument(sample_identifier=sample.get("Sample ID")), # type: ignore[arg-type] + sample_document=SampleDocument( + sample_identifier=sample.get("Sample ID") + ), # type: ignore[arg-type] device_control_aggregate_document=CellCountingDetectorDeviceControlAggregateDocument( device_control_document=[ DeviceControlDocumentItemModel( @@ -109,12 +111,18 @@ def get_model() -> Model: processed_data_document=[ ProcessedDataDocumentItem( data_processing_document=DataProcessingDocument( - cell_type_processing_method=sample.get("Cell type"), # type: ignore[arg-type] + cell_type_processing_method=sample.get( + "Cell type" + ), # type: ignore[arg-type] minimum_cell_diameter_setting=TQuantityValueMicrometer( - value=sample.get("Minimum Diameter (μm)"), # type: ignore[arg-type] + value=sample.get( + "Minimum Diameter (μm)" + ), # type: ignore[arg-type] ), maximum_cell_diameter_setting=TQuantityValueMicrometer( - value=sample.get("Maximum Diameter (μm)"), # type: ignore[arg-type] + value=sample.get( + "Maximum Diameter (μm)" + ), # type: ignore[arg-type] ), cell_density_dilution_factor=TQuantityValueUnitless( value=sample.get("Dilution"), # type: ignore[arg-type] @@ -124,19 +132,27 @@ def get_model() -> Model: value=sample.get("Viability (%)"), # type: ignore[arg-type] ), viable_cell_density__cell_counter_=TQuantityValueMillionCellsPerMilliliter( - value=sample.get("Viable (x10^6) cells/mL"), # type: ignore[arg-type] + value=sample.get( + "Viable (x10^6) cells/mL" + ), # type: ignore[arg-type] ), total_cell_count=TQuantityValueCell( value=sample.get("Cell count"), # type: ignore[arg-type] ), total_cell_density__cell_counter_=TQuantityValueMillionCellsPerMilliliter( - value=sample.get("Total (x10^6) cells/mL"), # type: ignore[arg-type] + value=sample.get( + "Total (x10^6) cells/mL" + ), # type: ignore[arg-type] ), average_total_cell_diameter=TQuantityValueMicrometer( - value=sample.get("Average diameter (μm)"), # type: ignore[arg-type] + value=sample.get( + "Average diameter (μm)" + ), # type: ignore[arg-type] ), average_live_cell_diameter__cell_counter_=TQuantityValueMicrometer( - value=sample.get("Average viable diameter (μm)"), # type: ignore[arg-type] + value=sample.get( + "Average viable diameter (μm)" + ), # type: ignore[arg-type] ), viable_cell_count=TQuantityValueCell( value=sample.get("Viable cells"), # type: ignore[arg-type] @@ -145,7 +161,9 @@ def get_model() -> Model: value=sample.get("Average circularity"), # type: ignore[arg-type] ), average_viable_cell_circularity=TQuantityValueUnitless( - value=sample.get("Average viable circularity"), # type: ignore[arg-type] + value=sample.get( + "Average viable circularity" + ), # type: ignore[arg-type] ), ) ], diff --git a/tests/parsers/test_utils.py b/tests/parsers/test_utils.py index ce2fdb58d..51261cd2b 100644 --- a/tests/parsers/test_utils.py +++ b/tests/parsers/test_utils.py @@ -43,7 +43,7 @@ def _assert_allotrope_dicts_equal( MEASUREMENT_IDENTIFIER, ] exclude_regex_paths = [ - fr"\['{exclude_id}'\]" for exclude_id in identifiers_to_exclude + rf"\['{exclude_id}'\]" for exclude_id in identifiers_to_exclude ] ddiff = DeepDiff( expected_replaced,