Skip to content

Commit

Permalink
Upstreaming precommit lessons from sunpy-template (#63)
Browse files Browse the repository at this point in the history
* Upstreaming precommit lessons from sunpy-template

* Adds py12 tox test suite

* Adds py12 enviroment to parent tox

* Update virtualenv handling in test to pytest-venv
  • Loading branch information
CyclingNinja authored Mar 8, 2024
1 parent cc1e504 commit ff5c864
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
- macos: py39-test
- linux: py310-test
- linux: py311-test
- linux: py312-test
- linux: build_docs
17 changes: 10 additions & 7 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess

import pytest
from pytest_venv import venv


@pytest.fixture
Expand Down Expand Up @@ -32,7 +33,7 @@ def test_examples_present(installed_cookiejar):
assert primes == cprimes


def test_dev_version_number(virtualenv, bake_examples_compiled_dev_version):
def test_dev_version_number(venv, bake_examples_compiled_dev_version):
cj = bake_examples_compiled_dev_version
path = str(cj.project_path)

Expand All @@ -54,12 +55,13 @@ def test_dev_version_number(virtualenv, bake_examples_compiled_dev_version):
subprocess.run(["git", "-C", path, "tag", "v0.1"], check=True)

# Create a new virtualenv with the package installed
virtualenv.run(f"pip install setuptools_scm")
virtualenv.run(f"pip install -e {path}")
venv.install('setuptools_scm')
venv.install(path, editable=True)

# assert it's actually correct
dynamic_version = virtualenv.run('python -c "import packagename; print(packagename.__version__)"', capture=True).strip()
assert dynamic_version == "0.1"
dynamic_version = subprocess.run([venv.python, '-c', 'import packagename; print(packagename.__version__)'],
capture_output=True)
assert dynamic_version.stdout.decode().strip() == "0.1"

with open(cj.project_path / "README.md", "a") as fobj:
fobj.seek(0, io.SEEK_END)
Expand All @@ -69,5 +71,6 @@ def test_dev_version_number(virtualenv, bake_examples_compiled_dev_version):
subprocess.run(["git", "-C", path, "commit", "-m", "second"], check=True)

# assert it's actually correct
dynamic_version = virtualenv.run('python -c "import packagename; print(packagename.__version__)"', capture=True).strip()
assert dynamic_version.startswith("0.2.dev1")
dynamic_version = subprocess.run([venv.python, '-c', 'import packagename; print(packagename.__version__)'],
capture_output=True)
assert dynamic_version.stdout.decode().startswith("0.2.dev1")
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
test
py{38,39,310,311,312}-test
build-docs

[testenv]
Expand All @@ -16,7 +16,7 @@ skip_install = true
deps =
cookiecutter
pytest-cookies
pytest-virtualenv
pytest-venv
tox[testing]

commands =
Expand Down
3 changes: 2 additions & 1 deletion {{ cookiecutter.package_name }}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@


import datetime

# -- Project information -----------------------------------------------------

# The full version, including alpha/beta/rc tags
from {{ cookiecutter.module_name }} import __version__


release = __version__

project = "{{ cookiecutter.package_name }}"
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.package_name }}/setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
from setuptools import setup
{%- if cookiecutter.use_compiled_extensions == 'y' %}
from extension_helpers import get_extensions
{%- endif %}
from setuptools import setup

setup( {%- if cookiecutter.use_compiled_extensions == 'y' -%}
ext_modules=get_extensions()
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.package_name }}/tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
min_version = 4.0
envlist =
py{38,39,310,311}-test
py{38,39,310,311,312}-test
py38-test-oldestdeps
build_docs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{%- if cookiecutter.include_example_code == 'y' -%}
from .example_mod import do_primes
{%- endif %}
from .version import version as __version__

{%- if cookiecutter.include_example_code == 'y' %}
from .example_mod import do_primes
{% if cookiecutter.include_example_code == 'y' -%}
# Then you can be explicit to control what ends up in the namespace,
__all__ = ['do_primes']
{% else %}
{% else -%}
__all__ = []
{%- endif -%}
{% endif -%}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def do_primes(n, usecython=False):

def main(args=None):

from astropy.utils.compat import argparse
from time import time

from astropy.utils.compat import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-c', '--use-cython', dest='cy', action='store_true',
help='Use the Cython-based Prime number generator.')
Expand Down

0 comments on commit ff5c864

Please sign in to comment.