- Commands
- Global options #
- Options #
- install #
- Options #
- update #
- Options #
- Options #
- remove #
- Options #
- Options #
- build #
- Options #
- publish #
- Options #
- config #
- Usage #
- Options #
- shell #
- check #
- search #
- Options #
- version #
- Options #
- export #
- Options #
- cache #
- cache list #
- Footer
- Мелкая питонячая радость #3: Poetry
- Управление зависимостями? Шо, опять?
- Щупаем
- Зачем это все?
- poetry install does not use available binary for numpy 1.19.2 #3196
- Comments
- pederpansen commented Oct 13, 2020
- Issue
- naveen521kk commented Oct 13, 2020 •
- jtc42 commented Oct 20, 2020
- jtc42 commented Oct 20, 2020
- pederpansen commented Oct 21, 2020
- JezuzStardust commented Jan 29, 2021 •
Commands
You’ve already learned how to use the command-line interface to do some things. This chapter documents all the available commands.
To get help from the command-line, simply call poetry to see the complete list of commands, then —help combined with any of those can give you more information.
Global options #
- —verbose (-v|vv|vvv) : Increase the verbosity of messages: “-v” for normal output, “-vv” for more verbose output and “-vvv” for debug.
- —help (-h) : Display help information.
- —quiet (-q) : Do not output any message.
- —ansi : Force ANSI output.
- —no-ansi : Disable ANSI output.
- —version (-V) : Display this application version.
This command will help you kickstart your new Python project by creating a directory structure suitable for most projects.
will create a folder as follows:
If you want to name your project differently than the folder, you can pass the —name option:
If you want to use a src folder, you can use the —src option:
That will create a folder structure as follows:
This command will help you create a pyproject.toml file interactively by prompting you to provide basic information about your package.
It will interactively ask you to fill in the fields, while using some smart defaults.
Options #
- —name : Name of the package.
- —description : Description of the package.
- —author : Author of the package.
- —python Compatible Python versions.
- —dependency : Package to require with a version constraint. Should be in format foo:1.0.0 .
- —dev-dependency : Development requirements, see —require .
install #
The install command reads the pyproject.toml file from the current project, resolves the dependencies, and installs them.
If there is a poetry.lock file in the current directory, it will use the exact versions from there instead of resolving them. This ensures that everyone using the library will get the same versions of the dependencies.
If there is no poetry.lock file, Poetry will create one after dependency resolution.
You can specify to the command that you do not want the development dependencies installed by passing the —no-dev option.
If you want to remove old dependencies no longer present in the lock file, use the —remove-untracked option.
You can also specify the extras you want installed by passing the -E|—extras option (See Extras for more info)
By default poetry will install your project’s package everytime you run install :
If you want to skip this installation, use the —no-root option.
Options #
- —no-dev : Do not install dev dependencies.
- —no-root : Do not install the root package (your project).
- —extras (-E) : Features to install (multiple values allowed).
update #
In order to get the latest versions of the dependencies and to update the poetry.lock file, you should use the update command.
This will resolve all dependencies of the project and write the exact versions into poetry.lock .
If you just want to update a few packages and not all, you can list them as such:
Note that this will not update versions for dependencies outside their version constraints specified in the pyproject.toml file. In other terms, poetry update foo will be a no-op if the version constraint specified for foo is
2.3 or 2.3 and 2.4 is available. In order for foo to be updated, you must update the constraint, for example ^2.3 . You can do this using the add command.
Options #
- —dry-run : Outputs the operations but will not execute anything (implicitly enables –verbose).
- —no-dev : Do not install dev dependencies.
- —lock : Do not perform install (only update the lockfile).
The add command adds required packages to your pyproject.toml and installs them.
If you do not specify a version constraint, poetry will choose a suitable one based on the available package versions.
You also can specify a constraint when adding a package, like so:
If you try to add a package that is already present, you will get an error. However, if you specify a constraint, like above, the dependency will be updated by using the specified constraint. If you want to get the latest version of an already present dependency you can use the special latest constraint:
You can also add git dependencies:
or use ssh instead of https:
If you need to checkout a specific branch, tag or revision, you can specify it when using add :
or make them point to a local directory or file:
If you want the dependency to be installed in editable mode you can specify it in the pyproject.toml file. It means that changes in the local directory will be reflected directly in environment.
If the package(s) you want to install provide extras, you can specify them when adding the package:
Options #
- —dev (-D) : Add package as development dependency.
- —path : The path to a dependency.
- —optional : Add as an optional dependency.
- —dry-run : Outputs the operations but will not execute anything (implicitly enables –verbose).
- —lock : Do not perform install (only update the lockfile).
remove #
The remove command removes a package from the current list of installed packages.
Options #
- —dev (-D) : Removes a package from the development dependencies.
- —dry-run : Outputs the operations but will not execute anything (implicitly enables –verbose).
To list all of the available packages, you can use the show command.
If you want to see the details of a certain package, you can pass the package name.
Options #
- —no-dev : Do not list the dev dependencies.
- —tree : List the dependencies as a tree.
- —latest (-l) : Show the latest version.
- —outdated (-o) : Show the latest version but only for packages that are outdated.
build #
The build command builds the source and wheels archives.
Note that, at the moment, only pure python wheels are supported.
Options #
- —format (-f) : Limit the format to either wheel or sdist .
publish #
This command publishes the package, previously built with the build command, to the remote repository.
It will automatically register the package before uploading if this is the first time it is submitted.
It can also build the package if you pass it the —build option.
Options #
- —repository (-r) : The repository to register the package to (default: pypi ). Should match a repository name set by the config command.
- —username (-u) : The username to access the repository.
- —password (-p) : The password to access the repository.
- —dry-run : Perform all actions except upload the package.
config #
The config command allows you to edit poetry config settings and repositories.
Usage #
setting-key is a configuration option name and setting-value1 is a configuration value. See Configuration for all available settings.
Options #
- —unset : Remove the configuration element named by setting-key .
- —list : Show the list of current config variables.
The run command executes the given command inside the project’s virtualenv.
It can also execute one of the scripts defined in pyproject.toml .
So, if you have a script defined like this:
You can execute it like so:
Note that this command has no option.
shell #
The shell command spawns a shell, according to the $SHELL environment variable, within the virtual environment. If one doesn’t exist yet, it will be created.
check #
The check command validates the structure of the pyproject.toml file and returns a detailed report if there are any errors.
search #
This command searches for packages on a remote index.
This command locks (without installing) the dependencies specified in pyproject.toml .
Options #
- —no-update : Do not update locked versions, only refresh lock file.
version #
This command shows the current version of the project or bumps the version of the project and writes the new version back to pyproject.toml if a valid bump rule is provided.
The new version should ideally be a valid semver string or a valid bump rule: patch , minor , major , prepatch , preminor , premajor , prerelease .
The table below illustrates the effect of these rules with concrete examples.
rule | before | after |
---|---|---|
major | 1.3.0 | 2.0.0 |
minor | 2.1.4 | 2.2.0 |
patch | 4.1.1 | 4.1.2 |
premajor | 1.0.2 | 2.0.0-alpha.0 |
preminor | 1.0.2 | 1.1.0-alpha.0 |
prepatch | 1.0.2 | 1.0.3-alpha.0 |
prerelease | 1.0.2 | 1.0.3-alpha.0 |
prerelease | 1.0.3-alpha.0 | 1.0.3-alpha.1 |
prerelease | 1.0.3-beta.0 | 1.0.3-beta.1 |
Options #
- —short (-s) : Output the version number only.
export #
This command exports the lock file to other formats.
Options #
- —format (-f) : The format to export to (default: requirements.txt ). Currently, only requirements.txt is supported.
- —output (-o) : The name of the output file. If omitted, print to standard output.
- —dev : Include development dependencies.
- —extras (-E) : Extra sets of dependencies to include.
- —without-hashes : Exclude hashes from the exported file.
- —with-credentials : Include credentials for extra indices.
The env command regroups sub commands to interact with the virtualenvs associated with a specific project.
See Managing environments for more information about these commands.
cache #
The cache command regroups sub commands to interact with Poetry’s cache.
cache list #
The cache list command lists Poetry’s available caches.
Footer
Python packaging and dependency management made easy.
Источник
Мелкая питонячая радость #3: Poetry
Управление зависимостями? Шо, опять?
Экосистема Python породила целую пачку способов управления зависимостями в проектах.
Прямо сейчас можно выбирать между setup.py, requirements.txt, setup.cfg, MANIFEST.in и Pipfile.
Но французского питониста Sébastien Eustace все эти способы не устроили, и он написал свою штуку для менеджмента питонячих пакетов — Poetry. Зачем он это сделал? Чтобы заменить все эти setup.py, requirements.txt, setup.cfg, MANIFEST.in и Pipfile чем-то простым и понятным. Плюс добавить кое-что полезное сверху.
Poetry позволяет рулить сразу кучей вещей — версией языка в вашем проекте, зависимостями, подключаемыми путями, скриптами тестирования/разработки, сборкой и публикацией билдов.Все необходимые пути, зависимости и скрипты описываются в специальном файле pyproject.toml.
Poetry лучше всего работает в паре с pyenv — системой управления множественными версиями Python и виртуальными окружениями.
Щупаем
Засучим рукава и посмотрим, как poetry работает в деле. Первым делом ставим pyenv, следуя официальной инструкции в доках.
Среда установлена и настроена, зависимости управляются одним пальцем, можно пилить код!
У вас, скорее всего, появятся в проекте команды запуска сервера, воркеров, скриптов деплоя и тестирования. Их можно засунуть в pyproject.toml и тоже рулить ими одним пальцем.
Добавляем в файл
и теперь можно запускать скрипт командой
Зачем это все?
Потратив десяток минут на освоение этой штуки, вы сэкономите время и нервы на управлении версиями языка и пакетов, отслеживании зависимостей и настройке путей. Особенно это поможет тем, кто хоть раз пробовал опубликовать свои наработки в pip 🙂
- Резолвер зависимостей, способный всегда найти решение конфликтам версий пакетов (если оно вообще существует)
- Автоматическое создание изолированных сред для запускапроектов.
- Приятная консольная утилита, которая здорово упрощает запуск, тесты и деплой проектов.
Poetry прекасно дружит с другими управлялками виртуальными средами, так что интегрировать новый подход в старые проекты будет очень легко.
Источник
poetry install does not use available binary for numpy 1.19.2 #3196
Comments
pederpansen commented Oct 13, 2020
|
Issue
When running poetry install the installation of numpy 1.19.2 (using pyenv-installed Python 3.8.2) takes very long (
minutes) and seems to compile from source.
However, running pip install numpy==1.19.2 yields
within a few seconds.
The text was updated successfully, but these errors were encountered:
naveen521kk commented Oct 13, 2020 •
Did you install python 3.9 and did poetry created a venv with that?
In that is the case it is expected.
jtc42 commented Oct 20, 2020
We’re also having this problem now which is causing significant delays in releasing a critical update.
jtc42 commented Oct 20, 2020
Worth noting that running poetry config experimental.new-installer false beforehand fixes this for me.
pederpansen commented Oct 21, 2020
@naveen521kk As it turns out, the poetry version installed via Homebrew uses a hardcoded Homebrew-installed Python 3.9. The maintainers do not seem to see any issues with that: Homebrew/homebrew-core#53169
I think this restricts the functionality of poetry in an unacceptable way. Solution: Use the official installer.
JezuzStardust commented Jan 29, 2021 •
@naveen521kk As it turns out, the poetry version installed via Homebrew uses a hardcoded Homebrew-installed Python 3.9. The maintainers do not seem to see any issues with that: Homebrew/homebrew-core#53169
I think this restricts the functionality of poetry in an unacceptable way. Solution: Use the official installer.
I installed via Homebrew and got everything working. Using pyenv to set the local version first, then using using poetry env use and finally using the sugggestions by @jtc42 worked for me.
Источник