Skip to content

Commit 9237ef7

Browse files
committed
version
Adds a version subcommand to print out the current version of the installed twarc. I put the version string in a separate module so it could be used by setup.py without pulling in all of twarc (which could fail due to missing dependencies) and also to avoid a circular dependency between twarc/__init__.py and twarc/client2.py
1 parent e8fb7ec commit 9237ef7

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import setuptools
33

4-
version = 'v2.0.0'
4+
from twarc.version import version
55

66
with open("docs/README.md") as f:
77
long_description = f.read()

twarc/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
__version__ = '2.0.0'
2-
1+
from .version import version
32
from .client import Twarc
43
from .client2 import Twarc2

twarc/command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import argparse
1212
import fileinput
1313

14-
from twarc import __version__
14+
from twarc.version import version
1515
from twarc.client import Twarc
1616
from twarc.json2csv import csv, get_headings, get_row
1717
from dateutil.parser import parse as parse_dt
@@ -73,7 +73,7 @@ def stop(signal, frame):
7373
signal.signal(signal.SIGINT, stop)
7474

7575
if command == "version":
76-
print("twarc v%s" % __version__)
76+
print("twarc v%s" % version)
7777
sys.exit()
7878
elif command == "help" or not command:
7979
parser.print_help()

twarc/command2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from click_plugins import with_plugins
1717
from pkg_resources import iter_entry_points
18+
19+
from twarc.version import version
1820
from twarc.handshake import handshake
1921
from twarc.decorators import cli_api_error
2022
from twarc.expansions import flatten as flat
@@ -124,6 +126,14 @@ def configure(ctx):
124126
ctx.exit()
125127

126128

129+
@twarc2.command('version')
130+
def get_version():
131+
"""
132+
Return the version of twarc that is installed.
133+
"""
134+
click.echo(f'twarc v{version}')
135+
136+
127137
@twarc2.command('search')
128138
@click.option('--since-id', type=int,
129139
help='Match tweets sent after tweet id')

twarc/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = '2.0.0'

0 commit comments

Comments
 (0)