theskumar / theskumar/python-dotenv

rewrite always finishes with an error when the file is on a Windows host

Abierto
#554 0 comentarios 0 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

Trying to run iotedgedev in a docker container inside a WSL2 vm always yields the same error:

ERROR: Could not update the environment variable IOTHUB_CONNECTION_STRING in file /home/iotedge/.env

Funny thing is, the variable IS written to the file. What isn't written is the next variable, so clearly an error occurs AFTER having already written the value to the file.

Iotedgedev uses dotenv to update the .env file:

    def save_envvar(self, key, value):
        try:
            dotenv_file = self.get_dotenv_file()
            dotenv_path = os.path.join(os.getcwd(), dotenv_file)
            set_key(dotenv_path, key, value)
        except Exception:
            raise IOError(f("Could not update the environment variable {key} in file {dotenv_path}"))

Now, set_key seems to be using rewrite to update the file, and rewrite does this:

    if error is None:
        shutil.move(dest.name, path)
    else:
        os.unlink(dest.name)
        raise error from None

Instead of plain move it should first do an os.remove and only then move. That should make it work with files on a Windows host.

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 at save_envvar and trace set_key into the rewrite path shown in the report. Reproduce the .env update with a file on a Windows host or WSL2-mounted path, then verify that the update finishes without an error and that subsequent variables are written.

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

Evaluación

Stack tecnológico
docker, python
Área
devops, operating-systems
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.