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

Test from installed wheel #91

Merged
merged 8 commits into from
Oct 7, 2024
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
66 changes: 54 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,44 @@ on:
branches: [ master ]

jobs:
test:
build-wheel:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Build the wheel
run: |
python -m pip install build
python -m build

- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/*.whl

- name: Run the tests
run: |
python -m pip install numpy pyparsing pytest pytest-cov
pytest -v

- name: Build the docs
run: |
python -m pip install matplotlib sphinx
python -m pip install dist/periodictable*.whl
make -j 4 -C doc/sphinx SPHINXOPTS="-W --keep-going" html

# Test the wheel on different platforms
test:
runs-on: ${{ matrix.cfg.os }}
needs: build-wheel

strategy:
matrix:
cfg:
Expand All @@ -19,6 +54,7 @@ jobs:
- { os: ubuntu-latest, py: 3.11, doc: 1 }
- { os: windows-latest, py: 3.11 }
- { os: macos-latest, py: 3.11 }
fail-fast: false

steps:
- uses: actions/checkout@v4
Expand All @@ -28,18 +64,24 @@ jobs:
with:
python-version: ${{ matrix.cfg.py }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel setuptools
python -m pip install numpy scipy matplotlib pytest pytest-cov
- name: Download the wheel
uses: actions/download-artifact@v4
with:
name: wheel
path: dist

- name: Install the wheel
run: python -m pip install dist/periodictable*.whl
shell: bash

- name: Test with pytest
- name: Install Python dependencies
run: |
pytest -v
python -m pip install pytest pytest-cov

- name: check that the docs build (linux only)
if: matrix.cfg.doc == 1
# Change into the test directory to test the wheel so that the
# source directory is not on the path. Full tests with coverage are
# run before building the wheel.
- name: Test wheel with pytest
run: |
python -m pip install sphinx
make -j 4 -C doc/sphinx SPHINXOPTS="-W --keep-going" html
cd test
pytest -v --pyargs --import-mode=append periodictable . ../doc/sphinx/guide
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include LICENSE.txt
include README.rst
graft doc
graft periodictable/xsf
include periodictable/activation.dat
prune doc
prune doc/sphinx/_build
prune doc/sphinx/build
prune */__pycache__
Expand Down
6 changes: 2 additions & 4 deletions doc/sphinx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ help:
clean:
-rm -rf _build/* build/* plots/*.pyc plots/*.png

html: build
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html
@echo
@echo "Build finished. The HTML pages are in _build/html."
Expand Down Expand Up @@ -66,7 +66,7 @@ qthelp:
@echo "To view the help file:"
@echo "# assistant -collectionFile _build/qthelp/Periodic Table.qhc"

latex: build
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex
@echo
@echo "Build finished; the LaTeX files are in _build/latex."
Expand All @@ -92,5 +92,3 @@ doctest:
@echo "Testing of doctests in the sources finished, look at the " \
"results in _build/doctest/output.txt."

build:
cd ../.. && python setup.py build
2 changes: 1 addition & 1 deletion doc/sphinx/guide/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The simplest solution is to load it directly when your package is imported.
In the current example, this could be done by adding the following
line to the end of the file::

init(periodictable.core.elements)
init(periodictable.core.default_table())

This would be fine for the current example because the table size is
small and load time is fast. For large tables, you may wish to
Expand Down
15 changes: 15 additions & 0 deletions periodictable/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,26 @@ def fasta_table():

beta_casein = "RELEELNVPGEIVESLSSSEESITRINKKIEKFQSEEQQQTEDELQDKIHPFAQTQSLVYPFPGPIPNSLPQNIPPLTQTPVVVPPFLQPEVMGVSKVKEAMAPKHKEMPFPKYPVEPFTESQSLTLTDVENLHLPLPLLQSWMHQPHQPLPPTVMFPPQSVLSLSQSKVLPVPQKAVPYPQRDMPIQAFLLYQEPVLGPVRGPFPIIV"

## Uncomment to show package path on CI infrastructure
#def doctestpath():
# """
# Checking import path for doctests::
#
# >>> import periodictable
# >>> print(f"Path to imported periodictable in docstr is {periodictable.__file__}")
# some path printed here
# """

def test():
from periodictable.constants import avogadro_number
from .formulas import formula
elements = default_table()

## Uncomment to show package path on CI infrastructure
#import periodictable
#print(f"Path to imported periodictable in package is {periodictable.__file__}")
#print(fail_test)

# Beta casein results checked against Duncan McGillivray's spreadsheet
# name Hmass Dmass vol den #el xray Hsld Dsld
# =========== ======= ======= ======= ===== ===== ===== ===== =====
Expand Down
18 changes: 10 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ dependencies = [
"pyparsing", "numpy",
]

[project.optional-dependencies]
dev = [
'build',
'pytest',
'pytest-cov',
'sphinx',
]
#[project.optional-dependencies]
#dev = [
# "build",
# "pytest",
# "pytest-cov",
# "matplotlib",
# "sphinx",
#]

classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down Expand Up @@ -49,7 +50,8 @@ packages = ["periodictable"]
[tool.pytest.ini_options]
addopts = ["--doctest-modules", "--doctest-glob=*.rst", "--cov=periodictable"]
doctest_optionflags = "ELLIPSIS"
pythonpath = ["doc/sphinx"]
testpaths = ["periodictable", "test", "doc/sphinx/guide"]
python_files = "*.py"
python_classes = "NoClassTestsWillMatch"
python_functions = ["test", "*_test", "test_*", "model_tests"]
python_functions = ["test", "*_test", "test_*"]
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from periodictable import H, O, Fe, helium, elements, data_files

def test():
## Uncomment to print the package path on the CI infrastructure
#import periodictable
#print(f"Path to imported periodictable in test dir is {periodictable.__file__}")
#print(fail_test)
# Check that we can access element properties
assert H.name == "hydrogen"
assert H.symbol == "H"
Expand Down