brightway-lca / brightway2-io

Importing and exporting for the Brightway LCA framework
BSD 3-Clause "New" or "Revised" License
27 stars 42 forks source link

Throw error when importing empty directory #97

Open BenPortner opened 3 years ago

BenPortner commented 3 years ago

Brightway throws no error when trying to import an empty directory and applying strategies after. Although the output says that 0 datasets were extracted, this information is easy to miss in the lengthy output:

Code

path = "C:/Users/myuser/myemptyfolder"
importer = bw.SingleOutputEcospold2Importer(path, 'empty-db')
importer.apply_strategies()

Output

Extracting XML data from 0 datasets
Extracted 0 datasets in 4.81 seconds
Applying strategy: normalize_units
Applying strategy: update_ecoinvent_locations
Applying strategy: remove_zero_amount_coproducts
Applying strategy: remove_zero_amount_inputs_with_no_activity
Applying strategy: remove_unnamed_parameters
Applying strategy: es2_assign_only_product_with_amount_as_reference_product
Applying strategy: assign_single_product_as_activity
Applying strategy: create_composite_code
Applying strategy: drop_unspecified_subcategories
Applying strategy: fix_ecoinvent_flows_pre35
Applying strategy: drop_temporary_outdated_biosphere_flows
Applying strategy: link_biosphere_by_flow_uuid
Applying strategy: link_internal_technosphere_by_composite_code
Applying strategy: delete_exchanges_missing_activity
Applying strategy: delete_ghost_exchanges
Applying strategy: remove_uncertainty_from_negative_loss_exchanges
Applying strategy: fix_unreasonably_high_lognormal_uncertainties
Applying strategy: set_lognormal_loc_value
Applying strategy: convert_activity_parameters_to_list
Applying strategy: add_cpc_classification_from_single_reference_product
Applied 20 strategies in 0.00 seconds

Proposal

Instead of going on business-as-usual, the importer should first check if the directory contains a .7z file. If yes, it should unpack it and check the extracted datasets-directory after. If the importer does not find a .7z file or the extracted directory does not include ecospold files, brightway should throw a descriptive error.

cmutel commented 3 years ago

@BenPortner Any interest in fixing this? I don't think 7z is supported in the stdlib, so we could just print an error, but the AB does it somehow...