Skip to content

Commit

Permalink
better versioning again
Browse files Browse the repository at this point in the history
  • Loading branch information
isnok committed Apr 10, 2016
1 parent a8b6bf1 commit 7959a73
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,8 @@ def import_file(name, path):
return module


def get_version():
""" Fallback & Test version function.
>>> get_version()
'no_version'
"""
return 'no_version'
# this will be overriden later
def get_version(): return 'no_version'


def setup_versioning():
Expand Down Expand Up @@ -299,12 +294,27 @@ class cmd_version_bump(Command):
#f_out.write(f_in.read())


# we override different commands for both environments
_sdist = _build_py = _upload = object

if "setuptools" in sys.modules:
from setuptools.command.build_py import build_py as _build_py
else:
from distutils.command.build_py import build_py as _build_py
def import_commands_to_override(oldschool=False):
""" Import the command classes to override either
from setuptools or distutils.
>>> import_commands_to_override()
>>> import_commands_to_override(True)
"""
global _sdist, _build_py, _upload
from distutils.command.upload import upload as _upload

if not oldschool and "setuptools" in sys.modules:
from setuptools.command.sdist import sdist as _sdist
from setuptools.command.build_py import build_py as _build_py
else:
from distutils.command.sdist import sdist as _sdist
from distutils.command.build_py import build_py as _build_py

import_commands_to_override()

class cmd_build_py(_build_py):
""" It seems as if build_py is executed when the distributed package is installed. """
Expand Down Expand Up @@ -344,11 +354,6 @@ class cmd_build_py(_build_py):
#cmds["build_exe"] = cmd_build_exe
#del cmds["build_py"]

# we override different "sdist" commands for both environments
if "setuptools" in sys.modules:
from setuptools.command.sdist import sdist as _sdist
else:
from distutils.command.sdist import sdist as _sdist

def add_to_sdist(self=None, base_dir=os.curdir, files=()):
""" The custom part of the sdist command.
Expand Down Expand Up @@ -381,7 +386,7 @@ def add_to_sdist(self=None, base_dir=os.curdir, files=()):
self_target = join(base_dir, basename(__file__))
print("== Updating: %s" % self_target)
try:
os.link(__file__, self_target)
os.path.exists(self_target) or os.link(__file__, self_target)
except OSError:
print("=== Could not add %s to sdist!" % basename(__file__))

Expand All @@ -399,8 +404,6 @@ class cmd_sdist(_sdist):
make_release_tree = add_to_sdist


from distutils.command.upload import upload as _upload

def protected_upload(self=None):
""" Allow only uploads with Python 3.
I experienced problems earlier, when i uploaded packages built
Expand Down

0 comments on commit 7959a73

Please sign in to comment.