Skip to content

Commit

Permalink
Refactor install_dev_deps.py to install both main and dev dependencie…
Browse files Browse the repository at this point in the history
…s and rename the function to install_deps.
  • Loading branch information
michaelaye committed Nov 27, 2024
1 parent f6ccf0e commit 24c2008
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions install_dev_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,47 @@
# Define packages that should be installed via pip instead of conda
PIP_PACKAGES = {'build', 'pip-tools'}

def install_dev_deps():
def install_deps():
# Read pyproject.toml
pyproject_path = Path("pyproject.toml")
with open(pyproject_path) as f:
pyproject = tomlkit.load(f)

# Get dev dependencies
# Get both main and dev dependencies
main_deps = pyproject["project"]["dependencies"]
dev_deps = pyproject["project"]["optional-dependencies"]["dev"]
all_deps = main_deps + dev_deps

# Split dependencies into conda and pip packages
conda_deps = [dep for dep in dev_deps if dep not in PIP_PACKAGES]
pip_deps = [dep for dep in dev_deps if dep in PIP_PACKAGES]
conda_deps = [dep for dep in all_deps if dep not in PIP_PACKAGES]
pip_deps = [dep for dep in all_deps if dep in PIP_PACKAGES]

# Install conda packages
if conda_deps:
try:
print(f"Installing with mamba: {' '.join(conda_deps)}")
print("Installing with mamba:", ' '.join(conda_deps))
sh.mamba("install", "-y", "-c", "conda-forge", *conda_deps,
_err=sys.stderr, _out=sys.stdout)
print("Conda installation completed successfully!")
except sh.ErrorReturnCode as e:
print("Error installing conda packages!")
print(f"Exit code: {e.exit_code}")
print(f"Stdout: {e.stdout.decode() if e.stdout else 'No stdout'}")
print(f"Stderr: {e.stderr.decode() if e.stderr else 'No stderr'}")
print("Exit code:", e.exit_code)
print("Stdout:", e.stdout.decode() if e.stdout else 'No stdout')
print("Stderr:", e.stderr.decode() if e.stderr else 'No stderr')
sys.exit(1)

# Install pip packages
if pip_deps:
try:
print(f"\nInstalling with pip: {' '.join(pip_deps)}")
print("\nInstalling with pip:", ' '.join(pip_deps))
sh.pip("install", *pip_deps, _err=sys.stderr, _out=sys.stdout)
print("Pip installation completed successfully!")
except sh.ErrorReturnCode as e:
print("Error installing pip packages!")
print(f"Exit code: {e.exit_code}")
print(f"Stdout: {e.stdout.decode() if e.stdout else 'No stdout'}")
print(f"Stderr: {e.stderr.decode() if e.stderr else 'No stderr'}")
print("Exit code:", e.exit_code)
print("Stdout:", e.stdout.decode() if e.stdout else 'No stdout')
print("Stderr:", e.stderr.decode() if e.stderr else 'No stderr')
sys.exit(1)

if __name__ == "__main__":
install_dev_deps()
install_deps()

0 comments on commit 24c2008

Please sign in to comment.