Skip to content

Commit c9ec0ad

Browse files
committed
Remove duplicated version and author information
The information is now canonically stored in pyproject.toml. It's also worth mentioning that I removed the _version_check() function because its goal was only to catch misuse of the old `setup.py` "editable" mode, which we basically don't use anymore for development. We now simply reinstall the package after making changes, which takes about 2 seconds.
1 parent 48126d4 commit c9ec0ad

File tree

5 files changed

+24
-47
lines changed

5 files changed

+24
-47
lines changed

docs/conf.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
# serve to show the default.
1313

1414
import datetime
15-
import sys
15+
import email
16+
import importlib.metadata
1617
import os
18+
import sys
1719

1820
# When we build in readthedocs, we can't have this package.
1921
use_bootstrap = True
@@ -32,6 +34,8 @@
3234

3335
project = "LNT"
3436
project_module = lnt
37+
metadata = importlib.metadata.metadata('LNT')
38+
author = email.utils.parseaddr(metadata['Author-email'])[0]
3539

3640
# -- General configuration -----------------------------------------------------
3741

@@ -55,17 +59,16 @@
5559
master_doc = 'contents'
5660

5761
# General information about the project.
58-
copyright = u'%s, %s' % (datetime.datetime.now().year,
59-
project_module.__author__)
62+
copyright = f"{datetime.datetime.now().year}, {author}"
6063

6164
# The version info for the project you're documenting, acts as replacement for
6265
# |version| and |release|, also used in various other places throughout the
6366
# built documents.
6467
#
6568
# The short X.Y version.
66-
version = project_module.__version__
69+
version = importlib.metadata.version(project)
6770
# The full version, including alpha/beta/rc tags.
68-
release = project_module.__version__
71+
release = importlib.metadata.version(project)
6972

7073
# The language for content autogenerated by Sphinx. Refer to documentation
7174
# for a list of supported languages.
@@ -149,7 +152,7 @@
149152
# Global TOC depth for "site" navbar tab. (Default: 1)
150153
# Switching to -1 shows all levels.
151154
'globaltoc_depth': 2,
152-
155+
153156
# Render the next and previous page links in navbar. (Default: true)
154157
'navbar_sidebarrel': True,
155158

@@ -158,7 +161,7 @@
158161

159162
# Tab name for the current pages TOC. (Default: "Page")
160163
'navbar_pagenav_name': "Page",
161-
164+
162165
# HTML navbar class (Default: "navbar") to attach to <div> element.
163166
# For black navbar, do "navbar navbar-inverse"
164167
'navbar_class': "navbar navbar-inverse",
@@ -169,12 +172,12 @@
169172
# Choose Bootstrap version.
170173
# Values: "3" (default) or "2" (in quotes)
171174
'bootstrap_version': "3",
172-
175+
173176
}
174177

175178
if use_bootstrap:
176179
html_theme_options.update(bootstrap_options)
177-
180+
178181
# Theme options are theme-specific and customize the look and feel of a theme
179182
# further. For a list of options available for each theme, see the
180183
# documentation.
@@ -246,7 +249,7 @@
246249
#html_file_suffix = ''
247250

248251
# Output file base name for HTML help builder.
249-
htmlhelp_basename = '%sdoc' % project
252+
htmlhelp_basename = f"{project}doc"
250253

251254

252255
# -- Options for LaTeX output --------------------------------------------------
@@ -260,8 +263,7 @@
260263
# Grouping the document tree into LaTeX files. List of tuples
261264
# (source start file, target name, title, author, documentclass [howto/manual]).
262265
latex_documents = [
263-
('contents', '%s.tex' % project, u'%s Documentation' % project,
264-
project_module.__author__, 'manual'),
266+
('contents', f"{project}.tex", f"{project} Documentation", author, 'manual'),
265267
]
266268

267269
# The name of an image file (relative to this directory) to place at the top of

lnt/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
__author__ = 'Daniel Dunbar'
2-
__email__ = '[email protected]'
3-
__versioninfo__ = (0, 4, 2)
4-
__version__ = '.'.join(map(str, __versioninfo__)) + '.dev0'
5-
61
__all__ = []

lnt/lnttool/main.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -457,34 +457,13 @@ def command_code_for_function(input, fn):
457457
list(profile.Profile.fromFile(input).getCodeForFunction(fn))))
458458

459459

460-
def _version_check():
461-
"""
462-
Check that the installed version of the LNT is up-to-date with the running
463-
package.
464-
465-
This check is used to force users of distribute's develop mode to reinstall
466-
when the version number changes (which may involve changing package
467-
requirements).
468-
"""
469-
import importlib.metadata
470-
import lnt
471-
472-
# Get the current distribution.
473-
meta = importlib.metadata.metadata("LNT")
474-
if meta['Name'].lower() != lnt.__name__ or meta['Version'] != lnt.__version__:
475-
installed = "{} {}".format(meta['Name'], meta['Version'])
476-
current = "{} {}".format(lnt.__name__, lnt.__version__)
477-
raise SystemExit(f"""\
478-
error: installed distribution {installed} is not current ({current}), you may need to reinstall LNT""")
479-
480-
481460
def show_version(ctx, param, value):
482-
"""print LNT version"""
483-
import lnt
461+
"""print the LNT version"""
484462
if not value or ctx.resilient_parsing:
485463
return
486-
if lnt.__version__:
487-
print("LNT %s" % (lnt.__version__, ))
464+
import importlib
465+
version = importlib.metadata.version('LNT')
466+
print(f"LNT {version}")
488467
ctx.exit()
489468

490469

@@ -497,7 +476,7 @@ def main():
497476
\b
498477
Use ``lnt <command> --help`` for more information on a specific command.
499478
"""
500-
_version_check()
479+
pass
501480

502481

503482
main.add_command(action_check_no_errors)

lnt/server/db/testsuite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Database models for the TestSuites abstraction.
33
"""
44

5+
import importlib.metadata
56
import json
6-
import lnt
77
from . import util
88

99
import sqlalchemy
@@ -133,8 +133,8 @@ class TestSuite(Base):
133133
def __init__(self, name, db_key_name):
134134
self.name = name
135135
self.db_key_name = db_key_name
136-
self.version = "%d.%d" % (lnt.__versioninfo__[0],
137-
lnt.__versioninfo__[1])
136+
(major, minor, *_) = importlib.metadata.version('LNT').split('.')
137+
self.version = f"{major}.{minor}"
138138

139139
def __repr__(self):
140140
return '%s%r' % (self.__class__.__name__, (self.name, self.db_key_name,

lnt/server/ui/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
import io
23
import logging
34
import logging.handlers
@@ -216,7 +217,7 @@ def __init__(self, name):
216217
self.request_class = Request
217218

218219
# Store a few global things we want available to templates.
219-
self.version = lnt.__version__
220+
self.version = importlib.metadata.version('LNT')
220221

221222
# Inject a fix for missing slashes on the root URL (see Flask issue
222223
# #169).

0 commit comments

Comments
 (0)