Skip to content

Commit

Permalink
Migrate from setup.cfg to pyproject.toml (#774)
Browse files Browse the repository at this point in the history
* fix authors, readme, versioning, python-requires
* add empty setup.cfg to allow for dev installs
* removed setup.py stub
* added todo in manifest
* move flake8 cfg from setup.cfg to .flake8 as it does not support pyproject.toml
* require pytest >=6 for pyproject.toml support
  Only this tool refuses pep518, so we let its config reside in an explicit file.
* add src dir for coverage.run
* fix pytest config section
* [conda-recipe] use pyproject.toml to expand dependencies and entry points (thx @kenodegard).
* request toml feature for build environment.
* use "build" package to create wheel and sdist
* [conda-recipe] build a compattible conda env from pyproject.toml via jinja
* [conda-recipe] version gets set by env variable
* set Development Status classifier to "beta"

Co-authored-by: CagtayFabry <CagtayFabry@users.noreply.github.com>
  • Loading branch information
marscher and CagtayFabry authored Sep 2, 2022
1 parent 91b89bd commit 6a90ebf
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 196 deletions.
22 changes: 22 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# flake8 maintainer does not like pyproject.toml:
# https://github.com/PyCQA/flake8/issues/234#issuecomment-812800722

[flake8]
# References:
# https://flake8.readthedocs.io/en/latest/user/configuration.html
# https://flake8.readthedocs.io/en/latest/user/error-codes.html

# Note: there cannot be spaces after comma's here
ignore =
W503,W504 # line break after binary operator
E203 # E203 whitespace before ':' (not PEP8 compliant anyway)
C408 # allow dict() over literal {}

max-line-length = 88
select = C,E,F,W,B,B950 # black formatting options
per-file-ignores =
aws_setup.py:E501
exclude =
__init__.py
doc/conf.py
no-accept-encodings = True
9 changes: 6 additions & 3 deletions .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ jobs:
- name: conda list
run: conda list

- name: set pkg version
run: echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(python -m setuptools_scm)" >> $GITHUB_ENV

- name: Build from local conda recipe
run: conda mambabuild -c conda-forge .

Expand Down Expand Up @@ -83,11 +86,11 @@ jobs:
- name: pip installs
run: |
python -m pip install --upgrade pip
pip install setuptools setuptools_scm wheel twine
pip install setuptools setuptools_scm wheel twine build
- name: build package
- name: build package + create src archive (stored in dist folder)
run: |
python setup.py sdist bdist_wheel
python -m build
- uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:

- uses: CagtayFabry/pydeps2env@main
with:
file: 'pyproject.toml'
channels: 'conda-forge defaults'
extras: 'test vis'
setup_requires: 'include'
Expand Down Expand Up @@ -133,6 +134,7 @@ jobs:

- uses: CagtayFabry/pydeps2env@main
with:
file: 'pyproject.toml'
channels: 'conda-forge defaults'
extras: 'test'
setup_requires: 'include'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:

- uses: CagtayFabry/pydeps2env@main
with:
file: 'pyproject.toml'
channels: 'conda-forge defaults'
extras: ''
setup_requires: 'include'
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ added
changes
=======

- ``weldx`` now requires pip to install (previously it could be installed by directly invoking setup.py) [:pull:`774`].
From a users perspective nothing changes here, as the package was always recommended to be installed via pip.
- Updated the outdated tutorial about the `LocalCoordinateSystem` [:pull:`775`]
- ``weld_seam`` is now a required field in the ``multi_pass_weld`` schema [:pull:`790`]
- Add section about time-dependent spatial data to the `CoordinateSystemManager` tutorial [:pull:`792`]


fixes
=====

Expand Down
5 changes: 4 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
global-exclude .*

recursive-include weldx/schemas *.yaml
recursive-include weldx/manifests *.yaml
include CITATION.cff
Expand All @@ -7,5 +9,6 @@ prune .github
prune devtools
prune doc
prune tutorials
prune build

global-exclude .*
# TODO: sdist contains files in parent, which are not part of the source dist (e.g. unversioned files etc. in repo)
23 changes: 14 additions & 9 deletions devtools/conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
{% set data = load_setup_py_data() %}
{% set pyproject = load_file_data("../../pyproject.toml", from_recipe_dir=True) %}
{% set proj = pyproject.get('project') %}

package:
name: weldx
version: {{ data.get("version") }}
version: {{ environ.get('SETUPTOOLS_SCM_PRETEND_VERSION', 999) }}

source:
path: ../..

build:
number: 0
noarch: python
script: {{ PYTHON }} -m pip install . -vv
script_env:
- SETUPTOOLS_SCM_PRETEND_VERSION
script: "{{ PYTHON }} -m pip install . -vv"
entry_points:
{% for e in data['entry_points']['console_scripts'] %}
- {{ e }}
{% for module, entrypoints in proj.get('entry-points').items() %}
{% for name, path in entrypoints.items() %}
- {{ name }} = {{ module }}.{{ path }}
{% endfor %}
{% endfor %}
requirements:
host:
- pip
- setuptools_scm
- python
run:
- python >=3.8,<3.10
# dependencies are defined in setup.py
{% for dep in data['install_requires'] %}
- python {{ proj.get("requires-python") }}
# dependencies are defined in pyproject.toml
{% for dep in proj.get('dependencies') %}
- {{ dep.lower() }}
{% endfor %}

Expand All @@ -33,7 +38,7 @@ test:
- pytest
- pytest-xdist
- black
# requires wx-widgets here, so we can properly load the visualization sub-package.
# require wx-widgets here, so we can properly load the visualization sub-package.
- weldx_widgets
files:
- conftest.py
Expand Down
187 changes: 186 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,192 @@
[project]
name = "weldx"
dynamic = [ # see: https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata
"version", # version gets derived from git by setuptools_scm.
]
authors = [
{name="Cagtay Fabry", email="cagtay.fabry@bam.de"},
{name="Volker Hirthammer", email="volker.hirthammer@bam.de"},
{name="Martin K. Scherer", email="martin.scherer@bam.de"},
]
description = "Python API for the WelDX file format and standard"
readme = {file = "README.rst", content-type="text/x-rst"}
license = {file = "LICENSE", name="BSD License"}
keywords = [
"welding",
"weldx",
"bam", # TODO: add more keywords here! think of them as in a journal article.
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering :: Physics", # TODO: add more topics here!
"Intended Audience :: Science/Research",
"Intended Audience :: Education",
]

# Dependencies
requires-python = ">=3.8,<3.11"
dependencies = [
"numpy >=1.20",
"asdf >=2.8.2",
"pandas >=1.0",
"xarray >=0.19",
"scipy >=1.4,!=1.6.0,!=1.6.1",
"sympy >=1.6",
"pint >=0.18",
"pint-xarray >=0.2.1",
"bottleneck >=1.3.3",
"boltons",
"bidict",
"networkx >=2,!=2.7.0,!=2.8.1",
"fs",
"meshio",
"psutil",
"IPython",
]

[project.urls]
documentation = "https://weldx.readthedocs.io"
repository = "https://github.com/BAMweldx/weldx"
bug_tracker = "https://github.com/BAMweldx/weldx/issues"
changelog = "https://github.com/BAMweldx/weldx/blob/master/CHANGELOG.rst"

[project.optional-dependencies]
test = [
"pytest >=6",
"pytest-cov",
"pytest-xdist",
"nbval",
]
vis = [
"weldx_widgets >= 0.2",
]

# ASDF extension entry points.

[project.entry-points."asdf.extensions"]
weldx = "weldx.asdf.extension:get_extensions"
weldx_validators = "weldx.asdf._extension:WeldxValidatorExtension"

[project.entry-points."asdf.resource_mappings"]
weldx_schemas = "weldx.asdf.extension:get_resource_mappings"

# console scripts
[project.scripts]
welding_schema = "weldx.asdf.cli.welding_schema:main"

# Build system config, pip creates a temporary env with "requires" pkgs.
[build-system]
requires = [
"wheel",
"setuptools >= 40.9.0",
"setuptools_scm",
"setuptools_scm[toml]>=6.2",
]
build-backend = "setuptools.build_meta"


# Tool configs
[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools_scm]
write_to = "weldx/_version.py"
write_to_template = '__version__ = "{version}"'

[tool.pydocstyle]
# convention numpy is currently equivalent to ignoring 'D107', 'D203', 'D212', 'D213', 'D402', 'D413'
convention = "numpy"
match = "(?!__)(?!_version)(?!conftest).*\\.py"
match_dir = "^(?!(tests|tags|asdf)).*"

[tool.pytest.ini_options]
addopts = "--tb=short --color=yes -rsw --cov=weldx --cov-report=term-missing:skip-covered --doctest-modules"
#addopts = --tb=short --color=yes -rs -p no:cov
testpaths = "weldx"
# custom test markers, see https://docs.pytest.org/en/latest/example/markers.html#mark-examples
markers = "slow: marks tests as slow to run (skipped by default, enable with --runslow option)"
asdf_schema_root = "weldx/schemas/weldx.bam.de/weldx" # TODO: couldn't we just use the entry points to resolve this?
#asdf_schema_tests_enabled = true
#asdf_schema_skip_tests =
# weldx.bam.de/weldx/datamodels/single_pass_weld-1.0.0.schema.yaml
norecursedirs = "doc"
filterwarnings = [
"ignore::DeprecationWarning:traittypes.*:",
"ignore:Passing method to :FutureWarning:xarray.*:",
"error::pint.UnitStrippedWarning",
]

[tool.isort]
profile = "black"
default_section = "THIRDPARTY"
known_first_party = "weldx"
sections = "FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER" # TODO: or list?

[tool.coverage.run]
source = ["weldx"]

[tool.coverage.report]
omit = [
"weldx/_version.py",
"weldx/tests/*",
]
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",

# ignore class __repr__-like functions:
"def __repr__",
"def __str__",
"def _ipython_display_",
]

[tool.mypy]
python_version = "3.9"
files = "weldx"
ignore_missing_imports = true # TODO: this is bad!
strict_optional = false
pretty = true
allow_redefinition = true
show_error_context = true
show_error_codes = true
show_column_numbers = true
sqlite_cache = true

# MyPy per-module options:
[[tool.mypy.overrides]]
module = "weldx.asdf.*"
ignore_errors = true

[[tool.mypy.overrides]]
module = "weldx.tags.*"
ignore_errors = true

[[tool.mypy.overrides]]
module = "weldx.tests.*"
ignore_errors = true

[[tool.mypy.overrides]]
module = "weldx.welding.groove.*"
ignore_errors = true

# TODO: remove after refactoring the geometry module
[[tool.mypy.overrides]]
module = "weldx.geometry.*"
ignore_errors = true

# this is a workaround for an xarray related mypy bug
# see https://github.com/python/mypy/pull/9495
# and https://github.com/space-physics/msise00/commit/8b59a9383dd6fcc54b7dac74eb95a350308d7b62
# TODO: is this still mandatory?
[[tool.mypy.overrides]]
module = "xarray"
follow_imports = "skip"
ignore_errors = true
Loading

0 comments on commit 6a90ebf

Please sign in to comment.