Skip to content

Commit

Permalink
Bugfix/ python3.12 compatibility issue (#1498)
Browse files Browse the repository at this point in the history
* Python 3.12 compatibility fix

* Apply pre-commit fixes (ruff and ruff-format)

* Add Troubleshooting to README explaining the feature/fix

* Add Troubleshooting to README.md explaining the feature/fix

* Update README.md

* Update README.md

---------

Co-authored-by: Dhanshree Arora <DhanshreeA@users.noreply.github.com>
  • Loading branch information
OlawumiSalaam and DhanshreeA authored Jan 13, 2025
1 parent c5d1ee0 commit 0159d87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ ersilia delete eos4e40

Please see the [Ersilia Book](https://ersilia.gitbook.io/ersilia-book/) for more examples and detailed explanations.

For Python versions 3.12, Ersilia explicitly installs the setuptools library during installation. This is due to a compatibility issue in Python 3.12, which is described in python/cpython#95299.

Note: If you are using Python 3.12, you don’t need to take any manual action. The Ersilia CLI automatically handles this by installing setuptools as part of the setup process.

## Contribute

The Ersilia Model Hub is a Free, Open Source Software and we highly value new contributors. There are several ways in which you can contribute to the project:
Expand Down
21 changes: 20 additions & 1 deletion ersilia/hub/fetch/fetch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib
import json
import os
import sys
from collections import namedtuple

from ... import ErsiliaBase
Expand All @@ -15,7 +16,7 @@
StandardModelExampleError,
)
from ...utils.exceptions_utils.throw_ersilia_exception import throw_ersilia_exception
from ...utils.terminal import yes_no_input
from ...utils.terminal import run_command, yes_no_input
from . import STATUS_FILE
from .lazy_fetchers.dockerhub import ModelDockerHubFetcher
from .lazy_fetchers.hosted import ModelHostedFetcher
Expand Down Expand Up @@ -93,6 +94,24 @@ def __init__(
ErsiliaBase.__init__(
self, config_json=config_json, credentials_json=credentials_json
)

# Python 3.12 Compatibility Check and Setuptools Handling
if sys.version_info >= (3, 12):
self.logger.info("Detected Python 3.12. Verifying setuptools...")
try:
importlib.import_module("setuptools")
self.logger.info("Setuptools is already installed.")
except ImportError:
self.logger.warning("Setuptools is not installed. Installing now...")
try:
run_command("python -m pip install setuptools")
self.logger.info("Setuptools installed successfully.")
except Exception as e:
self.logger.error(f"Failed to install setuptools: {str(e)}")
raise RuntimeError(
"Setuptools is required but could not be installed. Please resolve this manually."
)

self.ji = JsonModelsInterface(config_json=self.config_json)
self.overwrite = overwrite
self.mode = mode
Expand Down

0 comments on commit 0159d87

Please sign in to comment.