Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile and distribute docs in sdist #4526

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ static-updates
# Python compiling
*.pyc
*.pyo

# Backup files
*~

# Sublime editor
*.sublime-*

# Ignore all .zip files!? No comment?? Needs fixing, I guess it's to avoid
# committing local assessment items.
*.zip

# Documentation
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ recursive-include static-libraries *
recursive-include data *

recursive-exclude python-packages *pyc

# Docs
recursive-include docs/_build/html *
82 changes: 82 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.PHONY: clean-pyc clean-build docs clean

help:
@echo "clean - remove all build, test, coverage and Python artifacts"
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "clean-test - remove test and coverage artifacts"
@echo "lint - check style with pep8"
@echo "test - run tests quickly with the default Python"
@echo "test-all - run tests on every Python version with tox DISABLED"
@echo "assets - build all JS/CSS assets"
@echo "coverage - check code coverage quickly with the default Python"
@echo "docs - generate Sphinx HTML documentation, including API docs"
@echo "release - package and upload a release"
@echo "dist - package locally"
@echo "install - install the package to the active Python's site-packages"

clean: clean-build clean-pyc clean-test

clean-build:
rm -fr build/

This comment was marked as spam.

This comment was marked as spam.

rm -fr dist/
rm -fr .eggs/
rm -fr dist-packages/
rm -fr dist-packages-temp/
find . -name '*.egg-info' -exec rm -fr {} +

This comment was marked as spam.

find . -name '*.egg' -exec rm -f {} +

clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean-test:
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/

lint:
pep8 kalite

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


test:
python setup.py test

test-all:
@echo "Not supported yet"
# tox

coverage:
coverage run --source kalite_gtk setup.py test

This comment was marked as spam.

coverage report -m
coverage html
open htmlcov/index.html

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


docs:
# rm -f docs/ka-lite.rst
# rm -f docs/modules.rst
# sphinx-apidoc -o docs/ ka-lite-gtk
$(MAKE) -C docs clean
$(MAKE) -C docs html
# open docs/_build/html/index.html

assets: clean
# Necessary because NPM may have wrong versions in the cache
npm cache clean
npm install --production
node build.js
bin/kalite manage compileymltojson

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


release: clean docs assets
python setup.py sdist --formats=gztar,zip upload --sign
python setup.py sdist --formats=gztar,zip upload --sign --static
ls -l dist

dist: clean docs assets
python setup.py sdist
python setup.py sdist --static
ls -l dist

install: clean
python setup.py install
10 changes: 9 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
[metadata]
description-file = README.md

# This is the one we use officially
[pep8]
ignore = E226,E302,E41,E402
max-line-length = 160
exclude = kalite/*/migrations/*

# Using flake8 is also supported..
[flake8]
# E124: closing bracket does not match indentation
# E702: semicolon at end of line; ignored because we have `from django.conf import settings; logging = settings.LOG` lines and others
ignore = E702,E124
max-line-length = 130
max-line-length = 160

52 changes: 33 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,26 @@ def get_installed_packages():
# site-packages directory.


def gen_data_files(*dirs):
def gen_data_files(*dirs, **kwargs):
"""
We can only link files, not directories. Therefore, we use an approach
that scans all files to pass them to the data_files kwarg for setup().
Thanks: http://stackoverflow.com/a/7288382/405682
"""
results = []

filter_illegal_extensions = lambda f: os.path.splitext(f)[1] != ".pyc"


optional = kwargs.pop('optional', False)

def filter_illegal_extensions(f):
return os.path.splitext(f)[1] != ".pyc"

for src_dir in dirs:
if not os.path.isdir(src_dir):
if optional:
continue
else:
raise RuntimeError("{dir:s} does not exist, cannot continue".format(dir=src_dir))

for root, dirs, files in os.walk(src_dir):
results.append(
(
Expand Down Expand Up @@ -162,6 +171,11 @@ def gen_data_files(*dirs):
gen_data_files('static-libraries')
)

data_files += map(
lambda x: (os.path.join(kalite.ROOT_DATA_PATH, x[0]), x[1]),
gen_data_files('docs/_build/html', optional=True)
)

This comment was marked as spam.

# For now, just disguise the kalitectl.py script here as it's only to be accessed
# with the bin/kalite proxy.
data_files += [(
Expand Down Expand Up @@ -228,37 +242,37 @@ def run(self):
# If it's a static build, we invoke pip to bundle dependencies in python-packages
# This would be the case for commands "bdist" and "sdist"
if STATIC_BUILD:

manifest_content = file(os.path.join(where_am_i, 'MANIFEST.in.dist'), 'r').read()
manifest_content += "\n" + "recursive-include dist-packages *\nrecursive-exclude dist-packages *pyc"
file(os.path.join(where_am_i, 'MANIFEST.in'), "w").write(manifest_content)

sys.stderr.write(
"This is a static build... invoking pip to put static dependencies in "
"dist-packages/\n"
)

STATIC_DIST_PACKAGES_DOWNLOAD_CACHE = os.path.join(where_am_i, 'dist-packages-downloads')
STATIC_DIST_PACKAGES_TEMP = os.path.join(where_am_i, 'dist-packages-temp')

# Create directory where dynamically created dependencies are put
if not os.path.exists(STATIC_DIST_PACKAGES_DOWNLOAD_CACHE):
os.mkdir(STATIC_DIST_PACKAGES_DOWNLOAD_CACHE)

# Should remove the temporary directory always
if os.path.exists(STATIC_DIST_PACKAGES_TEMP):
print("Removing previous temporary sources for pip {}".format(STATIC_DIST_PACKAGES_TEMP))
shutil.rmtree(STATIC_DIST_PACKAGES_TEMP)

# Install from pip

# Code modified from this example:
# http://threebean.org/blog/2011/06/06/installing-from-pip-inside-python-or-a-simple-pip-api/
import pip.commands.install

# Ensure we get output from pip
enable_log_to_stdout('pip.commands.install')

def install_distributions(distributions):
command = pip.commands.install.InstallCommand()
opts, ___ = command.parser.parse_args([])
Expand All @@ -273,17 +287,17 @@ def install_distributions(distributions):
command.run(opts, distributions)
# requirement_set.source_dir = STATIC_DIST_PACKAGES_TEMP
# requirement_set.install(opts)

# Install requirements into dist-packages
if DIST_BUILDING_COMMAND:
install_distributions(STATIC_REQUIREMENTS)

# Empty the requirements.txt file


# It's not a build command with --static or it's not a build command at all
else:

# If the dist-packages directory is non-empty
if os.listdir(STATIC_DIST_PACKAGES):
# If we are building something or running from the source
Expand All @@ -302,7 +316,7 @@ def install_distributions(distributions):
# everything in the requirements.txt file
DIST_REQUIREMENTS = []
DIST_NAME = 'ka-lite-static'

if "ka-lite" in get_installed_packages():
raise RuntimeError(
"Already installed ka-lite so cannot install ka-lite-static. "
Expand All @@ -314,7 +328,7 @@ def install_distributions(distributions):
"...or other possible installation mechanisms you may have "
"been using."
)

# No dist-packages/ and not building, so must be installing the dynamic
# version
elif not DIST_BUILDING_COMMAND:
Expand All @@ -335,7 +349,7 @@ def install_distributions(distributions):
manifest_content = file(os.path.join(where_am_i, 'MANIFEST.in.dist'), 'r').read()
manifest_content += "\n" + "recursive-include dist-packages *"
file(os.path.join(where_am_i, 'MANIFEST.in'), "w").write(manifest_content)


# All files from dist-packages are included if the directory exists
if os.listdir(STATIC_DIST_PACKAGES):
Expand Down