Skip to content

Add abs paths to allow label-maker cli to work outside module dir #4

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

Merged
merged 4 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ jobs:
python test/verify-labels.py
label-maker package --dest integration --config test/fixtures/integration/config.integration.json
python test/verify-package.py

# Retest that `label-maker labels` works, but from outside the module directory
cd ~
label-maker labels --dest label-maker/integration --config label-maker/test/fixtures/integration/config.integration.json > stdout
cd ~/label-maker
python test/verify-labels.py
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include requirements.txt
include README.md
include label_maker/countries.txt
9 changes: 7 additions & 2 deletions label_maker/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from PIL import Image, ImageDraw
from tilepie import tilereduce

import label_maker
from label_maker.filter import create_filter

# declare a global accumulator so the workers will have access
Expand Down Expand Up @@ -61,9 +62,13 @@ def make_labels(dest_folder, zoom, country, classes, ml_type, bounding_box, **kw
print('Retiling QA Tiles to zoom level {} (takes a bit)'.format(zoom))
filtered_geo = op.join(dest_folder, '{}.geojson'.format(country))
ps = Popen(['tippecanoe-decode', '-c', '-f', mbtiles_file], stdout=PIPE)
run(['python', 'label_maker/stream_filter.py', json.dumps(bounding_box)], stdin=ps.stdout, stdout=open(filtered_geo, 'w'))
stream_filter_fpath = op.join(op.dirname(label_maker.__file__), 'stream_filter.py')
run(['python', stream_filter_fpath, json.dumps(bounding_box)],
stdin=ps.stdout, stdout=open(filtered_geo, 'w'))
ps.wait()
run(['tippecanoe', '--no-feature-limit', '--no-tile-size-limit', '-P', '-l', 'osm', '-f', '-z', str(zoom), '-Z', str(zoom), '-o', mbtiles_file_zoomed, filtered_geo])
run(['tippecanoe', '--no-feature-limit', '--no-tile-size-limit', '-P',
'-l', 'osm', '-f', '-z', str(zoom), '-Z', str(zoom), '-o',
mbtiles_file_zoomed, filtered_geo])

# Call tilereduce
print('Determining labels for each tile')
Expand Down
4 changes: 3 additions & 1 deletion label_maker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

logger = logging.getLogger(__name__)


def parse_args(args):
"""Create an argument parser with subcommands"""
desc = 'label_maker (v%s)' % __version__
dhf = argparse.ArgumentDefaultsHelpFormatter
parser = argparse.ArgumentParser(description=desc)

pparser = argparse.ArgumentParser(add_help=False)
pparser.add_argument('--version', help='Print version and exit', action='version', version=__version__)
pparser.add_argument('--version', help='Print version and exit',
action='version', version=__version__)
pparser.add_argument('--log', default=2, type=int,
help='0:all, 1:debug, 2:info, 3:warning, 4:error, 5:critical')
pparser.add_argument('-c', '--config', default='config.json', type=str,
Expand Down
6 changes: 5 additions & 1 deletion label_maker/validate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Expose a schema for use with cerberus for config validation"""
import os.path as op
import label_maker

countries = []
with open('label_maker/countries.txt') as f:
module_dir = op.dirname(label_maker.__file__) # Get module home directory

with open(op.join(module_dir, 'countries.txt')) as f:
lines = f.readlines()
for line in lines:
countries.append(line.strip())
Expand Down