Как загрузить нетронутый пакет Python на PyPI?

Резюме

Это красивый. Вам понравится ответ.

Добавьте следующую строку перед } else {:

continue 2;

Объяснение

Поскольку вы делаете двойной цикл, если соответствующий домен не является последним доменом, он переопределит домен, которому соответствует соответствие. Таким образом, вам нужно перейти сразу к следующей строке , а не только к следующей области , как только вы найдете совпадение.

Код

 "google.com"],
    ["domain" => "google.se"]
];

$rows = [
    ["product" => "Product 1 - Test purposes 1"],
    ["product" => "Product 2 - Test purposes 2 google.com"],
    ["product" => "Product 2 - Test purposes 2 google.se"],
];

$table = [];

# loop through all rows from the database
foreach($rows as $id => $row){
    # loop through all domains
    foreach($domains as $domain) {
        if(preg_match("/{$domain['domain']}/i", $row['product'],$matches, PREG_OFFSET_CAPTURE)) {
            $trimmed = str_replace($domain['domain'], '', $row['product']) ;
            $table[$id]['product'] = $trimmed;
            continue 2;
            //As soon as you hit a match, go to the next *row*.
            //Don't try to match any more domains.
        } else {
            $table[$id]['product'] = $row['product'];
        }
    }
}

var_dump($table);

Предостережения

Предполагается, что у вас есть только один домен, соответствующий каждой строке.

https://3v4l.org/Oo2Ie

10
задан Michael Currie 15 April 2016 в 09:58
поделиться

1 ответ

When you perform an "sdist" command, then what controls the list of included files is your "MANIFEST.in" file sitting next to "setup.py", not whatever you have listed in "package_data". This has something to do with the schizophrenic nature of the Python packaging solutions today; "sdist" is powered by the distutils in the standard library, while "bdist_egg" is controlled by the setuptools module.

To solve the problem, try creating a MANIFEST.in next to your setup.py file, and give it contents like this:

include *.jpg

Of course, I'm imaging that your "image files" are actual pictures rather than disk images or ISO images or something; you might have to adjust the above line if I've guessed wrong! But check out the Specifying which files to distribute section of the distutils docs, and see whether you can't get those files appearing in your .tar.gz source distribution! Good luck.

16
ответ дан 3 December 2019 в 22:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: