Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

63 clean code and refactor into class excel to entities #70

Merged

Conversation

carlosmada22
Copy link
Collaborator

@carlosmada22 carlosmada22 commented Jan 31, 2025

This pull request includes changes to the .vscode/settings.json file to add a new debug configuration, and modifications to the bam_masterdata module to refactor the way Excel data is extracted. The most important changes are summarized below:

Debug Configuration Improvements:

  • .vscode/settings.json: Added a new debug configuration for exporting to RDF and set justMyCode to false to include library code in debugging. [1] [2]

Code Refactoring:

@carlosmada22 carlosmada22 linked an issue Jan 31, 2025 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Jan 31, 2025

Pull Request Test Coverage Report for Build 13112718684

Details

  • 22 of 188 (11.7%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.8%) to 96.257%

Changes Missing Coverage Covered Lines Changed/Added Lines %
bam_masterdata/cli/fill_masterdata.py 1 2 50.0%
bam_masterdata/excel/excel_to_entities.py 21 186 11.29%
Totals Coverage Status
Change from base Build 13052092592: 0.8%
Covered Lines: 16407
Relevant Lines: 17045

💛 - Coveralls

Copy link
Contributor

@JosePizarro3 JosePizarro3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect, congrats! 🙂

Just a couple of comments for you to discuss with me if you agree or not.

Maybe it is a good idea to add testing for this class, but this I leave for you to decide if you want to do it in this PR or open a new issue and tackle it later.



class MasterdataExcelExtractor:
DATA_TYPES = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the Enum defined in bam_masterdata.metadata.definitions import DataType. If you want to check if some value is allowed by the data types, you just need to do:

value in [dt.value for dt in DataType]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed thank you!

"OBJECT",
]

VALIDATION_RULES = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a todo comment before this variable?

# TODO move these validation rules to a separate json

This is because I think we could have these mappings in a separate JSON to make it more readable. But you can leave it for another pr :)

from typing import TYPE_CHECKING, Any, Optional, Union

import openpyxl
from openpyxl.worksheet.worksheet import Worksheet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I checked the code and it seems Worksheet is only used for typing. You can:

import re
from typing import TYPE_CHECKING, Any, Optional, Union

if TYPE_CHECKING:
    from openpyxl.worksheet.worksheet import Worksheet

Then, you need to change in all the times a Worksheet was typed in a function by "Worksheet", i.e., add the double-quotes, e.g.:

    def get_last_non_empty_row(
        self, sheet: "Worksheet", start_index: int
    ) -> Optional[int]:

The thing is that, if a class is only used for typing checks, then it does not need to be imported (and hence added to memory) every time the module is executed. That's why we have this TYPE_CHECKING and we just need to add an if condition + double quotes when typing the specific class.

@carlosmada22
Copy link
Collaborator Author

Maybe it is a good idea to add testing for this class, but this I leave for you to decide if you want to do it in this PR or open a new issue and tackle it later.

Perfect, I will open a new issue for the testing after this pull request.

@carlosmada22 carlosmada22 merged commit f46b10f into main Feb 3, 2025
8 checks passed
@carlosmada22 carlosmada22 deleted the 63-clean-code-and-refactor-into-class---excel-to-entities branch February 3, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean code and refactor into class - Excel to Entities
3 participants