Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Poetry v2を使う #920

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ただのコメントです)

sedって置き換え対象の文字列がなかったとしてもエラーにならないんですよねー。。。
例えば今回の場合はversion = "\(0\.0\.0\)"のとこが別の値に変わってバージョンが入らなくなっていてもビルド時にきづけない。

あとsedはmacOSだとBSD版?が入ってて扱いづらいという。

一応s/置換前の文字列/置換後の文字列/; t; q1;などとすれば、書き換え対象の文字列がなかった場合exit 1してくれるっぽみです。

あるいはビルド時にバージョンが一致しているかどうかを確かめてもいいかも?

まあ、参考になれば。。。

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
Loading