Skip to content

Commit

Permalink
fix comparing versions (#6434)
Browse files Browse the repository at this point in the history
* fix comparing versions

* chlog

* .

* ...

* datasets
  • Loading branch information
Borda authored Mar 23, 2021
1 parent 2064ece commit 8cd75a4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
# First run the same pipeline as Read-The-Docs
cd docs
make clean
make html --debug --jobs $(nproc) SPHINXOPTS="-W"
make html --debug --jobs $(nproc) SPHINXOPTS="-W --keep-going"
- name: Upload built docs
uses: actions/upload-artifact@v2
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed torch distributed not available in setup hook for DDP ([#6506](https://github.com/PyTorchLightning/pytorch-lightning/pull/6506))


- Fixed comparing required versions ([#6434](https://github.com/PyTorchLightning/pytorch-lightning/pull/6434))


## [1.2.4] - 2021-03-16

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ test: clean

docs: clean
pip install --quiet -r requirements/docs.txt
python -m sphinx -b html -W docs/source docs/build
python -m sphinx -b html -W --keep-going docs/source docs/build
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def package_list_from_file(file):
}
MOCK_PACKAGES = []
if SPHINX_MOCK_REQUIREMENTS:
MOCK_PACKAGES += ['fairscale']
# mock also base packages when we are on RTD since we don't install them there
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements', 'extra.txt'))
Expand Down
22 changes: 18 additions & 4 deletions pytorch_lightning/utilities/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""General utilities"""
import importlib
import operator
import platform
import sys
from distutils.version import LooseVersion
from importlib.util import find_spec

import torch
from pkg_resources import DistributionNotFound, get_distribution
from pkg_resources import DistributionNotFound


def _module_available(module_path: str) -> bool:
Expand All @@ -42,11 +43,24 @@ def _module_available(module_path: str) -> bool:


def _compare_version(package: str, op, version) -> bool:
"""
Compare package version with some requirements
>>> _compare_version("torch", operator.ge, "0.1")
True
"""
try:
pkg_version = LooseVersion(get_distribution(package).version)
return op(pkg_version, LooseVersion(version))
except DistributionNotFound:
pkg = importlib.import_module(package)
except (ModuleNotFoundError, DistributionNotFound):
return False
try:
pkg_version = LooseVersion(pkg.__version__)
except AttributeError:
return False
if not (hasattr(pkg_version, "vstring") and hasattr(pkg_version, "version")):
# this is mock by sphinx, so it shall return True ro generate all summaries
return True
return op(pkg_version, LooseVersion(version))


_IS_WINDOWS = platform.system() == "Windows"
Expand Down
1 change: 1 addition & 0 deletions requirements/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ torchtext>=0.5
# onnx>=1.7.0
onnxruntime>=1.3.0
hydra-core>=1.0
# todo: when switch to standard package stream, drop `fairscale` from hard mocked docs libs
https://github.com/PyTorchLightning/fairscale/archive/pl_1.2.0.zip

0 comments on commit 8cd75a4

Please sign in to comment.