Skip to content

Commit 3024915

Browse files
committed
Prepare the releas of distribution.
1 parent aa7a66d commit 3024915

File tree

4 files changed

+80
-11
lines changed

4 files changed

+80
-11
lines changed

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include README.rst
2-
include docs/*.html
3-
2+
include LICENSE
3+
include version.txt
4+
recursive-include docs *

challenges/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from os.path import dirname, realpath
2-
3-
version_file = realpath(dirname(dirname(__file__))) + '/version.txt'
4-
with open(version_file) as f:
5-
__version__ = f.read().strip()

release.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import shutil
3+
4+
5+
def main():
6+
# pathes
7+
here = os.path.abspath(os.path.dirname(__file__))
8+
sphinx = os.path.join(here, 'sphinx/')
9+
docs = os.path.join(here, 'docs/')
10+
html_source = os.path.join(here, 'sphinx/_build/html/')
11+
html_target = os.path.join(here, 'docs/html/')
12+
epub_source = os.path.join(here, 'sphinx/_build/epub/')
13+
epub_target = os.path.join(here, 'docs/epub/')
14+
rst_challenges = os.path.join(sphinx, 'challenges.rst')
15+
rst_modules = os.path.join(sphinx, 'modules.rst')
16+
rst_hello = os.path.join(sphinx, 'HelloWorld.rst')
17+
18+
# commands
19+
genapi = 'sphinx-apidoc --doc-project="API" --force -o sphinx . setup.py ' \
20+
'release.py '
21+
genhtml = 'make html'
22+
genepub = 'make epub'
23+
24+
# execute
25+
if os.path.exists(docs):
26+
shutil.rmtree(docs)
27+
28+
if not os.path.exists(docs):
29+
os.makedirs(docs)
30+
31+
with cd(here):
32+
os.system(genapi)
33+
34+
with cd(sphinx):
35+
os.system(genhtml)
36+
37+
os.rename(html_source, html_target)
38+
39+
with cd(sphinx):
40+
os.system(genepub)
41+
42+
os.rename(epub_source, epub_target)
43+
44+
# cleanup autogenerated rst files
45+
os.remove(rst_challenges)
46+
os.remove(rst_hello)
47+
os.remove(rst_modules)
48+
49+
class cd:
50+
"""Context manager for changing the current working directory"""
51+
52+
def __init__(self, newPath):
53+
self.newPath = os.path.realpath(newPath)
54+
55+
def __enter__(self):
56+
self.savedPath = os.getcwd()
57+
os.chdir(self.newPath)
58+
59+
def __exit__(self, etype, value, traceback):
60+
os.chdir(self.savedPath)
61+
62+
if __name__ == '__main__':
63+
main()

setup.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
#!/usr/bin/env python3
22

3-
from os.path import dirname, realpath
4-
53
from setuptools import setup
4+
# To use a consistent encoding
5+
from codecs import open
6+
from os import path
67

7-
version_file = realpath(dirname(__file__)) + '/version.txt'
8+
here = path.abspath(path.dirname(__file__))
89

9-
with open(version_file) as f:
10+
# Read version from central version file
11+
with open(path.join(here, 'version.txt'), encoding='utf-8') as f:
1012
version = f.read().strip()
1113

14+
# Get the long description from the README file
15+
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
16+
long_description = f.read()
17+
1218
setup(
1319
name='challenges',
1420
version=version,
1521
description='Library to assist programming, testing and execution '
1622
+ 'of solutions for coding challenges like those on '
1723
'stepik.org',
24+
long_description=long_description,
25+
keywords='education stepik coursera bioinformatics challenges',
1826
url='https://github.com/elmar-hinz/Python.Challenges',
1927
author='Elmar Hinz',
2028
author_email='t3elmar@gmail.com',
2129
license='MIT',
2230
packages=['challenges', 'HelloWorld'],
31+
package_data={ 'HelloWorld': ['sample.txt', 'result.txt'], },
32+
include_package_data=True,
2333
entry_points={
2434
'console_scripts': [
2535
'challenge=challenges.main:main',

0 commit comments

Comments
 (0)