3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

Generate __init__.py with package version on runtime

Closes #259. This removes world.version and replaces it with pylinkirc.__version__ where the former was used.
This commit is contained in:
James Lu 2016-07-03 00:26:03 -07:00
parent e63a1bc739
commit 72c48502c6
5 changed files with 24 additions and 19 deletions

View File

@ -17,7 +17,7 @@ import hashlib
from copy import deepcopy
import inspect
from . import world, utils, structures
from . import world, utils, structures, __version__
from .log import *
### Exceptions
@ -786,7 +786,7 @@ class Irc():
Returns a detailed version string including the PyLink daemon version,
the protocol module in use, and the server hostname.
"""
fullversion = 'PyLink-%s. %s :[protocol:%s]' % (world.version, self.serverdata['hostname'], self.protoname)
fullversion = 'PyLink-%s. %s :[protocol:%s]' % (__version__, self.serverdata['hostname'], self.protoname)
return fullversion
### State checking functions

View File

@ -1,7 +1,7 @@
# commands.py: base PyLink commands
from time import ctime
from pylinkirc import utils
from pylinkirc import utils, __version__, world
from pylinkirc.log import log
@utils.add_cmd
@ -112,7 +112,7 @@ def version(irc, source, args):
"""takes no arguments.
Returns the version of the currently running PyLink instance."""
irc.reply("PyLink version \x02%s\x02, released under the Mozilla Public License version 2.0." % world.version)
irc.reply("PyLink version \x02%s\x02, released under the Mozilla Public License version 2.0." % __version__)
irc.reply("The source of this program is available at \x02%s\x02." % world.source)
@utils.add_cmd

6
pylink
View File

@ -6,7 +6,7 @@ PyLink IRC Services launcher.
import os
import sys
try:
from pylinkirc import world, conf
from pylinkirc import world, conf, __version__
except ImportError:
sys.stderr.write("ERROR: Failed to import PyLink main module (pylinkirc.world).\n\nIf you are "
"running PyLink from source, please install PyLink first using 'python3 "
@ -23,7 +23,7 @@ if __name__ == '__main__':
args = parser.parse_args()
if args.version: # Display version and exit
print(world.version)
print('PyLink ' + __version__)
sys.exit()
# Load the config
@ -31,7 +31,7 @@ if __name__ == '__main__':
from pylinkirc.log import log
from pylinkirc import classes, utils, coremods
log.info('PyLink %s starting...', world.version)
log.info('PyLink %s starting...', __version__)
# Write a PID file unless specifically told not to.
if not args.no_pid:

View File

@ -2,8 +2,24 @@
from setuptools import setup, find_packages
from codecs import open
import subprocess
from os import path
# Get version from Git tags.
try:
version = subprocess.check_output(['git', 'describe', '--tags']).decode('utf-8').strip()
except Exception as e:
print('ERROR: Failed to get version from "git describe --tags": %s: %s' % (type(e).__name__, e))
from . import __version__ as fallback_version
print('Using fallback version of %r.' % fallback_version)
version = fallback_version
else:
# Success. Write the version to disk.
with open('__init__.py', 'w') as f:
f.write('# Automatically generated by setup.py\n')
f.write('__version__ = %r\n' % version)
curdir = path.abspath(path.dirname(__file__))
# FIXME: Convert markdown to RST
@ -12,7 +28,7 @@ with open(path.join(curdir, 'README.md'), encoding='utf-8') as f:
setup(
name='pylinkirc',
version='0.9.0-dev1',
version=version,
description='PyLink IRC Services',
long_description=long_description,

View File

@ -4,8 +4,6 @@ world.py: Stores global variables for PyLink, including lists of active IRC obje
from collections import defaultdict
import threading
import subprocess
import os
# This indicates whether we're running in tests modes. What it actually does
# though is control whether IRC connections should be threaded or not.
@ -20,13 +18,4 @@ services = {}
started = threading.Event()
version = "<unknown>"
source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!
# Only run this once.
if version == "<unknown>":
# Get version from Git tags.
try:
version = 'v' + subprocess.check_output(['git', 'describe', '--tags']).decode('utf-8').strip()
except Exception as e:
print('ERROR: Failed to get version from "git describe --tags": %s: %s' % (type(e).__name__, e))