Skip to content

Commit e3587ed

Browse files
committed
Merge branch 'develop'
2 parents a8ae196 + 7707aa4 commit e3587ed

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

compare50/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
def _set_version():
2+
"""Set check50 __version__"""
3+
global __version__
4+
from pkg_resources import get_distribution, DistributionNotFound
5+
import os
6+
# https://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package
7+
try:
8+
dist = get_distribution("check50")
9+
# Normalize path for cross-OS compatibility.
10+
dist_loc = os.path.normcase(dist.location)
11+
here = os.path.normcase(__file__)
12+
if not here.startswith(os.path.join(dist_loc, "check50")):
13+
# This version is not installed, but another version is.
14+
raise DistributionNotFound
15+
except DistributionNotFound:
16+
__version__ = "locally installed, no version information available"
17+
else:
18+
__version__ = dist.version
19+
20+
21+
# Encapsulated inside a function so their local variables/imports aren't seen by autocompleters
22+
_set_version()
23+
124
from ._api import *
225
from ._data import *
326
from . import comparators, preprocessors, passes

compare50/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import lib50
1515
import termcolor
1616

17-
from . import comparators, _api, _data, _renderer
17+
from . import comparators, _api, _data, _renderer, __version__
1818

1919

2020
def excepthook(cls, exc, tb):
@@ -220,14 +220,15 @@ def main():
220220
metavar="MATCHES",
221221
type=int,
222222
help="number of matches to output")
223-
224223
parser.add_argument("--profile",
225224
action="store_true",
226225
help="profile compare50 (development only, requires line_profiler, implies debug)")
227-
228226
parser.add_argument("--debug",
229227
action="store_true",
230228
help="don't run anything in parallel, disable progress bar")
229+
parser.add_argument("-V", "--version",
230+
action="version",
231+
version=f"%(prog)s {__version__}")
231232

232233
args = parser.parse_args()
233234

0 commit comments

Comments
 (0)