PIP packaging with setup.py, and fixes for bugs revealed by this.

This commit is contained in:
Jonathan Piacenti 2015-01-14 17:21:15 -06:00
parent 42e7d9164e
commit 265f8a4e30
52 changed files with 92 additions and 37 deletions

View File

@ -1 +0,0 @@
Beta-GIT

View File

@ -15,7 +15,7 @@ import signal
import shutil
import importlib
from argparse import ArgumentParser
from subprocess import Popen, check_output, call
from subprocess import Popen, check_output, call, CalledProcessError, STDOUT
import django
# Signal processing
@ -24,9 +24,11 @@ SIG = signal.SIGINT
# Set up the main python paths to Evennia
EVENNIA_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EVENNIA_BIN = os.path.join(EVENNIA_ROOT, "bin")
EVENNIA_LIB = os.path.join(EVENNIA_ROOT, "evennia")
import evennia
EVENNIA_LIB = os.path.join(os.path.dirname(os.path.abspath(evennia.__file__)))
EVENNIA_RUNNER = os.path.join(EVENNIA_BIN, "evennia_runner.py")
EVENNIA_TEMPLATE = os.path.join(EVENNIA_ROOT, "game_template")
EVENNIA_TEMPLATE = os.path.join(EVENNIA_ROOT, "share", "evennia", "game_template")
EVENNIA_BINTESTING = os.path.join(EVENNIA_BIN, "testing")
EVENNIA_DUMMYRUNNER = os.path.join(EVENNIA_BINTESTING, "dummyrunner.py")
@ -299,11 +301,14 @@ def evennia_version():
Get the Evennia version info from the main package.
"""
version = "Unknown"
with open(os.path.join(EVENNIA_ROOT, "VERSION.txt"), 'r') as f:
version = f.read().strip()
try:
version = "%s (rev %s)" % (version, check_output("git rev-parse --short HEAD", shell=True, cwd=EVENNIA_ROOT).strip())
except IOError:
import evennia
version = evennia.__version__
except ImportError:
pass
try:
version = "%s (rev %s)" % (version, check_output("git rev-parse --short HEAD", shell=True, cwd=EVENNIA_ROOT, stderr=STDOUT).strip())
except (IOError, CalledProcessError):
pass
return version

View File

@ -19,6 +19,7 @@ import sys
from argparse import ArgumentParser
from subprocess import Popen
import Queue, thread
import evennia
try:
# check if launched with pypy
@ -31,7 +32,7 @@ PORTAL = None
EVENNIA_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EVENNIA_BIN = os.path.join(EVENNIA_ROOT, "bin")
EVENNIA_LIB = os.path.join(EVENNIA_ROOT, "evennia")
EVENNIA_LIB = os.path.dirname(evennia.__file__)
SERVER_PY_FILE = os.path.join(EVENNIA_LIB,'server', 'server.py')
PORTAL_PY_FILE = os.path.join(EVENNIA_LIB, 'server', 'portal', 'portal.py')

1
evennia/VERSION.txt Normal file
View File

@ -0,0 +1 @@
0.5.0

View File

@ -15,6 +15,7 @@ See www.evennia.com for full documentation.
# Delayed loading of properties
# Typeclasses
DefaultPlayer = None
DefaultGuest = None
DefaultObject = None
@ -61,13 +62,21 @@ spawn = None
managers = None
import os
from subprocess import check_output, CalledProcessError, STDOUT
__version__ = "Unknown"
root = os.path.dirname(os.path.abspath(__file__))
try:
__version__ = "Evennia"
with os.path.join(open(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "VERSION.txt", 'r') as f:
__version__ += " %s" % f.read().strip()
except IOError:
__version__ += " (unknown version)"
del os
with open(os.path.join(root, "VERSION.txt"), 'r') as f:
__version__ = f.read().strip()
except IOError as err:
print err
try:
__version__ = "%s" % (check_output("git rev-parse --short HEAD", shell=True, cwd=root, stderr=STDOUT).strip())
except (IOError, CalledProcessError):
pass
def init():
"""

View File

@ -242,7 +242,7 @@ class CmdBatchCommands(MuxCommand):
except UnicodeDecodeError, err:
caller.msg(_UTF8_ERROR % (python_path, err))
return
except IOError:
except IOError as err:
string = "'%s' not found.\nYou have to supply the python path "
string += "of the file relative to \none of your batch-file directories (%s)."
caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))

View File

@ -90,7 +90,7 @@ It seems the bottom of the box is a bit loose.
# close the @drop command since it's the end of the file)
-------------------------
An example batch file is contribs/examples/batch_example.ev.
An example batch file is contrib/examples/batch_example.ev.
==========================================================================

View File

@ -306,25 +306,8 @@ def host_os_is(osname):
def get_evennia_version():
"""
Get the Evennia version info from the main package.
"""
version = "Unknown"
with open(os.path.join(settings.ROOT_DIR, "VERSION.txt"), 'r') as f:
version = f.read().strip()
try:
version = "%s (rev %s)" % (version, check_output("git rev-parse --short HEAD", shell=True, cwd=settings.ROOT_DIR).strip())
except IOError:
pass
return version
"""
Check for the evennia version info.
"""
try:
f = open(settings.ROOT_DIR + os.sep + "VERSION.txt", 'r')
return "%s-%s" % (f.read().strip(), os.popen("git rev-parse --short HEAD").read().strip())
except IOError:
return "Unknown version"
import evennia
return evennia.__version__
def pypath_to_realpath(python_path, file_ending='.py'):
@ -343,7 +326,7 @@ def pypath_to_realpath(python_path, file_ending='.py'):
pathsplit = pathsplit[:-1]
if not pathsplit:
return python_path
path = settings.ROOT_DIR
path = settings.EVENNIA_DIR
for directory in pathsplit:
path = os.path.join(path, directory)
if file_ending:

57
setup.py Normal file
View File

@ -0,0 +1,57 @@
import os
from setuptools import setup, find_packages
os.chdir(os.path.dirname(os.path.realpath(__file__)))
def get_requirements():
req_lines = open('requirements.txt', 'r').readlines()
reqs = []
for line in req_lines:
line = line.strip()
if line and not line.startswith('#'):
reqs.append(line)
return reqs
VERSION_PATH = os.path.join('evennia', 'VERSION.txt')
def get_version():
return open(VERSION_PATH).read().strip()
def package_data():
file_set = []
for root, dirs, files in os.walk('evennia'):
for f in files:
file_name = os.path.relpath(os.path.join(root, f), 'evennia')
file_set.append(file_name)
return file_set
def template_data():
"""
Finds all of the static and template dirs in the project and adds
them to the package data.
By default setup.py only installs Python modules.
"""
data = []
for dirname, _, files in os.walk("game_template"):
for root, ___, current_files in os.walk(dirname):
for f in current_files:
file_name = os.path.join(root, f)
data.append((os.path.join('share', 'evennia', root), [file_name]))
return data
setup(
name='evennia',
version=get_version(),
description='A full-featured MUD building toolkit.',
packages=find_packages(exclude=['game_template', 'game_template.*']),
scripts=['bin/evennia', 'bin/evennia_runner.py'],
install_requires=get_requirements(),
package_data={'': package_data()},
data_files=template_data(),
zip_safe=False
)