Skip to content

Commit bc825d2

Browse files
committed
Test & CI
1 parent 3a7f314 commit bc825d2

File tree

7 files changed

+92
-39
lines changed

7 files changed

+92
-39
lines changed

.github/build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- name: Setup Python
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.13"
16+
17+
- name: Install Poetry
18+
run: |
19+
curl -sSL https://install.python-poetry.org | python3 -
20+
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
21+
22+
- name: Install dependencies with Poetry
23+
run: poetry install --with dev
24+
25+
- name: Build
26+
run: poetry build
27+
28+
- name: Tests
29+
run: poetry run pytest

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
22
__pycache__
33
.pytest_cache
4-
gephi-toolkit-all.jar
4+
gephi-toolkit-all.jar
5+
test-export-graph.*

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ It provides helpers to easy the use of Gephy toolkit for Pythonist, even if you
88

99
* Install the lib `pip install gephipy`
1010

11-
* Initialize the GephiPy context
11+
* Import gephipy
1212

1313
```python
1414
from gephipy import gephipy
1515

16-
gephipy.initialize()
1716
```
1817

1918
Then you can use the Gephi toolkit or the GephiPy features.
@@ -22,12 +21,17 @@ Then you can use the Gephi toolkit or the GephiPy features.
2221

2322
```python
2423
from gephipy import gephipy
25-
from org.gephi.statistics.plugin import Modularity, GraphDistance
2624

27-
#
28-
# Init context
29-
#
30-
gephipy.initialize()
25+
# Java imports must be after the gephipy import
26+
from org.gephi.layout.plugin.forceAtlas2 import ForceAtlas2Builder
27+
from org.gephi.layout.plugin.random import Random
28+
from org.gephi.layout.plugin.noverlap import NoverlapLayoutBuilder
29+
from org.gephi.statistics.plugin import Modularity, GraphDistance
30+
from org.openide.util import Lookup
31+
from org.gephi.appearance.api import AppearanceController
32+
from org.gephi.appearance.plugin import RankingNodeSizeTransformer, PartitionElementColorTransformer
33+
from org.gephi.appearance.plugin.palette import PaletteManager
34+
from org.gephi.statistics.plugin import GraphDistance, Modularity
3135

3236
#
3337
# Create a workspace

gephipy/gephipy.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import jpype
2-
3-
from pathlib import Path
4-
import urllib.request
2+
import jpype.imports
53
import networkx as nx
64

5+
# Starting the JVM
6+
from gephipy import jvm
7+
jvm.start()
8+
9+
# Java import
710
from java.io import File
811
from org.openide.util import Lookup
912
from org.gephi.graph.api import GraphController
@@ -12,22 +15,6 @@
1215
from org.gephi.io.exporter.api import ExportController
1316
from org.gephi.io.importer.api import ImportController, EdgeDirectionDefault
1417

15-
GTK_URL="https://repo1.maven.org/maven2/org/gephi/gephi-toolkit/0.10.1/gephi-toolkit-0.10.1-all.jar"
16-
17-
#
18-
# Initialize the context
19-
#
20-
def initialize(gephi_jar_path="./gephi-toolkit-all.jar"):
21-
gtk_jar = Path(gephi_jar_path)
22-
if not gtk_jar.is_file():
23-
print("Download the Gephi toolkit jar")
24-
urllib.request.urlretrieve(GTK_URL, gephi_jar_path)
25-
# Starts the JVM with the GTK in the classpath
26-
try:
27-
jpype.startJVM(classpath=[gephi_jar_path])
28-
except OSError as e:
29-
print(f"Warning: {e}")
30-
3118
#
3219
# Create a new Gephi workspace
3320
#

gephipy/jvm.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,40 @@
33
from pathlib import Path
44
import urllib.request
55

6+
started = None
7+
""" whether the JVM has been started """
8+
69
GTK_URL="https://repo1.maven.org/maven2/org/gephi/gephi-toolkit/0.10.1/gephi-toolkit-0.10.1-all.jar"
710

11+
def lol():
12+
jpype.startJVM(classpath=["./gephi-toolkit-all.jar"])
13+
814
#
915
# Initialize the context
1016
#
11-
def initialize(gephi_jar_path="./gephi-toolkit-all.jar"):
17+
def start(gephi_jar_path="./gephi-toolkit-all.jar"):
18+
global started
19+
print(started)
20+
if started is None:
1221
gtk_jar = Path(gephi_jar_path)
1322
if not gtk_jar.is_file():
1423
print("Download the Gephi toolkit jar")
1524
urllib.request.urlretrieve(GTK_URL, gephi_jar_path)
25+
1626
# Starts the JVM with the GTK in the classpath
1727
try:
28+
print("start JVM")
1829
jpype.startJVM(classpath=[gephi_jar_path])
1930
except OSError as e:
20-
print(f"Warning: {e}")
31+
print(f"Warning: {e}")
32+
33+
started = True
34+
35+
def stop():
36+
"""
37+
Kills the JVM.
38+
"""
39+
global started
40+
if started is not None:
41+
started = None
42+
jpype.shutdownJVM()

test/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from gephipy import jvm
2-
3-
jvm.initialize()

test/test_scenario.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import pytest
2+
from pathlib import Path
3+
import networkx as nx
24

35
from gephipy import gephipy
46

5-
import networkx as nx
7+
# Must be imported after gephipy
68
from org.gephi.layout.plugin.forceAtlas2 import ForceAtlas2Builder
79
from org.gephi.layout.plugin.random import Random
810
from org.gephi.layout.plugin.noverlap import NoverlapLayoutBuilder
@@ -13,16 +15,15 @@
1315
from org.gephi.appearance.plugin.palette import PaletteManager
1416
from org.gephi.statistics.plugin import GraphDistance, Modularity
1517

18+
1619
def test_scenario():
17-
1820
#
1921
# Create a workspace
2022
#
2123
workspace = gephipy.create_workspace()
2224

23-
#
25+
2426
# Create a random graph with NetworkX
25-
#
2627
graphX = nx.erdos_renyi_graph(500,0.01)
2728
gephipy.networkx_to_gephi(workspace, graphX)
2829
graphModel = gephipy.get_graph_model(workspace)
@@ -65,7 +66,6 @@ def test_scenario():
6566
partition.setColors(graphModel.getGraph(), palette.getColors())
6667
appearanceController.transform(colorPartition)
6768

68-
6969
#
7070
# Run Layouts
7171
#
@@ -94,5 +94,18 @@ def test_scenario():
9494
#
9595
# Export your graph
9696
#
97-
98-
gephipy.export_gexf(workspace, "my-gephi-graph.gexf")
97+
gephipy.export_gexf(workspace, "test-export-graph.gexf")
98+
file = Path("./test-export-graph.gexf")
99+
assert file.is_file() == True
100+
101+
gephipy.export_svg(workspace, "test-export-graph.svg")
102+
file = Path("./test-export-graph.svg")
103+
assert file.is_file() == True
104+
105+
gephipy.export_pdf(workspace, "test-export-graph.pdf")
106+
file = Path("./test-export-graph.pdf")
107+
assert file.is_file() == True
108+
109+
gephipy.export_png(workspace, "test-export-graph.png")
110+
file = Path("./test-export-graph.png")
111+
assert file.is_file() == True

0 commit comments

Comments
 (0)