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

Mejorar Makefile para conda #45

Open
albertotb opened this issue Jul 30, 2024 · 2 comments
Open

Mejorar Makefile para conda #45

albertotb opened this issue Jul 30, 2024 · 2 comments
Labels
question Further information is requested

Comments

@albertotb
Copy link
Member

Ejemplos:

Ejemplo generado por ChatGPT que comprueba si ya existe el entorno para no recrearlo:

# Name of the conda environment
ENV_NAME=myenv
# Conda environment YAML file
ENV_YAML=environment.yml

# Define the rule to create the conda environment if it does not exist
.PHONY: create_env
create_env:
	@echo "Checking if conda environment '$(ENV_NAME)' exists..."
	@if conda env list | grep -q '$(ENV_NAME)'; then \
		echo "Conda environment '$(ENV_NAME)' already exists."; \
	else \
		echo "Creating conda environment '$(ENV_NAME)'..."; \
		conda env create -f $(ENV_YAML); \
	fi

# Define the rule to run a command within the conda environment
.PHONY: run
run: create_env
	@echo "Running command in conda environment '$(ENV_NAME)'"
	conda run -n $(ENV_NAME) python -c "print('Hello from conda environment!')"

# Example of a rule to install dependencies
.PHONY: install
install: create_env
	@echo "Installing dependencies in conda environment '$(ENV_NAME)'"
	conda run -n $(ENV_NAME) pip install -r requirements.txt
@albertotb
Copy link
Member Author

Todo esto cambia si reemplazamos conda por uv

@albertotb albertotb added the question Further information is requested label Sep 3, 2024
@albertotb
Copy link
Member Author

Aunque esto no es necesario con uv, dejo aquí algunas posibles mejoras en el Makefilepara proyectos que usan conda:

  • Usar conda run -n ENV_NAME para ejecutar los comandos en el entorno creado

  • Si el proyecto no necesita instalar paquetes de conda, se puede reemplazar fácilmente la creación del entorno de conda con:

    curl -LsSf https://astral.sh/uv/0.4.7/install.sh | sh
    source $HOME/.cargo/env
    uv venv --python 3.11
    source .venv/bin/activate
    

    Esto tiene la ventaja de que la instalación de uv son 2 líneas y se puede hacer de forma desatendida, en conda son más líneas y tienes que interactuar con la terminal.

@albertotb albertotb changed the title Mejorar Makefile Mejorar Makefile para conda Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant