1919import tarfile
2020import tempfile
2121import urllib .request
22- from datetime import datetime
2322from distutils .version import LooseVersion
2423from importlib .util import module_from_spec , spec_from_file_location
2524from itertools import chain
2625from types import ModuleType
27- from typing import Dict , List , Sequence
26+ from typing import Dict , List
2827
2928from pkg_resources import parse_requirements
3029
3130_PROJECT_ROOT = os .path .dirname (os .path .dirname (__file__ ))
32- _PACKAGE_MAPPING = {"pytorch" : "pytorch_lightning" , "app" : "lightning_app" }
31+ _PACKAGE_MAPPING = {"pytorch" : "pytorch_lightning" , "app" : "lightning_app" , "lite" : "lightning_lite" }
3332
3433# TODO: remove this once lightning-ui package is ready as a dependency
3534_LIGHTNING_FRONTEND_RELEASE_URL = "https://storage.googleapis.com/grid-packages/lightning-ui/v0.0.0/build.tar.gz"
@@ -83,7 +82,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
8382 is_strict = False
8483 req = ln .strip ()
8584 # skip directly installed dependencies
86- if not req or req .startswith ("http" ) or "@http " in req :
85+ if not req or req .startswith ("http" ) or "@" in req :
8786 return ""
8887 # extract the major version from all listed versions
8988 if unfreeze == "major" :
@@ -237,20 +236,6 @@ def create_mirror_package(src_folder: str, lit_pkg_mapping: dict) -> None:
237236 copy_adjusted_modules (src_folder , pkg_name , lit_name , lit_pkg_mapping )
238237
239238
240- def set_version_today (fpath : str ) -> None :
241- """Replace the template date with today."""
242- with open (fpath ) as fp :
243- lines = fp .readlines ()
244-
245- def _replace_today (ln ):
246- today = datetime .now ()
247- return ln .replace ("YYYY.-M.-D" , f"{ today .year } .{ today .month } .{ today .day } " )
248-
249- lines = list (map (_replace_today , lines ))
250- with open (fpath , "w" ) as fp :
251- fp .writelines (lines )
252-
253-
254239def _download_frontend (pkg_path : str ):
255240 """Downloads an archive file for a specific release of the Lightning frontend and extracts it to the correct
256241 directory."""
@@ -273,27 +258,6 @@ def _download_frontend(pkg_path: str):
273258 print ("The Lightning UI downloading has failed!" )
274259
275260
276- def _relax_require_versions (
277- source_dir : str = "src" , req_dir : str = "requirements" , strict_pkgs : Sequence [str ] = ("lightning_app" ,)
278- ) -> None :
279- """Parse the base requirements and append as version adjustments if needed `pkg>=X1.Y1.Z1,==X2.Y2.*`.
280-
281- >>> _relax_require_versions("../src", "../requirements")
282- """
283- strict_pkgs = strict_pkgs or tuple ()
284- reqs = load_requirements (req_dir , file_name = "base.txt" )
285- for i , req in enumerate (parse_requirements (reqs )):
286- ver = parse_version_from_file (os .path .join (source_dir , req .name ))
287- if not ver :
288- continue
289- if req .name not in strict_pkgs :
290- ver = "." .join (ver .split ("." )[:2 ] + ["*" ])
291- reqs [i ] = f"{ req } , =={ ver } "
292-
293- with open (os .path .join (req_dir , "base.txt" ), "w" ) as fp :
294- fp .writelines ([ln + os .linesep for ln in reqs ])
295-
296-
297261def _load_aggregate_requirements (req_dir : str = "requirements" , freeze_requirements : bool = False ) -> None :
298262 """Load all base requirements from all particular packages and prune duplicates."""
299263 requires = [
@@ -308,3 +272,19 @@ def _load_aggregate_requirements(req_dir: str = "requirements", freeze_requireme
308272 requires = list (chain (* requires ))
309273 with open (os .path .join (req_dir , "base.txt" ), "w" ) as fp :
310274 fp .writelines ([ln + os .linesep for ln in requires ])
275+
276+
277+ def set_actual_version_from_src (req_path : str , src_root : str , pkg_name : str ) -> None :
278+ """Setting actual version from source code for a given package."""
279+ with open (req_path , encoding = "utf-8" ) as fo :
280+ lines = fo .readlines ()
281+ ver = parse_version_from_file (os .path .join (src_root , pkg_name .replace ("-" , "_" )))
282+ for i , ln in enumerate (lines ):
283+ reqs = list (parse_requirements ([ln ]))
284+ if not reqs :
285+ continue
286+ if reqs [0 ].name == pkg_name :
287+ lines [i ] = f"{ pkg_name } =={ ver } { os .linesep } "
288+
289+ with open (req_path , "w" , encoding = "utf-8" ) as fw :
290+ fw .writelines (lines )
0 commit comments