Skip to content

Commit

Permalink
Add "flit info --version" command
Browse files Browse the repository at this point in the history
References pypa#262
  • Loading branch information
exhuma committed May 1, 2019
1 parent a903073 commit c1d90d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions flit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def main(argv=None):
help="Prepare pyproject.toml for a new package"
)

parser_info = subparsers.add_parser('info',
help="Retrieve metadata information from the project",
)
parser_info.add_argument(
'--version', default=False, action='store_true', dest='show_version',
help="Print the version number of the project to stdout"
)

args = ap.parse_args(argv)

cf = args.ini_file
Expand All @@ -99,6 +107,11 @@ def main(argv=None):

log.debug("Parsed arguments %r", args)

if args.subcmd == 'info' and args.show_version:
from .info import get_version
print(get_version(args.ini_file))
sys.exit(0)

if args.logo:
from .logo import clogo
print(clogo.format(version=__version__))
Expand Down
20 changes: 20 additions & 0 deletions flit/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
This module contains code for the "info" subcommand
"""


def get_version(ini_path):
# type: (str) -> str
"""
This will return the package version as a string.
:param ini_path: The filename of the main config-file
(flit.ini/pyproject.toml)
"""
from . import inifile
from .common import Module, make_metadata
ini_info = inifile.read_pkg_ini(ini_path)
module = Module(ini_info['module'], ini_path.parent)
metadata = make_metadata(module, ini_info)
output = metadata.version
return output
9 changes: 9 additions & 0 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def test_flit_usage():
out, _ = p.communicate()
assert 'Build wheel' in out.decode('utf-8', 'replace')
assert p.poll() == 1

def test_flit_version():
import flit
version = flit.__version__

p = Popen([sys.executable, '-m', 'flit', 'info', '--version'],
stdout=PIPE, stderr=STDOUT)
out, _ = p.communicate()
assert out.decode('utf-8', 'replace').strip() == version

0 comments on commit c1d90d8

Please sign in to comment.