Skip to content
Merged
54 changes: 28 additions & 26 deletions src/sasctl/pzmm/write_json_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,34 @@ def create_requirements_json(
item[0] for item in package_and_version if not item[1]
]


IMPORT_TO_INSTALL_MAPPING = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could the addition of this import to install mapping create some issues with backwards compatibility? I noticed that in the example files it directs users to manually change the import names for packages like sklearn.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I think we're good here, since it was a non-programmatic ask. If they go hunting to change something and find it's fixed, I doubt we'll get complaints.

# Data Science & ML Core
"sklearn": "scikit-learn",
"skimage": "scikit-image",
"cv2": "opencv-python",
"PIL": "Pillow",
# Data Formats & Parsing
"yaml": "PyYAML",
"bs4": "beautifulsoup4",
"docx": "python-docx",
"pptx": "python-pptx",
# Date & Time Utilities
"dateutil": "python-dateutil",
# Database Connectors
"MySQLdb": "MySQL-python",
"psycopg2": "psycopg2-binary",
# System & Platform
"win32api": "pywin32",
"win32com": "pywin32",
# Scientific Libraries
"Bio": "biopython",
}

# Map import names to their corresponding package installation names
package_and_version = [
(IMPORT_TO_INSTALL_MAPPING.get(name, name), version) for name, version in package_and_version
]

if create_requirements_txt:
requirements_txt = ""
Expand Down Expand Up @@ -1752,37 +1780,11 @@ def package_not_found_output(package_name, package_versions):
package_versions.append([package_name, None])
return package_versions


IMPORT_TO_INSTALL_MAPPING = {
# Data Science & ML Core
"sklearn": "scikit-learn",
"skimage": "scikit-image",
"cv2": "opencv-python",
"PIL": "Pillow",
# Data Formats & Parsing
"yaml": "PyYAML",
"bs4": "beautifulsoup4",
"docx": "python-docx",
"pptx": "python-pptx",
# Date & Time Utilities
"dateutil": "python-dateutil",
# Database Connectors
"MySQLdb": "MySQL-python",
"psycopg2": "psycopg2-binary",
# System & Platform
"win32api": "pywin32",
"win32com": "pywin32",
# Scientific Libraries
"Bio": "biopython",
}

package_and_version = []

for package in package_list:
try:
name = importlib.import_module(package)
package = IMPORT_TO_INSTALL_MAPPING.get(package, package)

try:
package_and_version.append([package, name.__version__])
except AttributeError:
Expand Down
Loading