theskumar / theskumar/python-dotenv

Feature request: custom merge logic or variables

Abierto
#374 0 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
8.9k
Forks
581
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hello, this is a feature request for enabling custom merge logic when the environment variables are updated with values read from .env file.

My use case is that I would like to append an element to a colon-separated list of paths. Typical colon-separated environment variables are PATH or LD_LIBRARY_PATH. So the reading of the .env file should neither override, nor leave the original environment variables, instead it should extend the list.

Currently I use the following pseudo-code for this:

cfg = dotenv_values()
path_elems = []
if 'LD_LIBRARY_PATH' in os.environ:
    path_elems.extend(os.environ['LD_LIBRARY_PATH'].split(':'))
if 'LD_LIBRARY_PATH' in cfg:
    path_elems.append(cfg['LD_LIBRARY_PATH'])
path_elems = list(OrderedDict.fromkeys(path_elems)) # remove duplicates
path = ':'.join(path_elems)
path = path.replace('::', ':') # remove empty elements
os.environ['LD_LIBRARY_PATH'] = path

I think such logic could be integrated into the dotenv library. This would require changing the API: instead of / apart the override parameter the dotenv methods could take a variable name -> callable dictionary, where the callable would take as parameters the current and the new value and handle the merge logic for the specified variable. Senseful default behavior could be configured to simulate the current override/not override functionality.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Start with the dotenv methods that accept the existing override parameter and trace how values from .env are applied to the environment. Define how a variable-to-callable API would coexist with current override and non-override behavior, using the LD_LIBRARY_PATH example as the target case. Done means custom merge logic can extend and normalize a colon-separated value without changing existing defaults.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devops, tooling
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.