Open suzuki-shunsuke opened 1 year ago
pip install
supports --root
option.
--user Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows. (See the Python documentation
for site.USER_BASE for full details.)
--root <dir> Install everything relative to this alternate root directory.
e.g.
$ pip install --root pip-root pre-commit
$ ls pip-root/Users/shunsuke-suzuki/.local/bin
identify-cli nodeenv pre-commit virtualenv
<AQUA_ROOT_DIR>/pkgs/pip/pypi.org/<package name>/<version>/bin/<command>
AQUA_ROOT_DIR/pkgs/
pip/
pypi.org/
pre-commit/
3.3.3/
bin/
pre-commit
lib/
Packages in https://pypi.org/ should start with pypi.org/
so that aqua-renovate-config
can get versions from pypi datasource and aqua g
gets the version from https://pypi.org/ if API exists.
In the repository aquaproj/aqua-registry, pip packages should be located in pkgs/pypi.org
similar to crates.io.
pip install supports --root option.
--target
is more useful than --root
.
$ pip install -t target pre-commit
$ ls target/bin
identify-cli nodeenv pre-commit virtualenv
pre-commit
installed by pip install --target
commandHmm. I installed pre-commit
by pip install --target target pre-commit
, but it failed to execute pre-commit
command.
$ python --version
Python 3.10.5
$ pip --version
pip 22.2 from /Users/shunsukesuzuki/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pip (python 3.10)
$ pip install --target target pre-commit
$ ./target/bin/pre-commit --help
Traceback (most recent call last):
File "/Users/shunsukesuzuki/Documents/test/pip/./target/bin/pre-commit", line 5, in <module>
from pre_commit.main import main
ModuleNotFoundError: No module named 'pre_commit'
target/bin/pre-commit
#!/Users/shunsukesuzuki/.pyenv/versions/3.10.5/bin/python3.10
# -*- coding: utf-8 -*-
import re
import sys
from pre_commit.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
pre_commit
exists in target
.
The environment variable PYTHONPATH
is needed?
Succeeded.
$ env PYTHONPATH=$PWD/target ./target/bin/pre-commit --help
usage: pre-commit [-h] [-V]
{autoupdate,clean,gc,init-templatedir,install,install-hooks,migrate-config,run,sample-config,try-repo,uninstall,validate-config,validate-manifest,help,hook-impl}
...
positional arguments:
{autoupdate,clean,gc,init-templatedir,install,install-hooks,migrate-config,run,sample-config,try-repo,uninstall,validate-config,validate-manifest,help,hook-impl}
autoupdate Auto-update pre-commit config to the latest repos' versions.
clean Clean out pre-commit files.
gc Clean unused cached repos.
init-templatedir Install hook script in a directory intended for use with `git config init.templateDir`.
install Install the pre-commit script.
install-hooks Install hook environments for all environments in the config file. You may find `pre-commit install
--install-hooks` more useful.
migrate-config Migrate list configuration to new map configuration.
run Run hooks.
sample-config Produce a sample .pre-commit-config.yaml file
try-repo Try the hooks in a repository, useful for developing new hooks.
uninstall Uninstall the pre-commit script.
validate-config Validate .pre-commit-config.yaml files
validate-manifest Validate .pre-commit-hooks.yaml files
help Show help for a specific command.
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
I'm not sure if this is a correct solution.
pip
command depends on Python and pip versionBTW, the behaviour of pip
command depends on Python and pip version.
This means pip
package strongly depends on the environment and the reproductivity is low.
We have no plan (probably we won't) to support managing isolated Python environment like pyenv
and virtualenv
.
If the project uses tools such as pyenv
and virtualenv
, I guess it's better to manage pip packages without aqua
.
https://stackoverflow.com/a/27239645/6364492
curl "https://pypi.org/pypi/pre-commit/json" | jq -r '.releases | keys[]'
aqua >= v2.11.0
Support installing packages by pip install
.
To support packages written in Python.
aqua doesn't install these requirements automatically. Please install them yourself.
This feature depends on versions of Python and pip. We verified this feature with the following versions.
$ python --version
$ pip --version
Let's install pre-commit by aqua.
aqua init
aqua g -i pypi.org/pre-commit
You can also select the version by -s
option.
aqua g -i -s pypi.org/pre-commit
aqua i -l
aqua which pre-commit
pre-commit --version
https://github.com/aquaproj/aqua-renovate-config
From 1.8.0, aqua-renovate-config supports updating pypi
packages.
⚠️ Note that package names must be pypi.org/<pypi package name>
.
e.g. pypi.org/pre-commit
.
pypi
packages to Standard RegistryPlease send a pull request to https://github.com/aquaproj/aqua-registry .
Package names must be pypi.org/<pypi package name>
.
e.g. pypi.org/pre-commit
.
⚠️ This includes details of the internal implementation, which may be changed without notification. Please skip this section if you're not interested in the detail. You can use pypi packages even if you don't know this.
pypi
packages are installed in <AQUA_ROOT_DIR>/pkgs/pip/pypi.org/<pypi package name>/<version>
,
and executable files are installed in <AQUA_ROOT_DIR>/pkgs/pip/pypi.org/<pypi package name>/<version>/bin/<command>
.
aqua internally runs python -m pip install
commands.
python -m pip install --target "<AQUA_ROOT_DIR>/pkgs/pip/pypi.org/<pypi package name>/<version>" "<pypi package>==<version>"
aqua g -s
gets the list of pypi package versions from the endpoint https://pypi.org/pypi/<pypi package name>/json
.
<AQUA_ROOT_DIR>/pkgs/pip/pypi.org/<pypi package name>/<version>
is added to the environment variable PYTHONPATH when pypi packages are executed.
e.g.
packages:
- type: pypi
pypi_name: pre-commit
type
must be pypi
. pypi_name
is required. Other fields are optional.
The above setting is equivalent to the following setting.
packages:
- name: pypi.org/pre-commit
type: pypi
pypi_name: pre-commit
files:
- name: pre-commit
pypi
packages don't support the following fields.
pre-commit
https://github.com/aquaproj/aqua-registry/pull/14185I decided to rename the package type name pip
to pypi
.
Hi @Gowiem ,
I published a pre-release version v2.11.0-3 v2.11.0-4.
Could you try this? If you have any feedback, please let me know.
Document: https://github.com/aquaproj/aqua/issues/2128#issuecomment-1657001257
aqua update-aqua v2.11.0-4
aqua -v
mkdir workspace
cd workspace
aqua init
vi aqua.yaml
aqua.yaml
---
registries:
- type: standard
ref: cd6610dcdee69814d8f72e06e9557d42abad4298 # https://github.com/aquaproj/aqua-registry/pull/14185
packages:
Install pre-commit.
aqua g -i pypi.org/pre-commit
aqua i -l
Please check if pre-commit installed by aqua is executed.
command -v pre-commit
If pre-commit installed by other than aqua is executed, you have some options.
PATH
aqua exec
command. aqua exec -- pre-commit
Then please confirm that pre-commit
is available.
pre-commit --help
I'm trying some tools that can be installed by pip install
command.
https://github.com/topics/cli?l=python
Unfortunately, some tools don't work well.
https://github.com/Textualize/textual
ModuleNotFoundError: No module named 'aiohttp'
I'm adding some pypi packages.
I implemented this feature, but now I hesitate to introduce it because other tools such as pyenv, virtualenv, and pipx seem to be better than aqua. I'm not familiar with Python, but Python has already several version management tools. They support managing Python and dependencies in isolated environments, and Renovate supports updating them.
I tried to install some pypi packages by aqua, but some of them don't work well because they depend on other libraries. https://github.com/aquaproj/aqua/issues/2128#issuecomment-1657098894 I don't want to handle these troubles.
aqua has various advantages compared with other tools such as Homebrew and asdf, but in case of pypi packages, aqua doesn't have so many advantages compared with other tools such as pyenv, virtualenv, and pipx.
pypi packages can be installed by pip
easily, but to make them available by aqua, we need to add them to Registries.
It's a little bothersome.
@suzuki-shunsuke note that pipx is not suitable for project specific tool versions, see https://github.com/pypa/pipx/issues/1031
Perhaps aqua can provide a wrapper for both pipx and npx to install pip and node packages declaratively?
Aqua could run pipx under the hood and then just add the created binary to its path, for example /Users/xxxx/.local/pipx/venvs/copier/bin/copier
So rethinking this, i'm not sure pipx is a good solution since I believe it can produce non-deterministic builds: https://github.com/pypa/pipx/issues/1050
I believe that in order to make aqua work with pip packages and make them reproducible, aqua would need to do the following:
I see. Thank you. I misunderstood pipx.
How about direnv?
https://github.com/direnv/direnv/wiki/Python
.envrc
layout python
requirements.txt
pre-commit==3.3.3
direnv allow
pip install -r requirements.txt
$ command -V pre-commit
pre-commit is /Users/shunsukesuzuki/Documents/test/foo/.direnv/python-3.10/bin/pre-commit
$ pre-commit -V
pre-commit 3.3.3
To specify Python version, direnv + pyenv is useful.
Yeah i've also considered direnv as an alternative, there are a few issues though:
pip install manually
, we would like it to run automatically and i'm not sure if direnv can do that
Feature Overview
Support installing packages by
pip install
.Why is the feature needed?
To support packages written in Python.
Workaround
Install tools with other tools.
Example Code
registry.yaml
Reference