Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
show-source = True
max-line-length = 80
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
81 changes: 81 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and test

on:
# Only on pushes to master or one of the release branches we build on push
push:
branches:
- master
- "[0-9].[0-9]+-branch"
tags:
- "*"
# Build pull requests
pull_request:

jobs:
test:
strategy:
matrix:
py:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "pypy-3.8"
os:
- "ubuntu-latest"
- "windows-2022"
- "macos-12"
architecture:
- x64
- x86

exclude:
# Linux and macOS don't have x86 python
- os: "ubuntu-latest"
architecture: x86
- os: "macos-12"
architecture: x86

name: "Python: ${{ matrix.py }}-${{ matrix.architecture }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
architecture: ${{ matrix.architecture }}
- run: pip install tox
- name: Running tox
run: tox -e py
coverage:
runs-on: ubuntu-latest
name: Validate coverage
steps:
- uses: actions/checkout@v3
- name: Setup python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7
architecture: x64
- name: Setup python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12
architecture: x64
- run: pip install tox
- run: tox -e py37,py312,coverage
lint:
runs-on: ubuntu-latest
name: Lint the package
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.12
architecture: x64
- run: pip install tox
- run: tox -e lint
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
0.3 (2023-11-22)
================

- Drop Python 2.7, 3.4, 3.5, 3.6.

- Add support for Python 3.9, 3.10, 3.11, 3.12.

- No longer expect ``pkg_resources`` to be available in the created virtualenv.

- No longer depend on ``setuptools``.

- Add ``extra_args`` to ``install()`` and ``create()`` to pass extra arguments
to the underlying commands.

- Add ``raises=False`` option to ``get_version()`` to avoid raising an
exception if a package is not installed.


0.2.1 (2020-08-04)
==================

Expand Down
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ include CHANGES.rst
include LICENSE.txt
include CONTRIBUTING.rst

include .coveragerc
include tox.ini appveyor.yml .travis.yml rtd.txt
include pyproject.toml
include .coveragerc .flake8 pytest.ini
include tox.ini

recursive-exclude * __pycache__ *.py[cod]
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ The ``venv`` fixture is an instance of

``get_version(pkg_name)``

Returns a ``pkg_resources.Version`` object which is sortable and convertable
to a string.
Returns a ``packaging.version.Version`` object which is sortable and
convertable to a string.
23 changes: 0 additions & 23 deletions appveyor.yml

This file was deleted.

33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools>=41.0.1", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 79
skip-string-normalization = true
target_version = ["py37", "py38", "py39", "py310", "py311", "py312"]
exclude = '''
/(
\.git
| \.mypy_cache
| \.tox
| \.venv
| \.pytest_cache
| dist
| build
| docs
)/
'''

# This next section only exists for people that have their editors
# automatically call isort, black already sorts entries on its own when run.
[tool.isort]
profile = "black"
py_version = 3
combine_as_imports = true
line_length = 79
force_sort_within_sections = true
no_lines_before = "THIRDPARTY"
sections = "FUTURE,THIRDPARTY,FIRSTPARTY,LOCALFOLDER"
default_section = "THIRDPARTY"
known_first_party = "pytest_venv"
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
python_files = test_*.py
testpaths =
src/pytest_venv
tests
12 changes: 0 additions & 12 deletions setup.cfg

This file was deleted.

18 changes: 10 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup


def readfile(name):
with open(name) as f:
return f.read()


readme = readfile('README.rst')
changes = readfile('CHANGES.rst')

requires = [
'packaging',
'pytest',
'setuptools',
'virtualenv',
]

Expand All @@ -19,9 +21,10 @@ def readfile(name):

setup(
name='pytest-venv',
version='0.2.1',
version='0.3',
description='py.test fixture for creating a virtual environment',
long_description=readme + '\n\n' + changes,
long_description_content_type='text/x-rst',
author='Michael Merickel',
author_email='michael@merickel.org',
url='https://github.com/mmerickel/pytest-venv',
Expand All @@ -40,14 +43,13 @@ def readfile(name):
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Testing',
Expand Down
41 changes: 31 additions & 10 deletions src/pytest_venv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import pkg_resources
import packaging.version as pv
import pytest
import sys
import subprocess
import sys
import textwrap

WIN = sys.platform == 'win32'

Expand All @@ -23,27 +24,47 @@ def __init__(self, path):
)
self.python = os.path.join(self.bin, 'python')

def create(self, system_packages=False, python=None):
def create(self, system_packages=False, python=None, *, extra_args=None):
cmd = [sys.executable, '-m', 'virtualenv']
cmd += ['-p', python or sys.executable]
if system_packages:
cmd += ['--system-site-packages']
if extra_args:
cmd += extra_args
cmd += [self.path]
subprocess.check_call(cmd)

def install(self, pkg_name, editable=False, upgrade=False):
def install(
self, pkg_name, editable=False, upgrade=False, *, extra_args=None
):
cmd = [self.python, '-m', 'pip', 'install']
if upgrade:
cmd += ['-U']
if extra_args:
cmd += extra_args
if editable:
cmd += ['-e']
cmd += [pkg_name]
subprocess.check_call(cmd)

def get_version(self, pkg_name):
script = (
'import pkg_resources; '
'print(pkg_resources.get_distribution("%(pkg_name)s").version)'
) % dict(pkg_name=pkg_name)
def get_version(self, pkg_name, *, raises=True):
script = textwrap.dedent(
f'''
try:
from importlib.metadata import version
except ImportError:
import pkg_resources
version = lambda x: pkg_resources.get_distribution(x).version

try:
print(version("{pkg_name}"))
except Exception:
print('')
'''
)
version = subprocess.check_output([self.python, '-c', script]).strip()
return pkg_resources.parse_version(version.decode('utf8'))
if not version:
if raises:
raise Exception('package is not installed')
return None
return pv.Version(version.decode('utf8'))
Loading