Skip to content

Commit

Permalink
Provide mock 'dicom' import with helpful transition information (#585)
Browse files Browse the repository at this point in the history
* Provide mock 'dicom' import with helpful transition information

* pep-8 fix
  • Loading branch information
darcymason committed Mar 3, 2018
1 parent 898c0cf commit 1eb1da7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
11 changes: 11 additions & 0 deletions dicom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msg = """
Pydicom via 'import dicom' has been removed in pydicom version 1.0.
Please install the `dicom` package to restore function of code relying
on pydicom 0.9.9 or earlier. E.g. `pip install dicom`.
Alternatively, most code can easily be converted to pydicom > 1.0 by
changing import lines from 'import dicom' to 'import pydicom'.
See the Transition Guide at
https://pydicom.github.io/pydicom/stable/transition_to_pydicom1.html.
"""

raise ImportError(msg)
2 changes: 1 addition & 1 deletion pydicom/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Pure python package for DICOM medical file reading and writing."""
import re

__version__ = '1.0.1'
__version__ = '1.0.2'
__version_info__ = tuple(
re.match(r'(\d+\.\d+\.\d+).*', __version__).group(1).split('.'))
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.1
current_version = 1.0.2
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
Expand Down
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
from glob import glob
from setuptools import setup, find_packages

have_dicom = True
try:
import dicom
except ImportError:
have_dicom = False

# get __version__ from _version.py
base_dir = os.path.dirname(os.path.realpath(__file__))
ver_file = os.path.join(base_dir,'pydicom', '_version.py')
ver_file = os.path.join(base_dir, 'pydicom', '_version.py')
with open(ver_file) as f:
exec(f.read())

Expand All @@ -34,6 +40,9 @@

needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
pytest_runner = ['pytest-runner'] if needs_pytest else []
_py_modules = []
if not have_dicom:
_py_modules = ['dicom']

CLASSIFIERS = [
"License :: OSI Approved :: MIT License",
Expand Down Expand Up @@ -96,6 +105,7 @@ def data_files_inventory():
keywords=KEYWORDS,
classifiers=CLASSIFIERS,
packages=find_packages(),
py_modules=_py_modules,
package_data=PACKAGE_DATA,
include_package_data=True,
install_requires=REQUIRES,
Expand Down

0 comments on commit 1eb1da7

Please sign in to comment.