B
    d                 @   s  d dl mZmZmZ d dlZd dlZd dlZd dlZdddZdd	d
Z	e
dk rd dlZejddZejdddd ejdddd ejdddd eejdd ZeejejejdZedjejd ed xeD ]Zedjed qW ed dS )    )absolute_importdivisionprint_functionNcctbx_projectcctbx_versionc          	   C   sp  t jt jt jtdd| }t j|s>tdj|d|dkrd}d}d}d}d}	d}
ydt	j
ddg|dd	}|d
}t|dkrd}|d dd  }nt|d }	|d  }
W n t	jk
r   Y nX |syVt	j
ddddg|dd	}| d d
}t|d }t|d }t|d }W n2 t	jk
rj   t }|j}|j}|j}Y nX dj|||d}|	dk	r|
dk	r|dj|	|
d7 }n|d7 }t j||d }t|d}|| W dQ R X d}t j||d }t|d}||j| |d W dQ R X |dkr0d}t j|d}t|d}||j|d  W dQ R X |||fS )!a  
  Function for creating the files containing the version. This
  function is called by bootstrap.py after downloading the git
  repository. The development version is the date of the commit and
  the commit information from "git describe". Files containing an
  official release version can created by providing the version as an
  argument

  Parameters
  ----------
  git_repo: str
    The git repository to be versioned. This is the directory name in
    "modules" (e.g. cctbx_project)
  basename: str
    The basename for the filenames. It is also the name of the defintion
    in the C++ header. The ".txt" and ".h" extensions will be added to
    the filenames.
  version: str
    If set, this argument is used as the version
  setup_template: str
    A template for the setup.py file. There should be a {version} field.

  Returns
  -------
  filenames: str
    A tuple containing the three filenames. The first is the plain text
    file, the second is a C++ header file, and the last is a setup.py
    file. These files are located in the git repository. The plain text
    and header cab be copied to the build directory in libtbx_refresh.py.
  z..z$The {path} directory does not exist.)pathNFgitdescribe)cwdutf8-   Tr   logz-1z--pretty=%ci   z{y}.{m}.dev{d})ymdz+{n}.{h})nhz+unknownz.txtwz// {basename} version header
// This file is automatically generated

#ifndef {basename}_H
#define {basename}_H

#define {basename} "{version}"

#endif
z.h)basenameversiona  from setuptools import setup
setup(
    name='cctbx-base',
    version='{version}',
    url='https://github.com/cctbx/cctbx_project',
    description='The Computational Crystallography Toolbox (cctbx) is being developed as the open source component of the Phenix system. The goal of the Phenix project is to advance automation of macromolecular structure determination. Phenix depends on the cctbx, but not vice versa. This hierarchical approach enforces a clean design as a reusable library. The cctbx is therefore also useful for small-molecule crystallography and even general scientific applications.',
    author='CCTBX developers',
    author_email='cctbx@cci.lbl.gov',
    maintainer='CCTBX developers',
    maintainer_email='cctbx@cci.lbl.gov',
    license='BSD-3-Clause-LBNL AND BSD-3-Clause AND BSL-1.0 AND LGPL-2.0-only AND LGPL-2.1-only AND LGPL-3.0-only AND MIT AND LGPL-2.0-or-later WITH WxWindows-exception-3.1',
    packages=[],
)
zsetup.py)r   )osr   joindirnameabspath__file__isdirRuntimeErrorformat
subprocesscheck_outputdecodesplitlenstripintCalledProcessErrortime	localtimetm_yeartm_montm_mdayopenwriteupper)git_repor   r   Zsetup_templater   Ztaggedr   r   r   r   r   outputtZtxt_filenamefZheader_templateZ
h_filenameZsetup_filename r6   m/mnt/filia/a/genomebrowser/www/genomebrowser/fleming/tools/molprobity/modules/cctbx_project/libtbx/version.pycreate_version_files	   sb    !"

"
r8   cctbx_version.txtFc          	   C   s   ddl }d}| }tj|s2tjt|jj| }y$t|}|	 
 }W dQ R X W n tk
rr   |rndS Y nX |dkrt }dj|j|j|jd}|S )a  
  Function for returning the version of the current installation
  The file containing the version is manually created for official
  releases and created by bootstrap.py for development releases. The
  version follows calendar versioning, so in the event that the file
  cannot be read, a version based on the current date can be returned.

  Parameters
  ----------
  filename: str
    The filename of the file containing the version number. This can
    be a full path. Otherwise, the directory is assumed to be the build
    directory.
  fail_with_none: bool
    If set, any failure to read the version file will return None.
    Otherwise, the current date is used to generate the version.

  Returns
  -------
  str or None
  r   Nz{y}.{m}.dev{d}+unknown)r   r   r   )libtbx.load_envr   r   isabsr   absenv
build_pathr/   readr'   IOErrorr*   r+   r!   r,   r-   r.   )filenameZfail_with_nonelibtbxr   r   r5   r4   r6   r6   r7   get_version   s    

rC   __main__z<Command for generating files containing version information.)descriptionz
--git-repoz:The name of the git repository in the "modules" directory.)helpdefaultz
--basenamez(The base name for the version filenames.z	--versionzAn explicit version to be set.r   )r2   r   r   z;Writing files containing version information for {git_repo})r2   zO===============================================================================zWrote {filename})rA   )r   r   NN)r9   F)
__future__r   r   r   r   r"   sysr*   r8   rC   __name__argparseArgumentParserparseradd_argument
parse_argsargv	namespacer2   r   r   	filenamesprintr!   rA   r6   r6   r6   r7   <module>   sD    

+


