mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 18:01:36 +00:00
move nearly everything into /src to make git.io/gam cleaner w/o a readme tree
This commit is contained in:
1
src/passlib/_setup/__init__.py
Normal file
1
src/passlib/_setup/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""passlib.setup - helpers used by passlib's setup.py script"""
|
||||
87
src/passlib/_setup/docdist.py
Normal file
87
src/passlib/_setup/docdist.py
Normal file
@@ -0,0 +1,87 @@
|
||||
"""custom command to build doc.zip file"""
|
||||
#=============================================================================
|
||||
# imports
|
||||
#=============================================================================
|
||||
# core
|
||||
import os
|
||||
from distutils import dir_util
|
||||
from distutils.cmd import Command
|
||||
from distutils.errors import *
|
||||
from distutils.spawn import spawn
|
||||
# local
|
||||
__all__ = [
|
||||
"docdist"
|
||||
]
|
||||
#=============================================================================
|
||||
# command
|
||||
#=============================================================================
|
||||
class docdist(Command):
|
||||
|
||||
description = "create zip file containing standalone html docs"
|
||||
|
||||
user_options = [
|
||||
('build-dir=', None, 'Build directory'),
|
||||
('dist-dir=', 'd',
|
||||
"directory to put the source distribution archive(s) in "
|
||||
"[default: dist]"),
|
||||
('format=', 'f',
|
||||
"archive format to create (tar, ztar, gztar, zip)"),
|
||||
('sign', 's', 'sign files using gpg'),
|
||||
('identity=', 'i', 'GPG identity used to sign files'),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
self.build_dir = None
|
||||
self.dist_dir = None
|
||||
self.format = None
|
||||
self.keep_temp = False
|
||||
self.sign = False
|
||||
self.identity = None
|
||||
|
||||
def finalize_options(self):
|
||||
if self.identity and not self.sign:
|
||||
raise DistutilsOptionError(
|
||||
"Must use --sign for --identity to have meaning"
|
||||
)
|
||||
if self.build_dir is None:
|
||||
cmd = self.get_finalized_command('build')
|
||||
self.build_dir = os.path.join(cmd.build_base, 'docdist')
|
||||
if not self.dist_dir:
|
||||
self.dist_dir = "dist"
|
||||
if not self.format:
|
||||
self.format = "zip"
|
||||
|
||||
def run(self):
|
||||
# call build sphinx to build docs
|
||||
self.run_command("build_sphinx")
|
||||
cmd = self.get_finalized_command("build_sphinx")
|
||||
source_dir = cmd.builder_target_dir
|
||||
|
||||
# copy to directory with appropriate name
|
||||
dist = self.distribution
|
||||
arc_name = "%s-docs-%s" % (dist.get_name(), dist.get_version())
|
||||
tmp_dir = os.path.join(self.build_dir, arc_name)
|
||||
if os.path.exists(tmp_dir):
|
||||
dir_util.remove_tree(tmp_dir, dry_run=self.dry_run)
|
||||
self.copy_tree(source_dir, tmp_dir, preserve_symlinks=True)
|
||||
|
||||
# make archive from dir
|
||||
arc_base = os.path.join(self.dist_dir, arc_name)
|
||||
self.arc_filename = self.make_archive(arc_base, self.format,
|
||||
self.build_dir)
|
||||
|
||||
# Sign if requested
|
||||
if self.sign:
|
||||
gpg_args = ["gpg", "--detach-sign", "-a", self.arc_filename]
|
||||
if self.identity:
|
||||
gpg_args[2:2] = ["--local-user", self.identity]
|
||||
spawn(gpg_args,
|
||||
dry_run=self.dry_run)
|
||||
|
||||
# cleanup
|
||||
if not self.keep_temp:
|
||||
dir_util.remove_tree(tmp_dir, dry_run=self.dry_run)
|
||||
|
||||
#=============================================================================
|
||||
# eof
|
||||
#=============================================================================
|
||||
57
src/passlib/_setup/stamp.py
Normal file
57
src/passlib/_setup/stamp.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""update version string during build"""
|
||||
#=============================================================================
|
||||
# imports
|
||||
#=============================================================================
|
||||
from __future__ import with_statement
|
||||
# core
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from distutils.dist import Distribution
|
||||
# pkg
|
||||
# local
|
||||
__all__ = [
|
||||
"stamp_source",
|
||||
"stamp_distutils_output",
|
||||
]
|
||||
#=============================================================================
|
||||
# helpers
|
||||
#=============================================================================
|
||||
def get_command_class(opts, name):
|
||||
return opts['cmdclass'].get(name) or Distribution().get_command_class(name)
|
||||
|
||||
def stamp_source(base_dir, version, dry_run=False):
|
||||
"""update version string in passlib dist"""
|
||||
path = os.path.join(base_dir, "passlib", "__init__.py")
|
||||
with open(path) as fh:
|
||||
input = fh.read()
|
||||
output, count = re.subn('(?m)^__version__\s*=.*$',
|
||||
'__version__ = ' + repr(version),
|
||||
input)
|
||||
assert count == 1, "failed to replace version string"
|
||||
if not dry_run:
|
||||
os.unlink(path) # sdist likes to use hardlinks
|
||||
with open(path, "w") as fh:
|
||||
fh.write(output)
|
||||
|
||||
def stamp_distutils_output(opts, version):
|
||||
|
||||
# subclass buildpy to update version string in source
|
||||
_build_py = get_command_class(opts, "build_py")
|
||||
class build_py(_build_py):
|
||||
def build_packages(self):
|
||||
_build_py.build_packages(self)
|
||||
stamp_source(self.build_lib, version, self.dry_run)
|
||||
opts['cmdclass']['build_py'] = build_py
|
||||
|
||||
# subclass sdist to do same thing
|
||||
_sdist = get_command_class(opts, "sdist")
|
||||
class sdist(_sdist):
|
||||
def make_release_tree(self, base_dir, files):
|
||||
_sdist.make_release_tree(self, base_dir, files)
|
||||
stamp_source(base_dir, version, self.dry_run)
|
||||
opts['cmdclass']['sdist'] = sdist
|
||||
|
||||
#=============================================================================
|
||||
# eof
|
||||
#=============================================================================
|
||||
Reference in New Issue
Block a user