Skip to content

Commit

Permalink
Merge pull request #58 from jonasbb/cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb authored Jul 7, 2024
2 parents d48c2b2 + d3cfeac commit 5e789b7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 118 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ on:
push:
branches:
- master
- staging
- trying
schedule:
- cron: '0 0 * * *'
permissions: read-all

jobs:
security_audit:
name: Rustsec Audit
runs-on: ubuntu-latest
permissions:
# Allow the action to post about found problems
issues: write
steps:
- uses: actions/checkout@v3
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: actions-rust-lang/audit@v1
119 changes: 44 additions & 75 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ on:
push:
branches:
- master
- staging
- trying
# Test once per week: Monday at 00:00
# Test once per week: Saturday at 00:00
schedule:
- cron: "0 0 * * 1"

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -D warnings
- cron: "0 0 * * 6"
permissions: read-all

jobs:
clippy_check:
Expand All @@ -25,31 +20,19 @@ jobs:
rust: ["stable", "nightly"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- name: "Install/Update the Rust version"
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: clippy
- uses: actions-rs/clippy-check@v1
name: clippy "No Default Features" (${{ matrix.os }} / ${{ matrix.rust }})
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --no-default-features --all-targets -- -D warnings
name: clippy "No Default Features" (${{ matrix.os }} / ${{ matrix.rust }})
- uses: actions-rs/clippy-check@v1
name: clippy "Default" (${{ matrix.os }} / ${{ matrix.rust }})
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --all-targets -- -D warnings
name: clippy "Default" (${{ matrix.os }} / ${{ matrix.rust }})
- uses: actions-rs/clippy-check@v1
name: clippy "All Features" (${{ matrix.os }} / ${{ matrix.rust }})
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --all-features --all-targets -- -D warnings
name: clippy "All Features" (${{ matrix.os }} / ${{ matrix.rust }})

- name: clippy "No Default Features" (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo clippy --workspace --no-default-features --all-targets
- name: clippy "Default" (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo clippy --workspace --all-targets
- name: clippy "All Features" (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo clippy --workspace --all-features --all-targets

rustfmt:
name: Rustfmt
Expand All @@ -59,18 +42,14 @@ jobs:
rust:
- stable
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- name: "Install/Update the Rust version"
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
name: Rustfmt Check (${{ matrix.rust }})
with:
command: fmt
args: --all -- --check

- name: Rustfmt Check (${{ matrix.rust }})
uses: actions-rust-lang/rustfmt@v1

build_and_test:
name: Build and Test
Expand All @@ -79,48 +58,38 @@ jobs:
os: ["ubuntu-latest", "windows-latest"]
# It is good to test more than the MSRV and stable since sometimes
# breakage occurs in intermediate versions.
rust: ["1.46", "1.50", "stable", "beta", "nightly"]
rust: ["stable", "beta", "nightly"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- name: "Install/Update the Rust version"
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
name: Build (${{ matrix.os }} / ${{ matrix.rust }})
with:
command: build
args: --workspace --all-features --all-targets
- uses: actions-rs/cargo@v1
name: Test "No Default Features" (${{ matrix.os }} / ${{ matrix.rust }})
with:
command: test
# cargo test --all-targets does NOT run doctests
# since doctests are important this should not be added
# https://github.com/rust-lang/cargo/issues/6669
args: --workspace --no-default-features
- uses: actions-rs/cargo@v1
name: Test "Default" (${{ matrix.os }} / ${{ matrix.rust }})
with:
command: test
args: --workspace
- uses: actions-rs/cargo@v1
name: Test "All Features" (${{ matrix.os }} / ${{ matrix.rust }})
with:
command: test
args: --workspace --all-features

# The tests are split into build and run steps, to see the time impact of each
# cargo test --all-targets does NOT run doctests
# since doctests are important this should not be added
# https://github.com/rust-lang/cargo/issues/6669
- name: Build (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo build --workspace --all-features --all-targets
- name: Test "No Default Features" (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo test --workspace --no-default-features
- name: Test "Default" (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo test --workspace
- name: Test "All Features" (${{ matrix.os }} / ${{ matrix.rust }})
run: cargo test --workspace --all-features

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'
with:
# tarpaulin already runs with --all-targets
args: "--workspace --all-features -- --test-threads 1"
version: "latest"
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --out xml --workspace --all-features -- --test-threads=1
env:
# https://github.com/xd009642/tarpaulin/issues/1499
CARGO_PROFILE_DEV_DEBUG: 1
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'

# Added to summarize the matrix (otherwise we would need to list every single
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/publish-crates-io.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name: Publish to crates.io
on:
push:
tags:
- 'v*'
name: Publish to crates.io
permissions: read-all

jobs:
publish_petgraph_graphml:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/checkout@v4
- name: "Install/Update the Rust version"
uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
Expand Down
7 changes: 0 additions & 7 deletions bors.toml

This file was deleted.

44 changes: 21 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ where
where
W: Write,
{

// XML/GraphML boilerplate
writer.write(XmlEvent::StartDocument {
version: XmlVersion::Version10,
Expand All @@ -302,13 +301,11 @@ where
// emit graph with nodes/edges and possibly weights
self.emit_graph(writer)?;


writer.write(XmlEvent::end_element())?; // end graphml
Ok(())
}

fn extract_attributes(&self) -> HashSet<Attribute> {

// Store information about the attributes for nodes and edges.
// We cannot know in advance what the attribute names will be, so we just keep track of what gets emitted.
let mut attributes: HashSet<Attribute> = HashSet::new();
Expand All @@ -317,7 +314,10 @@ where
for node in self.graph.node_references() {
if let Some(ref node_labels) = self.export_nodes {
for (name, _) in node_labels(node.weight()) {
attributes.insert(Attribute { name, for_: For::Node });
attributes.insert(Attribute {
name,
for_: For::Node,
});
}
}
}
Expand All @@ -326,7 +326,10 @@ where
for edge in self.graph.edge_references() {
if let Some(ref edge_labels) = self.export_edges {
for (name, _) in edge_labels(edge.weight()) {
attributes.insert(Attribute { name, for_: For::Edge });
attributes.insert(Attribute {
name,
for_: For::Edge,
});
}
}
}
Expand All @@ -338,20 +341,18 @@ where
fn emit_attribute<W>(
&self,
writer: &mut EventWriter<W>,
name: Cow<'static, str>, data: &str
name: Cow<'static, str>,
data: &str,
) -> WriterResult<()>
where
W: Write
W: Write,
{
writer.write(XmlEvent::start_element("data").attr("key", &*name))?;
writer.write(XmlEvent::start_element("data").attr("key", &name))?;
writer.write(XmlEvent::characters(data))?;
writer.write(XmlEvent::end_element()) // end data
}

fn emit_graph<W>(
&self,
writer: &mut EventWriter<W>,
) -> WriterResult<()>
fn emit_graph<W>(&self, writer: &mut EventWriter<W>) -> WriterResult<()>
where
W: Write,
{
Expand All @@ -370,12 +371,12 @@ where

// Emit nodes
for node in self.graph.node_references() {
writer.write(XmlEvent::start_element("node").attr("id", &*node2str_id(node.id())))?;
writer.write(XmlEvent::start_element("node").attr("id", &node2str_id(node.id())))?;
// Print weights
if let Some(ref node_labels) = self.export_nodes {
let datas = node_labels(node.weight());
for (name, data) in datas {
self.emit_attribute(writer, name, &*data)?;
self.emit_attribute(writer, name, &data)?;
}
}
writer.write(XmlEvent::end_element())?; // end node
Expand All @@ -386,34 +387,31 @@ where
writer.write(
XmlEvent::start_element("edge")
.attr("id", &format!("e{}", i))
.attr("source", &*node2str_id(edge.source()))
.attr("target", &*node2str_id(edge.target())),
.attr("source", &node2str_id(edge.source()))
.attr("target", &node2str_id(edge.target())),
)?;
// Print weights
if let Some(ref edge_labels) = self.export_edges {
let datas = edge_labels(edge.weight());
for (name, data) in datas {
self.emit_attribute(writer, name, &*data)?;
self.emit_attribute(writer, name, &data)?;
}
}
writer.write(XmlEvent::end_element())?; // end edge
}
writer.write(XmlEvent::end_element()) // end graph
}

fn emit_keys<W>(
&self,
writer: &mut EventWriter<W>
) -> WriterResult<()>
fn emit_keys<W>(&self, writer: &mut EventWriter<W>) -> WriterResult<()>
where
W: Write,
{
for attr in self.extract_attributes() {
writer.write(
XmlEvent::start_element("key")
.attr("id", &*attr.name)
.attr("id", &attr.name)
.attr("for", attr.for_.to_str())
.attr("attr.name", &*attr.name)
.attr("attr.name", &attr.name)
.attr("attr.type", "string"),
)?;
writer.write(XmlEvent::end_element())?; // end key
Expand Down

0 comments on commit 5e789b7

Please sign in to comment.