Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several minor improvements to tox config and dependency declarations #1070

Merged
merged 6 commits into from
Jan 14, 2025
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
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
PYTHON_VERSION=python3
CLI_VERSION=$(shell grep '^__version__' src/globus_cli/version.py | cut -d '"' -f2)

.venv:
virtualenv --python=$(PYTHON_VERSION) .venv
.venv/bin/pip install -U pip setuptools
.venv/bin/pip install -e '.[development]'
.venv/bin/pip install -e '.[test]'
python -m venv .venv
.venv/bin/pip install -U pip
.venv/bin/pip install -e '.'

.PHONY: localdev install
localdev: .venv
Expand Down
28 changes: 18 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,39 @@ dependencies = [
"typing_extensions>=4.0;python_version<'3.11'",
# these are dependencies of the SDK, but they are used directly in the CLI
# declare them here in case the underlying lib ever changes
"requests>=2.19.1,<3.0.0",
"requests>=2.32.3,<3.0.0",
]
dynamic = ["version"]

[project.urls]
homepage = "https://github.com/globus/globus-cli"

[project.optional-dependencies]
[project.scripts]
globus = "globus_cli:main"

[dependency-groups]
coverage = [
"coverage[toml]>=7"
]
test = [
"coverage>=7",
{include-group = "coverage"},
"pytest>=7",
"pytest-xdist<4",
"pytest-timeout<3",
"click-type-test==1.1.0;python_version>='3.10'",
"responses==0.25.5",
# loading test fixture data
"ruamel.yaml==0.18.10",
# Python 3.12 needs setuptools.
"setuptools;python_version>='3.12'",
]

[project.scripts]
globus = "globus_cli:main"

[dependency-groups]
test-mindeps = [
{include-group = "test"},
"click==8.1.4",
"requests==2.32.3",
"pyjwt==2.0.0",
"cryptography==3.3.1",
"packaging==17.0",
"typing_extensions==4.0",
]
typing = [
"mypy==1.14.1",
"types-jwt",
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def bump_pkg_version_on_file(
"responses": "pyproject.toml",
"ruamel.yaml": "pyproject.toml",
"globus-sdk": "pyproject.toml",
"mypy": "tox.ini",
"mypy": "pyproject.toml",
}


Expand Down
72 changes: 22 additions & 50 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
clean
cov-clean
py{3.13,3.12,3.11,3.10,3.9,3.8}
py3.8-mindeps
cov-combine
Expand All @@ -16,56 +16,41 @@ package = wheel
wheel_build_env =
!sdkmain: build_wheel
sdkmain: build_wheel_sdkmain
extras = test
passenv = GLOBUS_SDK_PATH
# When testing against SDK main it's necessary to recreate the tox environment
# so that the SDK main tarball is re-downloaded and installed for each run.
recreate =
!sdkmain: false
sdkmain: true
deps =
mindeps: click==8.1.4
mindeps: requests==2.19.1
mindeps: pyjwt==2.0.0
mindeps: cryptography==3.3.1
mindeps: packaging==17.0
sdkmain: https://github.com/globus/globus-sdk-python/archive/main.tar.gz
dependency_groups =
!mindeps: test
mindeps: test-mindeps

# the 'localsdk' factor allows CLI tests to be run against a local repo copy of globus-sdk
# it requires that the GLOBUS_SDK_PATH env var is set and uses subprocess and os to pass it as
# an argument to 'pip'
# it requires that the GLOBUS_SDK_PATH env var is set
#
# This is unfortunately necessary: tox does not expand env vars in commands
#
# usage examples:
# GLOBUS_SDK_PATH=../globus-sdk tox -e py3.11-localsdk
# GLOBUS_SDK_PATH=../globus-sdk tox -e 'py{3.12,3.11,3.10,3.9,3.8}-localsdk'
commands =
localsdk: python -c 'import os, subprocess, sys; subprocess.run([sys.executable, "-m", "pip", "install", "-e", os.environ["GLOBUS_SDK_PATH"]])'
coverage run -m pytest {posargs}
depends =
py{3.13,3.12,3.11,3.10,3.9,3.8}{,-mindeps}: clean
cov-combine: py{3.13,3.12,3.11,3.10,3.9,3.8}{,-mindeps}
cov-report: cov-combine

[testenv:clean]
# usage example: GLOBUS_SDK_PATH=../globus-sdk tox -e py3.11-localsdk
deps =
coverage
setuptools
skip_install = true
commands =
python setup.py clean --all
coverage erase
sdkmain: https://github.com/globus/globus-sdk-python/archive/main.tar.gz
localsdk: {env:GLOBUS_SDK_PATH}
commands = coverage run -m pytest {posargs}
depends = cov-clean

[testenv:cov-combine]
deps = coverage
[testenv:cov]
dependency_groups = coverage
skip_install = true
[testenv:cov-clean]
base = cov
commands = coverage erase
[testenv:cov-combine]
base = cov
commands = coverage combine

depends = py{3.13,3.12,3.11,3.10,3.9,3.8}{,-mindeps}
[testenv:cov-report]
deps = coverage
skip_install = true
base = cov
commands_pre = coverage html --fail-under=0
commands = coverage report
depends = cov-combine

[testenv:lint]
deps = pre-commit
Expand Down Expand Up @@ -93,8 +78,7 @@ skip_install = true
deps =
build
twine
allowlist_externals = rm
commands_pre = rm -rf dist/
globus_cli_rmtree = dist
# check that twine validating package data works
commands =
python -m build
Expand All @@ -106,15 +90,3 @@ deps = scriv[toml]
commands =
scriv collect
python ./changelog.d/post-fix-changelog.py changelog.adoc

[testenv:publish-release]
skip_install = true
deps =
build
twine
# clean the build dir before rebuilding
allowlist_externals = rm
commands_pre = rm -rf dist/
commands =
python -m build
twine upload dist/*
46 changes: 46 additions & 0 deletions toxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
This is a very small 'tox' plugin.
'toxfile.py' is a special name for auto-loading a plugin without defining package
metadata.

For full doc, see: https://tox.wiki/en/latest/plugins.html

Methods decorated below with `tox.plugin.impl` are hook implementations.
We only implement hooks which we need.
"""

from __future__ import annotations

import logging
import pathlib
import shutil
import typing as t

from tox.plugin import impl

if t.TYPE_CHECKING:
from tox.config.sets import EnvConfigSet
from tox.session.state import State
from tox.tox_env.api import ToxEnv

log = logging.getLogger(__name__)


@impl
def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None:
env_conf.add_config(
keys=["globus_cli_rmtree"],
of_type=list[str],
default=[],
desc="A dir tree to remove before running the environment commands",
)


@impl
def tox_before_run_commands(tox_env: ToxEnv) -> None:
cli_rmtree = tox_env.conf.load("globus_cli_rmtree")
for name in cli_rmtree:
path = pathlib.Path(name)
if path.exists():
log.warning(f"globus_cli_rmtree: {path}")
shutil.rmtree(path)
Loading