<commit_before>use std::ffi::OsString;
use std::path::Path;

use binary::{
    async_trait::async_trait, binary_clone_box, eyre::Result, tracing, Binary, BinaryTrait,
};
use binary_python::PythonBinary;

/// A `BinaryTrait` for `poetry`
pub struct PoetryBinary;

#[async_trait]
impl BinaryTrait for PoetryBinary {
    fn spec(&self) -> Binary {
        Binary::new("poetry", &[], &[])
    }

    binary_clone_box!();

    async fn versions(&self, _os: &str) -> Result<Vec<String>> {
        self.versions_github_releases("python-poetry", "poetry")
            .await
            // "installer does not support Poetry releases < 0.12.0"
            .map(|versions| self.semver_versions_matching(versions, ">=0.12"))
    }

    async fn install_version(
        &self,
        version: &str,
        dest: &Path,
        _os: &str,
        _arch: &str,
    ) -> Result<()> {
        let script = self
            .download(
                "https://install.python-poetry.org",
                Some("install-poetry.py".to_string()),
                None,
            )
            .await?;

        tracing::info!(
            "Running `install-poetry.py` to install Poetry `{}` to `{}`",
            version,
            dest.display()
        );
        let mut python = PythonBinary {}
            .require(Some(">=3.6".to_string()), true)
            .await?;
        python.env_list(&[
            ("POETRY_HOME", dest.into()),
            ("POETRY_VERSION", OsString::from(version)),
            ("POETRY_ACCEPT", OsString::from("yes")),
        ]);
        python.run(&[&script.display().to_string()]).await?;

        Ok(())
    }
}<commit_msg>fix(Poetry binary): Requires at least Python 3.7<commit_after>use std::ffi::OsString;
use std::path::Path;

use binary::{
    async_trait::async_trait, binary_clone_box, eyre::Result, tracing, Binary, BinaryTrait,
};
use binary_python::PythonBinary;

/// A `BinaryTrait` for `poetry`
pub struct PoetryBinary;

#[async_trait]
impl BinaryTrait for PoetryBinary {
    fn spec(&self) -> Binary {
        Binary::new("poetry", &[], &[])
    }

    binary_clone_box!();

    async fn versions(&self, _os: &str) -> Result<Vec<String>> {
        self.versions_github_releases("python-poetry", "poetry")
            .await
            // "installer does not support Poetry releases < 0.12.0"
            .map(|versions| self.semver_versions_matching(versions, ">=0.12"))
    }

    async fn install_version(
        &self,
        version: &str,
        dest: &Path,
        _os: &str,
        _arch: &str,
    ) -> Result<()> {
        let script = self
            .download(
                "https://install.python-poetry.org",
                Some("install-poetry.py".to_string()),
                None,
            )
            .await?;

        tracing::info!(
            "Running `install-poetry.py` to install Poetry `{}` to `{}`",
            version,
            dest.display()
        );
        let mut python = PythonBinary {}
            .require(Some(">=3.7".to_string()), true)
            .await?;
        python.env_list(&[
            ("POETRY_HOME", dest.into()),
            ("POETRY_VERSION", OsString::from(version)),
            ("POETRY_ACCEPT", OsString::from("yes")),
        ]);
        python.run(&[&script.display().to_string()]).await?;

        Ok(())
    }
}
{'fraction_non_alphanumeric': 0.162016201620162, 'fraction_numerical': 0.006000600060006, 'mean_word_length': 2.0643382352941178, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6619992', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1036, 'n_words': 198}