Skip to content

Commit

Permalink
Add auto-updating of requirements.txt files.
Browse files Browse the repository at this point in the history
  • Loading branch information
etienned committed Dec 2, 2018
1 parent b64b6f1 commit a01fdb3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions poetry/packages/locker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import re

import poetry.packages
import poetry.repositories
Expand All @@ -7,6 +8,7 @@
from tomlkit import document
from typing import List

from poetry.packages import export_requirements
from poetry.utils._compat import Path
from poetry.utils.toml_file import TomlFile
from poetry.version.markers import parse_marker
Expand Down Expand Up @@ -162,6 +164,22 @@ def _write_lock_data(self, data):

self._lock_data = None

self._update_requirements_files()

def _update_requirements_files(self):
for requirements in ("requirements.txt", "requirements-dev.txt"):
path = self.lock.parent / requirements
if path.is_file():
try:
data = path.read_text()
except OSError:
continue
dev = "dev" in requirements
# if match without hash and match with hash
tag = not re.search("\+[^@\n]+@[\da-f]{40}", data)
egg = "#egg=" in data
export_requirements(self, path, dev, tag, egg)

def _get_content_hash(self): # type: () -> str
"""
Returns the sha256 hash of the sorted content of the pyproject file.
Expand Down

0 comments on commit a01fdb3

Please sign in to comment.