Skip to content

Commit bafd0f9

Browse files
committed
Finish the upgrade to reqwest 0.9
1 parent ea7486a commit bafd0f9

File tree

7 files changed

+100
-53
lines changed

7 files changed

+100
-53
lines changed

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["konstin <[email protected]>"]
33
name = "pyo3-pack"
4-
version = "0.3.4"
4+
version = "0.3.5"
55
description = "Build and publish crates with pyo3 bindings as python packages"
66
exclude = ["get-fourtytwo/**/*", "integration-test/**/*", "sysconfig/*"]
77
readme = "Readme.md"
@@ -26,7 +26,7 @@ cargo_metadata = "0.6.0"
2626
digest = { version = "0.7.5", features = ["std"] }
2727
failure = "0.1.2"
2828
keyring = { version = "0.6.0", optional = true }
29-
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "2698148743c9ab6dcf3ca664d235b458b2cfd426", optional = true }
29+
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "15857a11a43ee6782bb46b87043cb647c5f149c6", optional = true }
3030
rpassword = "2.0.0"
3131
serde_derive = "1.0.79"
3232
serde_json = "1.0.28"
@@ -45,15 +45,17 @@ atty = "0.2.11"
4545
tempfile = "3.0.4"
4646
goblin = { version = "0.0.17", optional = true }
4747
openssl = { version = "0.10.12", features = ["vendored"], optional = true }
48+
pretty_env_logger = { version = "0.2.4", optional = true }
4849

4950
[dev-dependencies]
5051
indoc = "0.2.8"
5152

5253
[features]
53-
default = ["auditwheel", "upload"]
54+
default = ["auditwheel", "upload", "log"]
5455
auditwheel = ["goblin"]
5556
upload = ["reqwest"]
5657
password-storage = ["upload", "keyring"]
58+
log = ["pretty_env_logger"]
5759

5860
# This will make rewquest use a statically linked version of openssl
5961
musl = ["openssl"]

Changelog.md

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.3.5] - 2018-09-20
9+
10+
### Changed
11+
12+
* Upgraded to reqwest 0.9
13+
14+
### Fixed
15+
16+
* "Broken Pipe" with musl builds (through the reqwest upgrade)
17+
818
## [0.3.4] - 2018-09-18
919

1020
### Added
@@ -69,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6979
* Initial Release
7080

7181
[Unreleased]: https://github.com/pyo3/pyo3-pack/compare/v0.3.3...HEAD
82+
[0.3.5]: https://github.com/pyo3/pyo3-pack/compare/v0.3.4...v0.3.5
7283
[0.3.4]: https://github.com/pyo3/pyo3-pack/compare/v0.3.3...v0.3.4
7384
[0.3.3]: https://github.com/pyo3/pyo3-pack/compare/v0.3.1...v0.3.3
7485
[0.3.1]: https://github.com/pyo3/pyo3-pack/compare/v0.3.0...v0.3.1

get-fourtytwo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["konstin <[email protected]>"]
33
name = "get-fourtytwo"
4-
version = "2.0.0"
4+
version = "2.0.1"
55
description = "This implements a dummy function (get_fortytwo.DummyClass.get_42()) in rust"
66
readme = "Readme.md"
77

src/compile.rs

+66-41
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ use std::str;
1212
use BuildContext;
1313
use PythonInterpreter;
1414

15-
#[derive(Deserialize)]
15+
#[derive(Deserialize, Debug, Clone)]
1616
struct BuildPlanEntry {
1717
package_name: String,
18+
program: String,
1819
}
1920

2021
/// The (abbreviated) format of `cargo build --build-plan`
2122
/// For the real thing, see
2223
/// https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/build_plan.rs
23-
#[derive(Deserialize)]
24+
#[derive(Deserialize, Debug, Clone)]
2425
struct SerializedBuildPlan {
2526
invocations: Vec<BuildPlanEntry>,
2627
}
@@ -40,7 +41,7 @@ struct SerializedBuildPlan {
4041
/// reason: "build-script-executed",
4142
/// }
4243
/// ```
43-
#[derive(Serialize, Deserialize)]
44+
#[derive(Serialize, Deserialize, Debug, Clone)]
4445
struct CargoBuildOutput {
4546
cfgs: Vec<String>,
4647
env: Vec<String>,
@@ -52,25 +53,26 @@ struct CargoBuildOutput {
5253

5354
/// This kind of message is printed by `cargo build --message-format=json
5455
/// --quiet` for an artifact such as an .so/.dll
55-
#[derive(Serialize, Deserialize)]
56+
#[derive(Serialize, Deserialize, Debug, Clone)]
5657
struct CompilerArtifactMessage {
5758
filenames: Vec<PathBuf>,
5859
target: CompilerTargetMessage,
60+
package_id: String,
5961
}
6062

61-
#[derive(Serialize, Deserialize)]
63+
#[derive(Serialize, Deserialize, Debug, Clone)]
6264
struct CompilerTargetMessage {
6365
crate_types: Vec<String>,
6466
name: String,
6567
}
6668

67-
#[derive(Serialize, Deserialize)]
69+
#[derive(Serialize, Deserialize, Debug, Clone)]
6870
struct CompilerErrorMessage {
6971
message: CompilerErrorMessageMessage,
7072
reason: String,
7173
}
7274

73-
#[derive(Serialize, Deserialize)]
75+
#[derive(Serialize, Deserialize, Debug, Clone)]
7476
struct CompilerErrorMessageMessage {
7577
rendered: String,
7678
}
@@ -86,7 +88,7 @@ fn get_build_plan(shared_args: &[&str]) -> Result<SerializedBuildPlan, Error> {
8688
"--build-plan",
8789
];
8890

89-
let command_formated = ["cargo"]
91+
let command_formatted = ["cargo"]
9092
.iter()
9193
.chain(build_plan_args)
9294
.chain(shared_args)
@@ -104,15 +106,15 @@ fn get_build_plan(shared_args: &[&str]) -> Result<SerializedBuildPlan, Error> {
104106
format_err!(
105107
"Failed to get a build plan from cargo: {} ({})",
106108
e,
107-
command_formated
109+
command_formatted
108110
)
109111
})?;
110112

111113
if !build_plan.status.success() {
112114
bail!(
113115
"Failed to get a build plan from cargo with '{}': `{}`",
114116
build_plan.status,
115-
command_formated
117+
command_formatted
116118
);
117119
}
118120

@@ -121,6 +123,39 @@ fn get_build_plan(shared_args: &[&str]) -> Result<SerializedBuildPlan, Error> {
121123
Ok(plan)
122124
}
123125

126+
fn get_progress_plan(shared_args: &[&str]) -> Option<(ProgressBar, Vec<String>)> {
127+
if atty::is(Stream::Stderr) {
128+
match get_build_plan(shared_args) {
129+
Ok(build_plan) => {
130+
let mut packages: Vec<String> = build_plan
131+
.invocations
132+
.iter()
133+
.filter(|x| x.program == "rustc") // Only those gives artifact messages
134+
.map(|x| x.package_name.clone())
135+
.collect();
136+
137+
let progress_bar = ProgressBar::new(packages.len() as u64);
138+
progress_bar.set_style(
139+
ProgressStyle::default_bar()
140+
.template("[{bar:60}] {pos:>3}/{len:3} {msg}")
141+
.progress_chars("=> "),
142+
);
143+
144+
if let Some(first) = packages.first() {
145+
progress_bar.set_message(first);
146+
} else {
147+
eprintln!("Warning: The build plan is empty");
148+
}
149+
150+
Some((progress_bar, packages))
151+
}
152+
Err(_) => None,
153+
}
154+
} else {
155+
None
156+
}
157+
}
158+
124159
/// Builds the rust crate into a native module (i.e. an .so or .dll) for a
125160
/// specific python version
126161
///
@@ -163,28 +198,12 @@ pub fn compile(
163198
let mut cargo_args = vec!["rustc", "--message-format", "json"];
164199

165200
// Mimicks cargo's -Z compile-progress, just without the long result log
166-
let progress_plan = if atty::is(Stream::Stderr) {
167-
match get_build_plan(&shared_args) {
168-
Ok(build_plan) => {
169-
let progress_bar = ProgressBar::new(build_plan.invocations.len() as u64);
170-
progress_bar.set_style(
171-
ProgressStyle::default_bar()
172-
.template("[{bar:60}] {pos:>3}/{len:3} {msg}")
173-
.progress_chars("=> "),
174-
);
175-
176-
progress_bar.set_message(&build_plan.invocations[0].package_name);
201+
let mut progress_plan = get_progress_plan(&shared_args);
177202

178-
// We have out own progess bar, so we don't need cargo's bar
179-
cargo_args.push("--quiet");
180-
181-
Some((progress_bar, build_plan))
182-
}
183-
Err(_) => None,
184-
}
185-
} else {
186-
None
187-
};
203+
if progress_plan.is_some() {
204+
// We have out own progess bar, so we don't need cargo's bar
205+
cargo_args.push("--quiet");
206+
}
188207

189208
let mut rustc_args: Vec<&str> = context
190209
.rustc_extra_args
@@ -222,24 +241,30 @@ pub fn compile(
222241
let mut cargo_build = build_command.spawn().context("Failed to run cargo")?;
223242

224243
let mut artifact_messages = Vec::new();
225-
let mut build_plan_pos = 0;
226244
let reader = BufReader::new(cargo_build.stdout.take().unwrap());
227245
for line in reader.lines().map(|line| line.unwrap()) {
228246
if let Ok(message) = serde_json::from_str::<CompilerArtifactMessage>(&line) {
229247
// Extract the location of the .so/.dll/etc. from cargo's json output
230-
if message.target.name == context.module_name
231-
|| message.target.name == context.metadata21.name
232-
{
233-
artifact_messages.push(message);
248+
let target_name = message.target.name.clone();
249+
if target_name == context.module_name || target_name == context.metadata21.name {
250+
artifact_messages.push(message.clone());
234251
}
235252

253+
let crate_name = message.package_id.split(" ").nth(0).unwrap().to_string();
254+
236255
// The progress bar isn't an exact science and stuff might get out-of-sync,
237256
// but that isn't big problem since the bar is only to give the user an estimate
238-
if let Some((ref progress_bar, ref build_plan)) = progress_plan {
239-
progress_bar.inc(1);
240-
build_plan_pos += 1;
241-
if let Some(package) = build_plan.invocations.get(build_plan_pos) {
242-
progress_bar.set_message(&package.package_name);
257+
if let Some((ref progress_bar, ref mut packages)) = progress_plan {
258+
match packages.iter().position(|x| x == &crate_name) {
259+
Some(pos) => {
260+
packages.remove(pos);
261+
progress_bar.inc(1);
262+
}
263+
None => eprintln!("WARN: {} not found in build plan", crate_name),
264+
}
265+
266+
if let Some(package) = packages.first() {
267+
progress_bar.set_message(&package);
243268
}
244269
}
245270
}

src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ extern crate rpassword;
2020
#[allow(unused_imports)]
2121
#[macro_use]
2222
extern crate structopt;
23+
#[cfg(feature = "log")]
24+
extern crate pretty_env_logger;
2325

2426
use failure::Error;
2527
#[cfg(all(feature = "upload", feature = "keyring"))]
@@ -159,6 +161,9 @@ enum Opt {
159161
}
160162

161163
fn run() -> Result<(), Error> {
164+
#[cfg(feature = "log")]
165+
pretty_env_logger::init();
166+
162167
let opt = Opt::from_args();
163168

164169
match opt {

src/target.rs

-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ impl Target {
9090
pub fn get_shared_platform_tag(&self) -> &'static str {
9191
match self.os {
9292
OS::Linux => {
93-
if target_info::Target::env() != "gnu" {
94-
panic!("Expected a gnu target, musl is not supported");
95-
}
9693
if self.is_64_bit {
9794
"x86_64-linux-gnu"
9895
} else {

src/upload.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ use Registry;
1919
#[fail(display = "Uploading to the registry failed")]
2020
pub enum UploadError {
2121
/// Any reqwest error
22-
#[fail(display = "{}", _0)]
22+
#[fail(display = "Http error")]
2323
RewqestError(#[cause] reqwest::Error),
2424
/// The registry returned a "403 Forbidden"
2525
#[fail(display = "Username or password are incorrect")]
2626
AuthenticationError,
2727
/// Reading the wheel failed
28-
#[fail(display = "{}", _0)]
28+
#[fail(display = "IO Error")]
2929
IOError(#[cause] io::Error),
3030
/// The registry returned something else than 200
31-
#[fail(display = "Failed to upload the wheel {}", _0)]
32-
StatusCodeError(String),
31+
#[fail(
32+
display = "Failed to upload the wheel with status {}: {}",
33+
_0,
34+
_1
35+
)]
36+
StatusCodeError(String, String),
3337
}
3438

3539
impl From<io::Error> for UploadError {
@@ -114,6 +118,9 @@ pub fn upload(
114118
e
115119
)
116120
});
117-
Err(UploadError::StatusCodeError(err_text))
121+
Err(UploadError::StatusCodeError(
122+
response.status().to_string(),
123+
err_text,
124+
))
118125
}
119126
}

0 commit comments

Comments
 (0)