Skip to content

Commit

Permalink
build: Poetry v2を使う
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jan 8, 2025
1 parent 87443fd commit 1962b45
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ jobs:
- name: set cargo version
run: |
cargo set-version "$VERSION" --exclude voicevox_core_python_api --exclude downloader --exclude xtask
if ${{ matrix.python_whl }}; then cargo set-version "$VERSION" -p voicevox_core_python_api; fi
if ${{ matrix.python_whl }}; then
sed -i_ 's/version = "\(0\.0\.0\)"/version = "'"$VERSION"'"/' ./crates/voicevox_core_python_api/pyproject.toml
fi
- name: cache target
uses: Swatinem/rust-cache@v2
if: ${{ !inputs.is_production }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
poetry config virtualenvs.create false
- name: Validate poetry.lock
run: |
poetry lock --no-update
poetry lock
git diff --exit-code
- name: Install dependencies
run: poetry install --with test
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ typetag = "0.2.18"
url = "2.5.4"
uuid = "1.10.0"
voicevox_core = { path = "crates/voicevox_core" }
voicevox_core_macros = { path = "crates/voicevox_core_macros" }
windows = "0.43.0"
zip = "0.6.3"

Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ thiserror.workspace = true
tracing.workspace = true
uuid = { workspace = true, features = ["v4", "serde"] }
voicevox-ort = { workspace = true, features = ["download-binaries", "__init-for-voicevox"] }
voicevox_core_macros = { path = "../voicevox_core_macros" }
voicevox_core_macros.workspace = true

[dev-dependencies]
heck.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/voicevox_core_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ proc-macro = true

[dependencies]
derive-syn-parse.workspace = true
fs-err.workspace = true
indexmap.workspace = true
proc-macro2.workspace = true
quote.workspace = true
serde = { workspace = true, features = ["derive"] }
syn = { workspace = true, features = ["extra-traits", "full", "visit-mut"] }
toml.workspace = true

[lints.rust]
unsafe_code = "forbid"
Expand Down
7 changes: 7 additions & 0 deletions crates/voicevox_core_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod extract;
mod inference_domain;
mod inference_domains;
mod python_api;

use syn::parse_macro_input;

Expand Down Expand Up @@ -123,6 +124,12 @@ pub fn substitute_type(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
from_syn(inference_domains::substitute_type(input))
}

#[proc_macro]
pub fn pyproject_project_version(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input);
from_syn(python_api::pyproject_project_version(input))
}

fn from_syn(result: syn::Result<proc_macro2::TokenStream>) -> proc_macro::TokenStream {
result.unwrap_or_else(|e| e.to_compile_error()).into()
}
36 changes: 36 additions & 0 deletions crates/voicevox_core_macros/src/python_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::env;

use derive_syn_parse::Parse;
use quote::ToTokens as _;
use serde::Deserialize;
use syn::LitStr;

pub(crate) fn pyproject_project_version(_: Input) -> syn::Result<proc_macro2::TokenStream> {
let span = proc_macro2::Span::call_site();

let path = &env::var("CARGO_MANIFEST_DIR")
.map_err(|e| syn::Error::new(span, format!("could not get `$CARGO_MANIFEST_DIR`: {e}")))?;
let path = std::path::Path::new(path).join("pyproject.toml");

let PyprojectToml {
project: Project { version },
} = &fs_err::read_to_string(path)
.map_err(|e| e.to_string())
.and_then(|s| toml::from_str(&s).map_err(|e| e.to_string()))
.map_err(|e| syn::Error::new(span, e))?;

return Ok(LitStr::new(version, span).to_token_stream());

#[derive(Deserialize)]
struct PyprojectToml {
project: Project,
}

#[derive(Deserialize)]
struct Project {
version: String,
}
}

#[derive(Parse)]
pub(crate) struct Input {}
2 changes: 1 addition & 1 deletion crates/voicevox_core_python_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "voicevox_core_python_api"
version = "0.0.0"
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
Expand All @@ -24,6 +23,7 @@ tokio = { workspace = true, features = ["rt", "sync"] }
tracing = { workspace = true, features = ["log"] }
uuid.workspace = true
voicevox_core = { workspace = true, features = ["load-onnxruntime"] }
voicevox_core_macros.workspace = true

[lints.rust]
unsafe_code = "forbid"
Expand Down
Loading

0 comments on commit 1962b45

Please sign in to comment.