Skip to content

Commit

Permalink
Create fn
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca committed Nov 4, 2022
1 parent 7c4f592 commit 44cd4d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
16 changes: 15 additions & 1 deletion .actions/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from pprint import pprint
from types import ModuleType
from typing import List, Optional, Sequence, Tuple
from typing import Dict, List, Optional, Sequence, Tuple

import pkg_resources

Expand Down Expand Up @@ -100,6 +100,20 @@ def copy_replace_imports(
fo.writelines(lines)


def create_mirror_package(source_dir: str, package_mapping: Dict[str, str]) -> None:
# replace imports and copy the code
mapping = package_mapping.copy()
mapping.pop("lightning", None) # pop this key to avoid replacing `lightning` to `lightning.lightning`
for new, previous in mapping.items():
copy_replace_imports(
source_dir=os.path.join(source_dir, previous),
# pytorch_lightning uses lightning_lite, so we need to replace all imports for all directories
source_imports=list(mapping.values()),
target_imports=[f"lightning.{new}" for new in mapping],
target_dir=os.path.join(source_dir, "lightning", new),
)


class AssistantCLI:
@staticmethod
def requirements_prune_pkgs(packages: Sequence[str], req_files: Sequence[str] = REQUIREMENT_FILES_ALL) -> None:
Expand Down
21 changes: 21 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@ exclude __pycache__
include .actions/setup_tools.py
include .actions/assistant.py
include *.cff # citation info
recursive-include src/lightning *.md
recursive-include requirements *.txt
recursive-include src/lightning/app/ui *
recursive-include src/lightning/cli/*-template *
prune src/lightning_app
prune src/lightning_lite
prune src/pytorch_lightning
recursive-include src/lightning *.md
recursive-include requirements *.txt
recursive-include src/lightning/app/ui *
recursive-include src/lightning/cli/*-template *
prune src/lightning_app
prune src/lightning_lite
prune src/pytorch_lightning
recursive-include src/lightning *.md
recursive-include requirements *.txt
recursive-include src/lightning/app/ui *
recursive-include src/lightning/cli/*-template *
prune src/lightning_app
prune src/lightning_lite
prune src/pytorch_lightning
11 changes: 1 addition & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,7 @@ def _load_py_module(name: str, location: str) -> ModuleType:
# merge all requirements files
setup_tools._load_aggregate_requirements(_PATH_REQUIRE, _FREEZE_REQUIREMENTS)
# replace imports and copy the code
mapping = _PACKAGE_MAPPING.copy()
del mapping["lightning"] # del this key to avoid replacing `lightning` to `lightning.lightning`
for new, previous in mapping.items():
assistant.copy_replace_imports(
source_dir=os.path.join(_PATH_SRC, previous),
# pytorch_lightning uses lightning_lite, so we need to replace all imports for all directories
source_imports=list(mapping.values()),
target_imports=[f"lightning.{new}" for new in mapping],
target_dir=os.path.join(_PATH_SRC, "lightning", new),
)
assistant.create_mirror_package(_PATH_SRC, _PACKAGE_MAPPING)
elif package_to_install not in _PACKAGE_MAPPING:
raise ValueError(f"Unexpected package name: {_PACKAGE_NAME}. Possible choices are: {list(_PACKAGE_MAPPING)}")

Expand Down

0 comments on commit 44cd4d6

Please sign in to comment.