Skip to content

Commit bfbb01e

Browse files
committed
Add Python3 generation variants to makefile
1 parent e3fa8cf commit bfbb01e

2 files changed

Lines changed: 74 additions & 36 deletions

File tree

tools/do3

Lines changed: 0 additions & 35 deletions
This file was deleted.

tools/makefile

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ metaclean:
7272
rm -rf $(PYDIR)/phonenumbers/data $(PYDIR)/tests/testdata
7373
rm -rf $(PYDIR)/phonenumbers/geodata $(PYDIR)/tests/testgeodata
7474

75-
distclean: clean metaclean
75+
distclean: clean metaclean distclean3
7676
rm -rf $(PYDIR)/$(PACKAGE).egg-info
7777
rm -rf $(PYDIR)/build
7878
rm -f $(PYDIR)/DumpLocale.class
@@ -85,3 +85,76 @@ deb: $(PYDIR)/deb_dist/$(DEB_PACKAGE)_$(DEB_VERSION).deb
8585
deb_dist/$(DEB_PACKAGE)_$(VERSION)-1_all.deb: $(TARBALL)
8686
py2dsc $(TARBALL)
8787
cd $(PYDIR)/deb_dist/$(PACKAGE)-$(VERSION) && dpkg-buildpackage -us -uc -nc
88+
89+
#####################################################################################################
90+
# Python3 generation
91+
PYTHON3=python3
92+
PY3PACKAGE=phonenumbers3k
93+
PY3DIR=$(TOPDIR)/python3
94+
PYSRC=$(wildcard $(PYDIR)/*.py) $(wildcard $(PYDIR)/tests/*.py) $(wildcard $(PYDIR)/phonenumbers/*.py)
95+
PY3SRC=$(subst $(PYDIR),$(PY3DIR),$(PYSRC))
96+
python3: $(PY3SRC) all3data
97+
98+
$(PY3DIR):
99+
mkdir $@
100+
$(PY3DIR)/phonenumbers: | $(PY3DIR)
101+
mkdir $@
102+
$(PY3DIR)/phonenumbers/geodata: | $(PY3DIR)/phonenumbers
103+
mkdir $@
104+
$(PY3DIR)/tests: | $(PY3DIR)
105+
mkdir $@
106+
$(PY3DIR)/tests/testgeodata:
107+
mkdir $@
108+
109+
$(PY3DIR)/phonenumbers/%.py: $(PYDIR)/phonenumbers/%.py | $(PY3DIR)/phonenumbers
110+
cp $< $@
111+
2to3 --write --nobackups $@ > /dev/null 2>&1
112+
2to3 --write --doctests_only --nobackups $@ > /dev/null 2>&1
113+
$(PY3DIR)/tests/%.py: $(PYDIR)/tests/%.py | $(PY3DIR)/tests
114+
cp $< $@
115+
2to3 --write --nobackups $@ > /dev/null 2>&1
116+
$(PY3DIR)/%.py: $(PYDIR)/%.py | $(PY3DIR)
117+
cp $< $@
118+
2to3 --write --nobackups $@ > /dev/null 2>&1
119+
120+
# Python3 generation of .py files
121+
$(PY3DIR)/phonenumbers/geodata/locale.py: DumpLocale.class | $(PY3DIR)/phonenumbers/geodata
122+
java DumpLocale -python3 > $@
123+
locale3: $(PY3DIR)/phonenumbers/geodata/locale.py
124+
$(PY3DIR)/phonenumbers/geodata/__init__.py: buildgeocodingdata.py $(TOPDIR)/resources/geocoding | $(PY3DIR)/phonenumbers/geodata
125+
$(PYTHON3) buildgeocodingdata.py $(TOPDIR)/resources/geocoding $@
126+
$(PY3DIR)/tests/testgeodata/__init__.py: buildgeocodingdata.py $(TOPDIR)/resources/test/geocoding | $(PY3DIR)/tests/testgeodata
127+
$(PYTHON3) buildgeocodingdata.py $(TOPDIR)/resources/test/geocoding $@
128+
geo3data: $(PY3DIR)/phonenumbers/geodata/__init__.py $(PY3DIR)/tests/testgeodata/__init__.py
129+
130+
$(PY3DIR)/phonenumbers/data/__init__.py: $(TOPDIR)/resources/PhoneNumberMetaData.xml $(TOPDIR)/resources/PhoneNumberAlternateFormats.xml buildmetadatafromxml.py
131+
$(PYTHON3) buildmetadatafromxml.py --alt $(TOPDIR)/resources/PhoneNumberAlternateFormats.xml $(TOPDIR)/resources/PhoneNumberMetaData.xml $(PY3DIR)/phonenumbers/data .
132+
$(PY3DIR)/tests/testdata/__init__.py: $(TOPDIR)/resources/PhoneNumberMetaDataForTesting.xml buildmetadatafromxml.py
133+
$(PYTHON3) buildmetadatafromxml.py $(TOPDIR)/resources/PhoneNumberMetaDataForTesting.xml $(PY3DIR)/tests/testdata phonenumbers
134+
meta3data: $(PY3DIR)/phonenumbers/data/__init__.py $(PY3DIR)/tests/testdata/__init__.py geo3data
135+
136+
all3data: meta3data geo3data locale3
137+
138+
test3: all3data
139+
cd $(PY3DIR) && $(PYTHON3) -m testwrapper
140+
141+
# Packaging
142+
TARBALL3=$(PY3DIR)/dist/$(PY3PACKAGE)-$(VERSION).tar.gz
143+
# Build setuptools packaged tarball $(TARBALL)
144+
sdist3: all3data
145+
cd $(PY3DIR) && $(PYTHON3) setup.py sdist
146+
$(TARBALL3): sdist3
147+
148+
clean3:
149+
rm -rf $(PY3DIR)/MANIFEST $(PY3DIR)/__pycache__
150+
rm -rf $(PY3DIR)/phonenumbers/__pycache__ $(PY3DIR)/phonenumbers/data/__pycache__ $(PY3DIR)/phonenumbers/geodata/__pycache__
151+
rm -rf $(PY3DIR)/tests/__pycache__ $(PY3DIR)/tests/testdata/__pycache__ $(PY3DIR)/tests/testgeodata/__pycache__
152+
rm -rf $(PY3DIR)/build $(PY3DIR)/deb_dist $(PY3DIR)/dist
153+
154+
metaclean3:
155+
rm -rf $(PY3DIR)/phonenumbers/data $(PY3DIR)/tests/testdata
156+
rm -rf $(PY3DIR)/phonenumbers/geodata $(PY3DIR)/tests/testgeodata
157+
158+
distclean3: clean3 metaclean3
159+
rm -rf $(PY3DIR)
160+

0 commit comments

Comments
 (0)