Skip to content

Commit

Permalink
Merge pull request #22 from david-caro/move_to_autosemver
Browse files Browse the repository at this point in the history
packaging: moved to autosemver
  • Loading branch information
david-caro committed Oct 14, 2016
2 parents b2e2232 + 7308a19 commit b8261f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 124 deletions.
17 changes: 6 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@
from __future__ import print_function

import os
import subprocess
import sys

sys.path.insert(0, os.path.abspath('..')) # noqa
import setup as inspire_schemas_setup
from autosemver.packaging import get_changelog, get_current_version


if not os.path.exists('_build/html/_static'):
os.makedirs('_build/html/_static')

with open('_build/html/_static/CHANGELOG.txt', 'w') as changelog_fd:
subprocess.call(
[
'../scripts/version_manager.py', '..', 'changelog',
],
stdout=changelog_fd,
)
changelog_fd.write(get_changelog(
project_dir='..',
bugtracker_url='https://github.com/inspirehep/inspire-schemas/issues/',
))

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -88,7 +83,7 @@
# The short X.Y version.

# Get the version string. Cannot be done with import!
version = inspire_schemas_setup.get_version('..')
version = get_current_version(project_dir='..')

# The full version, including alpha/beta/rc tags.
release = version
Expand Down
2 changes: 1 addition & 1 deletion requirements-build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dulwich
autosemver
122 changes: 10 additions & 112 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,135 +24,33 @@

"""INSPIRE schemas and related tools bundle."""

import os
import subprocess

from setuptools import setup, find_packages

from autosemver.packaging import (
get_authors,
get_current_version,
get_changelog,
)

def check_output(args):
proc = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = proc.communicate()

if proc.returncode:
raise RuntimeError(
'Failed to run %s\nrc=%s\nstdout=\n%sstderr=%s' %
(args, proc.returncode, stdout, stderr)
)

return stdout.decode()


def get_version(project_dir=os.curdir):
"""
Retrieves the version of the package, from the PKG-INFO file or generates
it with the version script
Returns:
str: Version for the package
Raises:
RuntimeError: If the version could not be retrieved
"""
if (
'INSPIRE_SCHEMAS_VERSION' in os.environ and
os.environ['INSPIRE_SCHEMAS_VERSION']
):
return os.environ['INSPIRE_SCHEMAS_VERSION']

version = None
pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
version_manager = os.path.join(project_dir, 'scripts/version_manager.py')
if os.path.exists(pkg_info_file):
with open(pkg_info_file) as info_fd:
for line in info_fd.readlines():
if line.startswith('Version: '):
version = line.split(' ', 1)[-1]

elif os.path.exists(version_manager):
version = check_output(
[version_manager, project_dir, 'version']
).strip()

if version is None:
raise RuntimeError('Failed to get package version')

# py3 compatibility step
if not isinstance(version, str) and isinstance(version, bytes):
version = version.decode()

return version


def get_authors(project_dir=os.curdir):
"""
Retrieves the authors list, from the AUTHORS file (if in a package) or
generates it with the version script
Returns:
list(str): List of authors
Raises:
RuntimeError: If the authors could not be retrieved
"""
authors = set()
pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
authors_file = os.path.join(project_dir, 'AUTHORS')
version_manager = os.path.join(project_dir, 'scripts/version_manager.py')
if os.path.exists(pkg_info_file) and os.path.exists(authors_file):
with open(authors_file) as authors_fd:
authors = set(authors_fd.read().splitlines())

elif os.path.exists(version_manager):
authors = set(check_output(
[version_manager, project_dir, 'authors']
).strip().splitlines())

return authors


def get_changelog(project_dir=os.curdir):
"""
Retrieves the changelog, from the CHANGELOG file (if in a package) or
generates it with the version script
Returns:
str: changelog
Raises:
RuntimeError: If the changelog could not be retrieved
"""
changelog = ''
pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
changelog_file = os.path.join(project_dir, 'CHANGELOG')
version_manager = os.path.join(project_dir, 'scripts/version_manager.py')
if os.path.exists(pkg_info_file) and os.path.exists(changelog_file):
with open(changelog_file) as changelog_fd:
changelog = changelog_fd.read()

elif os.path.exists(version_manager):
changelog = check_output(
[version_manager, project_dir, 'changelog']
).strip()

return changelog

URL = 'https://github.com/inspirehep/inspire-schemas'

if __name__ == '__main__':
with open('AUTHORS', 'w') as authors_fd:
authors_fd.write('\n'.join(get_authors()))

with open('CHANGELOG', 'w') as changelog_fd:
changelog_fd.write(get_changelog())
changelog_fd.write(get_changelog(bugtracker_url=URL + '/issues/'))

setup(
author='CERN',
author_email='admin@inspirehep.net',
description='Inspire JSON schemas and utilities to use them.',
install_requires=['jsonschema'],
install_requires=['autosemver', 'jsonschema'],
license='GPLv2',
name='inspire-schemas',
package_data={'': ['*.json', 'CHANGELOG', 'AUTHORS']},
packages=find_packages(),
url='https://github.com/inspirehep/inspire-schemas',
version=get_version(),
url=URL,
version=get_current_version(project_name='inspire-schemas'),
zip_safe=False,
)

0 comments on commit b8261f4

Please sign in to comment.