Skip to content

Commit a2caaf4

Browse files
danieledlerAnton Eriksson
authored andcommitted
feat(python): Add meta info to infomap package
Adds infomap.__version__ Fixes #63 BREAKING CHANGE: Drop support for python 2
1 parent f61692c commit a2caaf4

File tree

8 files changed

+280
-378
lines changed

8 files changed

+280
-378
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ node_modules
4141
dist
4242
interfaces/js/src/worker
4343
docs/.*
44+
interfaces/python/package_meta.py

Makefile

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -145,94 +145,74 @@ SWIG_FILES := $(shell find interfaces/swig -name "*.i")
145145
##################################################
146146

147147
PY_BUILD_DIR = build/py
148-
PY2_BUILD_DIR = build/py2
149148
PY_ONLY_HEADERS := $(HEADERS:%.h=$(PY_BUILD_DIR)/headers/%.h)
150149
PY_HEADERS := $(HEADERS:src/%.h=$(PY_BUILD_DIR)/src/%.h)
151150
PY_SOURCES := $(SOURCES:src/%.cpp=$(PY_BUILD_DIR)/src/%.cpp)
152-
PY2_HEADERS := $(HEADERS:src/%.h=$(PY2_BUILD_DIR)/src/%.h)
153-
PY2_SOURCES := $(SOURCES:src/%.cpp=$(PY2_BUILD_DIR)/src/%.cpp)
154151

155-
.PHONY: python2 python py2-build py-build
152+
.PHONY: python py-build
156153

157154
# Use python distutils to compile the module
158155
python: py-build Makefile
159156
@cp -a interfaces/python/setup.py $(PY_BUILD_DIR)/
157+
python utils/create-python-package-meta.py
158+
@cp -a interfaces/python/package_meta.py $(PY_BUILD_DIR)/
159+
@touch $(PY_BUILD_DIR)/__init__.py
160+
@cp -a $(PY_BUILD_DIR)/infomap.py $(PY_BUILD_DIR)/infomap_package.py
161+
cat $(PY_BUILD_DIR)/package_meta.py $(PY_BUILD_DIR)/infomap_api.py interfaces/python/infomap_cli.py > $(PY_BUILD_DIR)/infomap.py
162+
@cp -a interfaces/python/MANIFEST.in $(PY_BUILD_DIR)/
163+
@cp -a README.md $(PY_BUILD_DIR)/
164+
@cp -a LICENSE_AGPLv3.txt $(PY_BUILD_DIR)/LICENSE
160165
cd $(PY_BUILD_DIR) && CC=$(CXX) python3 setup.py build_ext --inplace
161166
@true
162167

163-
python2: py2-build Makefile
164-
@cp -a interfaces/python/setup.py $(PY2_BUILD_DIR)/
165-
cd $(PY2_BUILD_DIR) && CC=$(CXX) python setup.py build_ext --inplace
166-
@true
167-
168168
# Generate wrapper files from source and interface files
169169
py-build: $(PY_HEADERS) $(PY_SOURCES) $(PY_ONLY_HEADERS) interfaces/python/infomap.py
170170
@mkdir -p $(PY_BUILD_DIR)
171171
@cp -a $(SWIG_FILES) $(PY_BUILD_DIR)/
172172
swig -c++ -python -outdir $(PY_BUILD_DIR) -o $(PY_BUILD_DIR)/infomap_wrap.cpp $(PY_BUILD_DIR)/Infomap.i
173-
174-
py2-build: $(PY2_HEADERS) $(PY2_SOURCES)
175-
@mkdir -p $(PY2_BUILD_DIR)
176-
@cp -a $(SWIG_FILES) $(PY2_BUILD_DIR)/
177-
swig -c++ -python -outdir $(PY2_BUILD_DIR) -o $(PY2_BUILD_DIR)/infomap_wrap.cpp $(PY2_BUILD_DIR)/Infomap.i
173+
@cp -a $(PY_BUILD_DIR)/infomap.py $(PY_BUILD_DIR)/infomap_api.py
178174

179175
# Rule for $(PY_HEADERS) and $(PY_SOURCES)
180176
$(PY_BUILD_DIR)/src/%: src/%
181177
@mkdir -p $(dir $@)
182178
@cp -a $^ $@
183179

184-
$(PY2_BUILD_DIR)/src/%: src/%
185-
@mkdir -p $(dir $@)
186-
@cp -a $^ $@
187-
188180
$(PY_BUILD_DIR)/headers/%: %
189181
@mkdir -p $(dir $@)
190182
@cp -a $^ $@
191183

192-
.PHONY: py-doc py-doc-prepare
184+
.PHONY: py-doc py-local-install
193185
SPHINX_SOURCE_DIR = interfaces/python/source
194186
SPHINX_TARGET_DIR = docs
195187

196-
py-doc-prepare:
188+
py-local-install:
197189
# Run this to get 'import infomap' to always import the latest
198190
# locally built version, so no need to run this multiple times.
199191
pip install -e $(PY_BUILD_DIR)
200192

201193
py-doc: python
202194
# Uses docstrings from the infomap available with 'import infomap'.
203-
# Run py-doc-prepare if you don't have pip installed it with -e
195+
# Run py-local-install if you don't have pip installed it with -e
204196
# and don't have the latest version installed
205197
@mkdir -p $(SPHINX_TARGET_DIR)
206198
@touch $(SPHINX_TARGET_DIR)/.nojekyll
207199
sphinx-build -b html $(SPHINX_SOURCE_DIR) $(SPHINX_TARGET_DIR)
208200

209-
.PHONY: pypi_prepare pypitest_publish pypi_publish
210-
PYPI_DIR = $(PY_BUILD_DIR)/pypi/infomap
201+
.PHONY: pypitest_publish pypi_publish
202+
PYPI_DIR = $(PY_BUILD_DIR)
211203
PYPI_SDIST = $(shell find $(PYPI_DIR) -name "*.tar.gz" 2>/dev/null)
212204

213-
pypi_prepare: py-build Makefile
214-
@mkdir -p $(PYPI_DIR)
215-
$(RM) -r $(PYPI_DIR)/dist $(PYPI_DIR)/infomap.egg-info
216-
cat $(PY_BUILD_DIR)/infomap.py interfaces/python/infomap_cli.py > $(PYPI_DIR)/infomap.py
217-
@cp -a $(PY_BUILD_DIR)/infomap_wrap.cpp $(PYPI_DIR)/
218-
@cp -a $(PY_BUILD_DIR)/src $(PYPI_DIR)/
219-
@cp -a $(PY_BUILD_DIR)/headers $(PYPI_DIR)/
220-
@cp -a interfaces/python/setup_pypi.py $(PYPI_DIR)/setup.py
221-
@cp -a interfaces/python/MANIFEST.in $(PYPI_DIR)/
222-
@cp -a README.md $(PYPI_DIR)/
223-
@cp -a LICENSE_AGPLv3.txt $(PYPI_DIR)/LICENSE
224-
225-
pypi_dist: pypi_prepare
226-
cd $(PYPI_DIR) && python setup.py sdist bdist_wheel
205+
pypi_dist: python
206+
cd $(PY_BUILD_DIR) && python setup.py sdist bdist_wheel
227207

228208
# pip -vvv --no-cache-dir install --upgrade -I --index-url https://test.pypi.org/simple/ infomap
229209
# pip install -e build/py/pypi/infomap/
230-
pypitest_publish:
210+
pypitest_publish: pypi_dist
231211
# cd $(PYPI_DIR) && python setup.py sdist upload -r testpypi
232212
@[ "${PYPI_SDIST}" ] && echo "Publish dist..." || ( echo "dist files not built"; exit 1 )
233213
cd $(PYPI_DIR) && python -m twine upload -r testpypi dist/*
234214

235-
pypi_publish:
215+
pypi_publish: pypi_dist
236216
@[ "${PYPI_SDIST}" ] && echo "Publish dist..." || ( echo "dist files not built"; exit 1 )
237217
cd $(PYPI_DIR) && python -m twine upload dist/*
238218

examples/python/Makefile

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

examples/python/simple.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import infomap
22

3+
print(f"Using Infomap {infomap.__version__}")
4+
35
im = infomap.Infomap("--two-level --verbose --silent")
46

57
print("Creating network...")

0 commit comments

Comments
 (0)