Skip to content

Commit

Permalink
Drop support for installing Python 2 packages and add tests for rez_p…
Browse files Browse the repository at this point in the history
…ip.pip (#39)

Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
  • Loading branch information
JeanChristopheMorinPerso authored Jul 2, 2023
1 parent 093ae3d commit be04359
Show file tree
Hide file tree
Showing 15 changed files with 480 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
python-version: ${{ matrix.python }}

- name: Test
run: pipx run nox --error-on-missing-interpreter -s test-${{ matrix.python }} -- -s
run: pipx run nox --error-on-missing-interpreter -s test-${{ matrix.python }}

- name: Codecov upload
uses: codecov/codecov-action@v3
Expand Down
89 changes: 5 additions & 84 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
Expand All @@ -27,80 +21,18 @@ share/python-wheels/
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
Expand All @@ -110,16 +42,6 @@ ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
Expand All @@ -128,10 +50,9 @@ dmypy.json
# Pyre type checker
.pyre/

# Custom
.nox
# Other
.vscode
tests/data/rez_repo
tests/data/_tmp_download
docs/build
docs/bin
/docs/build/
tests/data/rez_repo/
tests/data/_tmp_download/
docs/bin/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Modern rez-pip implementation. Very WIP.
* [x] Use logging
* [x] Progress bars for download?
* [x] Confirm that Python 2 is supported
* It is not...
* [x] Confirm that the theory works as expected
* [x] Windows support
* [ ] Hook into rez
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Features
========

* Simpler to use thanks to the vendoring of pip.
* Supports installing Python 2 and 3 packages.
* Does **not** support installing packages for Python 2.
* Better output logs.
* Implemented as an out-of-tree plugin, which means faster development cycle and more frequent releases.
* Maintained by the rez maintainers.
Expand Down
13 changes: 11 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
[pytest]
addopts = -v --strict-markers --cov=rez_pip --cov-branch --cov-report=term-missing --cov-report=xml --cov-report=html
addopts =
-v
--strict-markers
--cov=rez_pip
--cov-branch
--cov-report=term-missing
--cov-report=xml
--cov-report=html
--durations=0

norecursedirs = rez_repo

markers =
integration: mark the tests as integration tests
py27: mark the tests has using a Python 2.7 rez package
py37: mark the tests has using a Python 3.7 rez package
py39: mark the tests has using a Python 3.7 rez package
py311: mark the tests has using a Python 3.11 rez package
30 changes: 21 additions & 9 deletions src/rez_pip/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ def getPackages(
) -> typing.List[PackageInfo]:
# python pip.pyz install -q requests --dry-run --ignore-installed --python-version 2.7 --only-binary=:all: --target /tmp/asd --report -

with tempfile.NamedTemporaryFile(prefix="pip-install-output") as fd:
_fd, tmpFile = tempfile.mkstemp(prefix="pip-install-output", text=True)
os.close(_fd)
# We can't with "with" (context manager) because it will fail on Windows.
# Windows doesn't allow two different processes to write if the file is
# already opened.
try:
command = [
# We need to use the real interpreter because pip can't resolve
# markers correctly even if --python-version is provided.
# See https://github.com/pypa/pip/issues/11664.
pythonExecutable,
pip,
"install",
Expand All @@ -90,7 +98,7 @@ def getPackages(
"--target=/tmp/asd",
"--disable-pip-version-check",
"--report", # This is the "magic". Pip will generate a JSON with all the resolved URLs.
fd.name,
tmpFile,
*extraArgs,
]

Expand Down Expand Up @@ -119,13 +127,17 @@ def getPackages(
f"{output}",
)

rawData = json.load(fd)
rawPackages = rawData["install"]
with open(tmpFile, "r") as fd:
rawData = json.load(fd)
finally:
os.remove(tmpFile)

packages: typing.List[PackageInfo] = []
rawPackages = rawData["install"]

for rawPackage in rawPackages:
packageInfo = PackageInfo.from_dict(rawPackage)
packages.append(packageInfo)
packages: typing.List[PackageInfo] = []

return packages
for rawPackage in rawPackages:
packageInfo = PackageInfo.from_dict(rawPackage)
packages.append(packageInfo)

return packages
Loading

0 comments on commit be04359

Please sign in to comment.