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

(cherry picked from commit 8cd75a4)
  • Loading branch information
Borda committed Mar 23, 2021
1 parent 717ea43 commit fa6b3be
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 @@ -144,6 +144,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed a bug where `all_gather` would not work correctly with `tpu_cores=8` ([#6587](https://github.com/PyTorchLightning/pytorch-lightning/pull/6587))


- 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,13 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""General utilities"""
import importlib
import operator
import platform
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 @@ -41,11 +42,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 fa6b3be

Please sign in to comment.