Commit dd1e2e92 authored by Sean Leavey's avatar Sean Leavey
Browse files

Use setup.cfg

Fix build

Fix build

Fix build

Fix build

Fix Makefile
parent 1f41ebb0
# NOTE: hopefully this file can eventually be merged into pyproject.toml, if/once flake8
# ever supports it.
[flake8]
# Ignored rules.
ignore =
# Errors
E203 # Whitespace before ':'
E266 # Too many leading '#' for block comment
E402 # Module level import not at top of file
E501 # Line too long
E731 # Do not assign a lambda expression, use a def
E741 # ambiguous variable name
E231 # missing whitespace after ','
# Warnings
W503 # line break before binary operator (soon deprecated; see https://www.flake8rules.com/rules/W503.html)
# Excluded directories.
exclude =
.git
__pycache__
src/docs/source/conf.py
build
dist
......@@ -99,7 +99,7 @@ build/linux/conda:
# A build with special flags set on Cython extensions to enable debugging.
build/debug:
build/linux/debug:
stage: build
image: python:3.9
needs: []
......@@ -107,9 +107,9 @@ build/debug:
- apt update
- apt install -y libsuitesparse-dev
# Install editable mode so in-place pyx files are picked up by coverage.
- pip3 install -e .[dev]
- pip3 install -e .
# Make a platform-specific wheel (with Cython coverage support)
- pip3 wheel . --no-deps -w wheelhouse --build-option --coverage --debug
- CYTHON_COVERAGE=1 CYTHON_DEBUG=1 pip3 wheel . --no-deps -w wheelhouse
artifacts:
paths:
- wheelhouse
......@@ -124,6 +124,7 @@ test/debian/3.8:
- build/manylinux/3.8
image: python:3.8
script:
- python3 scripts/extract_extra_requirements.py setup.cfg test > requirements-test.txt
- pip3 install -r requirements-test.txt
- pip3 install -f wheelhouse finesse
- pytest tests
......@@ -134,6 +135,7 @@ test/debian/3.9:
- build/manylinux/3.9
image: python:3.9
script:
- python3 scripts/extract_extra_requirements.py setup.cfg test > requirements-test.txt
- pip3 install -r requirements-test.txt
- pip3 install -f wheelhouse finesse
- pytest tests
......@@ -152,6 +154,7 @@ test/debian/3.9:
# - conda create -p .finesse-env python=3.8
# - conda activate ./.finesse-env
# - python --version
# - python scripts/extract_extra_requirements.py setup.cfg test > requirements-test.txt
# - pip install -r requirements-test.txt
# - pip install -f wheelhouse finesse
# - pytest tests
......@@ -170,6 +173,7 @@ test/debian/3.9:
# - conda create -p .finesse-env python=3.9
# - conda activate ./.finesse-env
# - python --version
# - python scripts/extract_extra_requirements.py setup.cfg test > requirements-test.txt
# - pip install -r requirements-test.txt
# - pip install -f wheelhouse finesse
# - pytest tests
......@@ -180,14 +184,13 @@ test/debian/3.9:
test/coverage:
stage: test
needs:
- build/debug
- build/linux/debug
image: python:3.9
script:
# Dependencies for the wheel provided by the debug build.
- apt update
- apt install -y libsuitesparse-dev
# Dependencies for running the tests. Cython is also required from the build
# dependencies for use by the pytest Cython coverage plugin.
# Dependencies for running the tests.
- python3 scripts/extract_extra_requirements.py setup.cfg test > requirements-test.txt
- pip3 install -r requirements-test.txt
- pip3 install -f wheelhouse finesse
# Run all tests and generate Cobertura XML formatted coverage report.
......@@ -210,6 +213,7 @@ docs/html:
- build/manylinux/3.9
image: python:3.9
script:
- python scripts/extract_extra_requirements.py setup.cfg docs > requirements-doc.txt
- pip install -r requirements-doc.txt
# Sphinx autodoc needs to be able to import finesse and finesse_sphinx.
- pip install -f wheelhouse finesse
......@@ -241,6 +245,7 @@ docs/pdf:
script:
- apt update
- apt install -y texlive-latex-base librsvg2-bin
- python scripts/extract_extra_requirements.py setup.cfg docs > requirements-doc.txt
- pip install -r requirements-doc.txt
# Sphinx autodoc needs to be able to import finesse and finesse_sphinx.
- pip install -f wheelhouse finesse
......
......@@ -2,11 +2,11 @@ default:
python3 setup.py build_ext -j 4 --inplace
debug:
python3 setup.py --debug build_ext -j 4 --inplace
CYTHON_DEBUG=1 python3 setup.py build_ext -j 4 --inplace
# Build Cython extensions with the CYTHON_TRACE flag enabled to allow coverage tracking.
coverage:
python3 setup.py --coverage build_ext -j 4 --force --inplace
CYTHON_COVERAGE=1 python3 setup.py build_ext -j 4 --force --inplace
clean:
find . -name "*.so" -type f -delete
......
......@@ -12,4 +12,4 @@ dependencies:
- pip:
# Can run arbitrary pip commands here; see e.g.
# https://stackoverflow.com/a/59056234/2251982.
- -e .[dev]
- -e .[test,docs,lint]
......@@ -13,4 +13,4 @@ dependencies:
- pip:
# Can run arbitrary pip commands here; see e.g.
# https://stackoverflow.com/a/59056234/2251982.
- -e .[dev]
- -e .[test,docs,lint]
[build-system]
requires = ["setuptools", "setuptools_scm", "wheel", "Cython>=0.29", "numpy >= 1.20.0"]
requires = ["setuptools", "wheel", "setuptools_scm[toml]", "Cython>=0.29", "numpy >= 1.20.0"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
write_to = "src/finesse/version.py"
[tool.pytest.ini_options]
testpaths = ["tests"]
......
# Requirements for building documentation.
# See https://finesse.docs.ligo.org/finesse3/developer/codeguide/requirements.html.
sphinx
sphinx_rtd_theme
sphinxcontrib-bibtex
sphinxcontrib-katex
sphinxcontrib-svg2pdfconverter
sphinxcontrib-programoutput
jupyter-sphinx
numpydoc
reslate
# Requirements for test runners.
# See https://finesse.docs.ligo.org/finesse3/developer/codeguide/requirements.html.
pytest
pytest-cov
coverage == 4.5.4 # Can't use latest version due to Cython bug: https://github.com/cython/cython/issues/3515
Faker
hypothesis
pycobertura
"""Extract extra dependencies from `setup.cfg`.
Call with the path to `setup.cfg` and the extras section name(s) to extract as
arguments.
This is used by the CI to install test and documentation dependencies without the need
for separate `requirements-test.txt` and `requirements-doc.txt` files.
"""
import sys
import configparser
if __name__ == "__main__":
conf = configparser.ConfigParser()
conf.read(sys.argv[1])
requirements = set(
[conf["options.extras_require"][extra].strip() for extra in sys.argv[2:]]
)
for requirement in requirements:
print(requirement)
[metadata]
name = finesse
author_email = finesse-support@nikhef.nl
license = GPL
license_file = LICENSES.md
url = https://www.gwoptics.org/finesse
description = Simulation tool for modelling laser interferometers
long_description = file: README.md
long_description_content_type = text/markdown
classifiers =
Development Status :: 3 - Alpha
Topic :: Scientific/Engineering :: Physics
Intended Audience :: Science/Research
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
project_urls =
source = https://git.ligo.org/finesse/finesse3
documentation = https://finesse.docs.ligo.org/finesse3
bug-tracker = https://git.ligo.org/finesse/finesse3/issues
[options]
package_dir =
= src
packages = find:
zip_safe = false
python_requires = >=3.8
install_requires =
# See https://finesse.docs.ligo.org/finesse3/developer/codeguide/requirements.html
# for more information.
# Pin these to specific packages so updates don't break Finesse in the wild.
# Periodically update these to newer versions where possible.
numpy==1.20.3
scipy==1.6.3
matplotlib==3.4.2
networkx==2.5.1
sly==0.4
click==8.0.1
click-default-group==1.2.2
tabulate==0.8.9
control==0.9.0
sympy==1.8.0
[options.packages.find]
where=src
[options.package_data]
finesse = finesse.ini, usr.ini.dist
finesse.plotting.style = *.mplstyle
[options.entry_points]
console_scripts =
kat3 = finesse.__main__:cli
pygments.lexers =
KatScript = finesse.script.highlighter:KatScriptPygmentsLexer
KatScriptInPython = finesse.script.highlighter:KatScriptSubstringPygmentsLexer
[options.extras_require]
# Optional extras. These should not be pinned to specific versions so that we can
# continuously test the latest versions. One exception would be for when there are
# incompatibilities with new versions, in which case pin to a working version and leave
# a comment as to why.
test =
pytest
pytest-cov
coverage == 4.5.4 # Cython incompatibility with newer versions: https://github.com/cython/cython/issues/3515
Faker
hypothesis
pycobertura
docs =
sphinx
sphinx_rtd_theme
sphinxcontrib-bibtex
sphinxcontrib-katex
sphinxcontrib-svg2pdfconverter
sphinxcontrib-programoutput
jupyter-sphinx
numpydoc
reslate
lint =
black
pre-commit
pylint
flake8
flake8-bugbear
doc8
graphviz =
pygraphviz
[flake8] # Annoyingly, flake8 doesn't support pyproject.toml so we have to put this here...
# Ignored rules.
ignore =
# Errors
E203 # Whitespace before ':'
E266 # Too many leading '#' for block comment
E402 # Module level import not at top of file
E501 # Line too long
E731 # Do not assign a lambda expression, use a def
E741 # ambiguous variable name
E231 # missing whitespace after ','
# Warnings
W503 # line break before binary operator (soon deprecated; see https://www.flake8rules.com/rules/W503.html)
# Excluded directories.
exclude =
.git
__pycache__
src/docs/source/conf.py
build
dist
"""Setup file."""
"""Setup file.
Also see `setup.cfg`. Ideally all build information would go there such that the
requirements for building Finesse are entirely declarative (which makes it easier to use
build systems other than pip), but we've not yet found a way to build Cython extensions
this way. The `setup` function below therefore just defines the absolute minimum and
everything else goes in `setup.cfg`.
"""
from setuptools import setup, find_packages
import os
import sys
import platform
from pathlib import Path
from setuptools import setup
from Cython.Build import build_ext, cythonize
from Cython.Distutils import Extension
SYS_NAME = platform.system()
NUM_JOBS = int(os.getenv("CPU_COUNT", os.cpu_count()))
......@@ -17,15 +25,15 @@ def get_conda_paths():
# library = os.environ["CONDA_PREFIX"]
if sys.platform == "win32":
library = os.path.join(library, "Library")
return (os.path.join(library, "include"), os.path.join(library, "lib"))
return os.path.join(library, "include"), os.path.join(library, "lib")
except KeyError:
return (None, None)
return None, None
class finesse_build_ext(build_ext):
def initialize_options(self):
super().initialize_options()
# Default to parallel building.
# default to parallel build
self.parallel = NUM_JOBS
......@@ -42,6 +50,7 @@ def make_extension(relpath, **kwargs):
while trailing != "":
names.append(trailing)
leading, trailing = os.path.split(leading)
names.reverse()
......@@ -67,7 +76,6 @@ def make_extension(relpath, **kwargs):
"cython_include_dirs": [],
"cython_directives": [],
}
### Setting up some global options that need to be passed ###
### to all extensions ###
......@@ -128,8 +136,8 @@ def make_extension(relpath, **kwargs):
def ext_modules():
# Argument pattern for extensions requiring OpenMP.
if platform.system() == "Darwin":
# Argument pattern for extensions requiring OpenMP
if SYS_NAME == "Darwin":
open_mp_args = {
"extra_compile_args": ["-Xpreprocessor", "-fopenmp"],
"extra_link_args": ["-liomp5"],
......@@ -137,21 +145,38 @@ def ext_modules():
else:
open_mp_args = {"extra_compile_args": "-fopenmp", "extra_link_args": "-fopenmp"}
# Argument pattern for extensions using KLU.
# Argument pattern for extensions using KLU
cmatrix_args = {"libraries": "klu"}
# The argument patterns that get passed to all extensions.
# The argument patterns that get passed to all extensions
default_ext_args = {}
COVERAGE_MODE = "--coverage" in sys.argv
if COVERAGE_MODE:
# If we're in coverage report mode, then add the trace macros to all extensions
# so that proper line tracing is performed.
# See https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives
# for in-depth details on the options for compiler directives
compiler_directives = {
# Embeds call signature in docstring of Python visible functions
"embedsignature": True,
# No checks are performed on division by zero (for big perfomance boost)
"cdivision": True,
}
if os.environ.get("CYTHON_COVERAGE", False):
# If we're in coverage report mode, then add the trace
# macros to all extensions so that proper line tracing
# is performed
default_ext_args["define_macros"] = [
("CYTHON_TRACE", "1"),
("CYTHON_TRACE_NOGIL", "1"),
]
# Ensure line tracing is switched on for all extensions.
compiler_directives["linetrace"] = True
# If debug mode is set then ensure profiling
# is switched on for all extensions
if os.environ.get("CYTHON_DEBUG", False):
compiler_directives["profile"] = True
# NOTE (sjr) Pass any extra arguments that a specific extension needs via a
# dict of the arg names: values here. See ext_args in make_extension
# function above for the options.
......@@ -192,30 +217,10 @@ def ext_modules():
for ext_rel_path, args in ext_args:
exts.append(make_extension(os.path.normpath(ext_rel_path), **args))
# See https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives
# for in-depth details on the options for compiler directives
compiler_directives = {
# Embeds call signature in docstring of Python visible functions.
"embedsignature": True,
# No checks are performed on division by zero (for big perfomance boost).
"cdivision": True,
}
# If coverage mode is set the ensure line tracing is switched on for all extensions.
if COVERAGE_MODE:
compiler_directives["linetrace"] = True
sys.argv.remove("--coverage")
# If debug mode is set then ensure profiling is switched on for all extensions.
DEBUG_MODE = "--debug" in sys.argv
if DEBUG_MODE:
compiler_directives["profile"] = True
sys.argv.remove("--debug")
return cythonize(
exts,
# Produces HTML files showing level of CPython interaction per-line of each
# Cython extension (.pyx) file.
# Produces HTML files showing level of CPython interaction
# per-line of each Cython extension (.pyx) file
annotate=True,
language_level=3,
nthreads=NUM_JOBS,
......@@ -224,110 +229,5 @@ def ext_modules():
)
CLASSIFIERS = [
"Development Status :: 3 - Alpha",
"Topic :: Scientific/Engineering :: Physics",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS",
]
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
if __name__ == "__main__":
setup(
# Package description.
name="finesse",
description=("A simulation tool for modelling laser interferometers"),
long_description=read("README.md"),
long_description_content_type="text/markdown",
url="https://www.gwoptics.org/finesse",
author_email="finesse-support@nikhef.nl",
project_urls={
"Bug Tracker": "https://git.ligo.org/finesse/finesse3/issues",
"Documentation": "https://finesse.docs.ligo.org/finesse3",
"Source Code": "https://git.ligo.org/finesse/finesse3",
},
# Versioning.
use_scm_version={"write_to": "src/finesse/version.py"},
# Packages and extensions.
packages=find_packages("src"),
package_dir={"": "src"},
ext_modules=ext_modules(),
cmdclass={"build_ext": finesse_build_ext},
zip_safe=False,
package_data={
"finesse": [
"plotting/style/*.mplstyle",
"finesse.ini", # Base config file.
"usr.ini.dist", # Barebone user config file.
]
},
# Requirements. See pyproject.toml for build system requirements and
# https://finesse.docs.ligo.org/finesse3/developer/codeguide/requirements.html
# for more information.
python_requires=">=3.8",
install_requires=[
# Pin these to specific packages so updates don't break Finesse in the wild.
# Periodically update these to newer versions where possible.
"numpy==1.20.3",
"scipy==1.6.3",
"matplotlib==3.4.2",
"networkx==2.5.1",
"sly==0.4",
"click==8.0.1",
"click-default-group==1.2.2",
"tabulate==0.8.9",
"control==0.9.0",
"sympy==1.8.0",
],
extras_require={
# Development extras. These should not be pinned to specific versions so
# that we can continuously test the latest versions. One exception would be
# for when there are incompatibilities with new versions, in which case
# pin to a working version and leave a comment as to why.
"dev": [
# Testing.
"pytest",
"pytest-cov",
"coverage == 4.5.4", # Cython incompatibility with newer versions: https://github.com/cython/cython/issues/3515
"Faker",
"hypothesis",
"pycobertura",
# Documentation.
"sphinx",
"sphinx_rtd_theme",
"sphinxcontrib-bibtex",
"sphinxcontrib-katex",
"sphinxcontrib-svg2pdfconverter",
"sphinxcontrib-programoutput",
"jupyter-sphinx",
"numpydoc",
"reslate",
# Linting.
"black",
"pre-commit",
"pylint",
"flake8",
"flake8-bugbear",
"doc8",
],
"graphviz": ["pygraphviz"],
},
# Other.
license="GPL",
classifiers=CLASSIFIERS,
entry_points={
"console_scripts": ["kat3 = finesse.__main__:cli"],
"pygments.lexers": [
"KatScript = finesse.script.highlighter:KatScriptPygmentsLexer",
"KatScriptInPython = finesse.script.highlighter:KatScriptSubstringPygmentsLexer",
],
},
)
setup(ext_modules=ext_modules(), cmdclass={"build_ext": finesse_build_ext})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment