Skip to content

Commit 1f1c71a

Browse files
Bordacarmocca
andauthored
unify extras & minor CI cleaning: move env. var (#15942)
Co-authored-by: Carlos Mocholí <[email protected]>
1 parent 1eaff9b commit 1f1c71a

File tree

13 files changed

+104
-74
lines changed

13 files changed

+104
-74
lines changed

.actions/assistant.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
6060
Returns:
6161
adjusted requirement
6262
63-
>>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # anything", unfreeze="")
63+
>>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # anything", unfreeze="none")
6464
'arrow<=1.2.2,>=1.2.0'
65-
>>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # strict", unfreeze="")
65+
>>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # strict", unfreeze="none")
6666
'arrow<=1.2.2,>=1.2.0 # strict'
6767
>>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # my name", unfreeze="all")
6868
'arrow>=1.2.0'
@@ -79,6 +79,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
7979
>>> _augment_requirement("arrow", unfreeze="major")
8080
'arrow'
8181
"""
82+
assert unfreeze in {"none", "major", "all"}
8283
# filer all comments
8384
if comment_char in ln:
8485
comment = ln[ln.index(comment_char) :]
@@ -88,7 +89,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
8889
is_strict = False
8990
req = ln.strip()
9091
# skip directly installed dependencies
91-
if not req or req.startswith("http") or "@" in req:
92+
if not req or any(c in req for c in ["http:", "https:", "@"]):
9293
return ""
9394
# extract the major version from all listed versions
9495
if unfreeze == "major":
@@ -99,7 +100,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
99100
ver_major = None
100101

101102
# remove version restrictions unless they are strict
102-
if unfreeze and "<" in req and not is_strict:
103+
if unfreeze != "none" and "<" in req and not is_strict:
103104
req = re.sub(r",? *<=? *[\d\.\*]+,? *", "", req).strip()
104105
if ver_major is not None and not is_strict:
105106
# add , only if there are already some versions
@@ -121,6 +122,7 @@ def load_requirements(
121122
>>> load_requirements(path_req, "docs.txt", unfreeze="major") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
122123
['sphinx>=4.0, <6.0 # strict', ...]
123124
"""
125+
assert unfreeze in {"none", "major", "all"}
124126
with open(os.path.join(path_dir, file_name)) as file:
125127
lines = [ln.strip() for ln in file.readlines()]
126128
reqs = [_augment_requirement(ln, comment_char=comment_char, unfreeze=unfreeze) for ln in lines]
@@ -206,17 +208,21 @@ def _download_frontend(pkg_path: str):
206208

207209

208210
def _load_aggregate_requirements(req_dir: str = "requirements", freeze_requirements: bool = False) -> None:
209-
"""Load all base requirements from all particular packages and prune duplicates."""
211+
"""Load all base requirements from all particular packages and prune duplicates.
212+
213+
>>> _load_aggregate_requirements(os.path.join(_PROJECT_ROOT, "requirements"))
214+
"""
210215
requires = [
211-
load_requirements(d, file_name="base.txt", unfreeze=not freeze_requirements)
216+
# TODO: consider passing unfreeze as string instead
217+
load_requirements(d, file_name="base.txt", unfreeze="none" if freeze_requirements else "major")
212218
for d in glob.glob(os.path.join(req_dir, "*"))
213219
# skip empty folder as git artefacts, and resolving Will's special issue
214220
if os.path.isdir(d) and len(glob.glob(os.path.join(d, "*"))) > 0 and "__pycache__" not in d
215221
]
216222
if not requires:
217223
return None
218224
# TODO: add some smarter version aggregation per each package
219-
requires = list(chain(*requires))
225+
requires = sorted(set(chain(*requires)))
220226
with open(os.path.join(req_dir, "base.txt"), "w") as fp:
221227
fp.writelines([ln + os.linesep for ln in requires] + [os.linesep])
222228

.azure/app-cloud-e2e.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,15 @@ jobs:
113113
displayName: 'Info'
114114
115115
# TODO: we are testing it as `lightning`, so add also version for `lightning_app`
116-
- bash: git restore . && python -m pip install -e . -r requirements/app/test.txt -r requirements/app/ui.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
116+
- bash: |
117+
pip install -e .[test] \
118+
-f https://download.pytorch.org/whl/cpu/torch_stable.html
119+
env:
120+
FREEZE_REQUIREMENTS: "1"
117121
displayName: 'Install Lightning & dependencies'
118122
119123
- bash: |
120-
python -m pip install playwright
124+
pip install playwright
121125
python -m playwright install # --with-deps
122126
displayName: 'Install Playwright system dependencies'
123127
@@ -130,7 +134,6 @@ jobs:
130134
condition: eq(variables['name'], 'quick_start')
131135
displayName: 'Clone Quick start Repo'
132136
133-
134137
# - bash: |
135138
# rm -rf examples/app_template_jupyterlab || true
136139
# git clone https://github.com/Lightning-AI/LAI-lightning-template-jupyterlab-App examples/app_template_jupyterlab
@@ -144,7 +147,7 @@ jobs:
144147
condition: eq(variables['name'], 'template_react_ui')
145148
displayName: 'Clone Template React UI Repo'
146149
147-
- bash: python -m pip install -q -r .actions/requirements.txt
150+
- bash: pip install -q -r .actions/requirements.txt
148151
displayName: 'Install assistant dependencies'
149152

150153
# Fix imports to use `lightning` instead of `lightning_app` since we install lightning only ATM

.azure/gpu-tests-lite.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
- bash: python -m coverage run --source lightning_lite -m pytest --ignore benchmarks -v --junitxml=$(Build.StagingDirectory)/test-results.xml --durations=50
9797
env:
9898
PL_RUN_CUDA_TESTS: "1"
99+
CUDA_LAUNCH_BLOCKING: "1"
99100
workingDirectory: tests/tests_lite
100101
displayName: 'Testing: Lite standard'
101102
timeoutInMinutes: "10"

.github/workflows/ci-examples-app.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ jobs:
7272
key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ matrix.pkg-name }}-${{ matrix.requires }}-${{ hashFiles('requirements/app/base.txt') }}
7373
restore-keys: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ matrix.pkg-name }}-${{ matrix.requires }}-
7474

75-
- name: Install dependencies
75+
- name: Install Lightning package & dependencies
76+
env:
77+
PACKAGE_NAME: ${{ matrix.pkg-name }}
78+
FREEZE_REQUIREMENTS: 1
7679
run: |
77-
pip --version
78-
pip install -r requirements/app/devel.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
80+
# do not use `-e` because it will make both packages available since it adds `src` to `sys.path` automatically
81+
pip install .[dev] --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
7982
pip list
8083
8184
- name: Setup Node.js
@@ -86,12 +89,6 @@ jobs:
8689
- name: Install Yarn
8790
run: npm install -g yarn
8891

89-
- name: Install Lightning package
90-
env:
91-
PACKAGE_NAME: ${{ matrix.pkg-name }}
92-
# do not use -e because it will make both packages available since it adds `src` to `sys.path` automatically
93-
run: pip install .
94-
9592
- name: Adjust tests
9693
if: ${{ matrix.pkg-name == 'lightning' }}
9794
run: |
@@ -116,7 +113,10 @@ jobs:
116113
AWS_DEFAULT_REGION: us-east-1
117114
PYTEST_ARTIFACT: results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
118115
run: |
119-
coverage run --source ${COVERAGE_SCOPE} -m pytest -m "not cloud" tests_examples_app --timeout=300 -vvvv --junitxml=$PYTEST_ARTIFACT --durations=0
116+
python -m coverage run --source ${COVERAGE_SCOPE} \
117+
-m pytest -m "not cloud" tests_examples_app \
118+
--timeout=300 --durations=0 -vvvv \
119+
--junitxml=$PYTEST_ARTIFACT
120120
121121
- name: Upload pytest test results
122122
uses: actions/upload-artifact@v3

.github/workflows/ci-tests-app.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ concurrency:
2222
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
2323
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
2424

25-
env:
26-
FREEZE_REQUIREMENTS: 1
27-
2825
defaults:
2926
run:
3027
shell: bash
@@ -77,11 +74,12 @@ jobs:
7774
- name: Switch PyTorch URL
7875
run: python -c "print('TORCH_URL=https://download.pytorch.org/whl/' + str('test/cpu/torch_test.html' if '${{matrix.release}}' == 'pre' else 'cpu/torch_stable.html'))" >> $GITHUB_ENV
7976

80-
- name: Install package & depenencies
77+
- name: Install package & dependencies
8178
env:
8279
PACKAGE_NAME: ${{ matrix.pkg-name }}
80+
FREEZE_REQUIREMENTS: 1
8381
run: |
84-
pip install -e . -r requirements/app/devel.txt -U -q --find-links ${TORCH_URL}
82+
pip install -e .[dev] --upgrade --find-links ${TORCH_URL}
8583
pip list
8684
8785
- name: Setup Node.js
@@ -117,7 +115,10 @@ jobs:
117115
AWS_DEFAULT_REGION: us-east-1
118116
PYTEST_ARTIFACT: results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
119117
run: |
120-
coverage run --source ${COVERAGE_SCOPE} -m pytest -m "not cloud" tests_app --timeout=300 -vvvv --junitxml=$PYTEST_ARTIFACT --durations=50
118+
python -m coverage run --source ${COVERAGE_SCOPE} \
119+
-m pytest -m "not cloud" tests_app \
120+
--timeout=300 -vvvv --durations=50 \
121+
--junitxml=$PYTEST_ARTIFACT
121122
122123
- name: Upload pytest test results
123124
uses: actions/upload-artifact@v3

.github/workflows/ci-tests-lite.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ jobs:
110110
- name: Install package & dependencies
111111
env:
112112
PACKAGE_NAME: ${{ matrix.pkg-name }}
113+
FREEZE_REQUIREMENTS: 1
113114
run: |
114-
pip install -e . "pytest-timeout" -r requirements/lite/devel.txt --upgrade --find-links ${TORCH_URL}
115+
pip install -e .[test] "pytest-timeout" --upgrade --find-links ${TORCH_URL}
115116
pip list
116117
117118
- name: Adjust tests
@@ -133,7 +134,10 @@ jobs:
133134
- name: Testing Lite
134135
working-directory: tests/tests_lite
135136
# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003
136-
run: coverage run --source ${COVERAGE_SCOPE} -m pytest -v --timeout=30 --durations=50 --junitxml=results-${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.requires }}-${{ matrix.release }}.xml
137+
run: |
138+
python -m coverage run --source ${COVERAGE_SCOPE} \
139+
-m pytest -v --timeout=30 --durations=50 \
140+
--junitxml=results-${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.requires }}-${{ matrix.release }}.xml
137141
138142
- name: Upload pytest results
139143
if: failure()

.github/workflows/ci-tests-pytorch.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ jobs:
135135
- name: Install package & dependencies
136136
env:
137137
PACKAGE_NAME: ${{ matrix.pkg-name }}
138+
FREEZE_REQUIREMENTS: 1
138139
run: |
139-
pip install -e . "pytest-timeout" -r requirements/pytorch/devel.txt --upgrade --find-links ${TORCH_URL}
140+
pip install -e .[extra,test] "pytest-timeout" --upgrade --find-links ${TORCH_URL}
141+
# TODO: installing the strategies from file as deepspeed expects already installed PyTorch and extras do not install base first
142+
# pip install -r requirements/pytorch/strategies.txt --find-links ${TORCH_URL}
140143
pip list
141144
142145
- name: Reinstall Horovod if necessary
@@ -184,7 +187,12 @@ jobs:
184187
- name: Testing PyTorch
185188
working-directory: tests/tests_pytorch
186189
# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003
187-
run: coverage run --source ${COVERAGE_SCOPE} -m pytest -v --timeout=${TEST_TIMEOUT} --durations=50 --junitxml=results-${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.requires }}-${{ matrix.release }}.xml
190+
run: |
191+
python -m coverage run --source ${COVERAGE_SCOPE} \
192+
-m pytest . -v \
193+
--timeout=${TEST_TIMEOUT} --durations=50 \
194+
--reruns 3 --reruns-delay 1 \
195+
--junitxml=results-${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.requires }}-${{ matrix.release }}.xml
188196
189197
- name: Upload pytest results
190198
if: failure()

.github/workflows/docs-checks.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ concurrency:
2323
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
2424
cancel-in-progress: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
2525

26-
env:
27-
FREEZE_REQUIREMENTS: "1"
28-
2926
defaults:
3027
run:
3128
shell: bash
@@ -78,6 +75,8 @@ jobs:
7875
- name: Install LAI package
7976
# This is needed as App docs is heavily using/referring to lightning package
8077
if: ${{ matrix.pkg-name == 'app' }}
78+
env:
79+
FREEZE_REQUIREMENTS: 1
8180
run: |
8281
pip install -e . -U -v -f https://download.pytorch.org/whl/cpu/torch_stable.html -f pypi
8382
@@ -92,6 +91,7 @@ jobs:
9291
- name: Install this package
9392
env:
9493
PACKAGE_NAME: ${{ matrix.pkg-name }}
94+
FREEZE_REQUIREMENTS: 1
9595
run: |
9696
pip install -e .[extra,cloud,ui] -U -r requirements/${{ matrix.pkg-name }}/docs.txt -f pypi
9797
pip list
@@ -110,8 +110,6 @@ jobs:
110110
fail-fast: false
111111
matrix:
112112
pkg-name: ["app", "pytorch"]
113-
env:
114-
FREEZE_REQUIREMENTS: "1"
115113
steps:
116114
- uses: actions/checkout@v3
117115
with:
@@ -145,6 +143,7 @@ jobs:
145143
- name: Install package & dependencies
146144
env:
147145
PACKAGE_NAME: ${{ matrix.pkg-name }}
146+
FREEZE_REQUIREMENTS: 1
148147
run: |
149148
sudo apt-get update
150149
sudo apt-get install -y cmake pandoc texlive-latex-extra dvipng texlive-pictures

.github/workflows/docs-deploy.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ on:
88
- ".github/workflows/docs-deploy.yml"
99
# TODO: this workflow is just for debugging. extend the paths that should trigger it
1010

11-
env:
12-
FREEZE_REQUIREMENTS: 1
13-
1411
defaults:
1512
run:
1613
shell: bash
@@ -48,6 +45,8 @@ jobs:
4845
${{ runner.os }}-deploy-docs-pip-
4946
5047
- name: Install package & dependencies
48+
env:
49+
FREEZE_REQUIREMENTS: 1
5150
run: |
5251
sudo apt-get update
5352
sudo apt-get install -y cmake pandoc

src/lightning/__setup__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _prepare_extras() -> Dict[str, Any]:
3232
# From remote, use like `pip install pytorch-lightning[dev, docs]`
3333
# From local copy of repo, use like `pip install ".[dev, docs]"`
3434
req_files = [Path(p) for p in glob.glob(os.path.join(_PATH_REQUIREMENTS, "*", "*.txt"))]
35-
common_args = dict(unfreeze="major" if _FREEZE_REQUIREMENTS else "all")
35+
common_args = dict(unfreeze="none" if _FREEZE_REQUIREMENTS else "major")
3636
extras = {
3737
f"{p.parent.name}-{p.stem}": _ASSISTANT.load_requirements(file_name=p.name, path_dir=p.parent, **common_args)
3838
for p in req_files
@@ -41,12 +41,11 @@ def _prepare_extras() -> Dict[str, Any]:
4141
for extra in list(extras):
4242
name = "-".join(extra.split("-")[1:])
4343
extras[name] = extras.get(name, []) + extras[extra]
44-
# todo
45-
# extras["extra"] = extras["cloud"] + extras["ui"]
46-
# extras["dev"] = extras["extra"] + extras["test"] # + extras['docs']
47-
# extras["all"] = extras["dev"]
48-
extras = {name: list(set(reqs)) for name, reqs in extras.items()}
49-
print("The extras are", extras)
44+
extras["extra"] += extras["cloud"] + extras["ui"] + extras["components"]
45+
extras["all"] = extras["extra"]
46+
extras["dev"] = extras["all"] + extras["test"] # + extras['docs']
47+
extras = {name: sorted(set(reqs)) for name, reqs in extras.items()}
48+
print("The extras are: ", extras)
5049
return extras
5150

5251

@@ -84,7 +83,9 @@ def _setup_args() -> Dict[str, Any]:
8483
],
8584
},
8685
setup_requires=[],
87-
install_requires=_ASSISTANT.load_requirements(_PATH_REQUIREMENTS, unfreeze="all"),
86+
install_requires=_ASSISTANT.load_requirements(
87+
_PATH_REQUIREMENTS, unfreeze="none" if _FREEZE_REQUIREMENTS else "major"
88+
),
8889
extras_require=_prepare_extras(),
8990
project_urls={
9091
"Bug Tracker": "https://github.com/Lightning-AI/lightning/issues",

0 commit comments

Comments
 (0)