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

Prepare isort black formatters and checks #766

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bd19a92
start introducing format target
bpkroth Jun 28, 2024
a1fc746
new global vars to help reuse elsewhere
bpkroth Jun 28, 2024
2af7971
clean format targets on conda rebuild
bpkroth Jun 28, 2024
d6d2e9b
rework some dependencies in some rules
bpkroth Jun 28, 2024
77d3982
rework pytest rules for simplicity
bpkroth Jun 28, 2024
89a2907
Rename a clean target for consistency
bpkroth Jun 28, 2024
fdf400b
introduce clean-format target
bpkroth Jun 28, 2024
7a2e645
fixup message
bpkroth Jun 28, 2024
b890eae
Adjust the Makefile check rules to only rerun checks on files that ha…
bpkroth Jun 28, 2024
e7880fb
Introduce pyproject.toml and new build mechanisms, refactor version.py
bpkroth Jun 28, 2024
287fb4f
Revert back to prefering default conda repo instead of conda forge
bpkroth Jun 28, 2024
4dd6b5b
This directive was moved to pyproject.toml files
bpkroth Jun 28, 2024
3a7ab0c
Omit the notebooks from the sdist and whl files
bpkroth Jun 28, 2024
2777483
include a toml extension in vscode
bpkroth Jun 28, 2024
b9767d9
Prepare isort and black formatters and checks, but don't enable them …
bpkroth Jun 28, 2024
148ca57
comment
bpkroth Jun 28, 2024
7ca2026
not ready for that one yet
bpkroth Jun 28, 2024
ebdd526
CI trigger
bpkroth Jun 28, 2024
e77f585
CI trigger
bpkroth Jun 28, 2024
04a674a
CI trigger
bpkroth Jun 28, 2024
2146d7a
CI trigger
bpkroth Jun 28, 2024
8ae75ec
Merge branch 'main' into makefile-improvements-with-incremental-support
bpkroth Jul 1, 2024
d68383b
Merge branch 'makefile-improvements-with-incremental-support' into py…
bpkroth Jul 1, 2024
2a74dbc
Leave those changes stagged in another PR for now
bpkroth Jul 1, 2024
f179046
revert for now
bpkroth Jul 1, 2024
0c0cc59
Fetch more of the history for Github CI workers
bpkroth Jul 1, 2024
f887ad8
Merge branch 'main' into pyproject-toml-build-changes
bpkroth Jul 1, 2024
a898393
make sure setuptools-scm is available from pip
bpkroth Jul 1, 2024
134b473
with a version
bpkroth Jul 1, 2024
03eae63
Merge branch 'pyproject-toml-build-changes' into prepare-isort-black-…
bpkroth Jul 1, 2024
f292abb
Merge branch 'main' into pyproject-toml-build-changes
bpkroth Jul 1, 2024
4782b7e
Merge branch 'main' into pyproject-toml-build-changes
bpkroth Jul 2, 2024
5c95cca
makefile fixups
bpkroth Jul 2, 2024
0f4840c
include more specific documentation urls
bpkroth Jul 2, 2024
0f7f4f4
docs also depend on unshallow repo
bpkroth Jul 2, 2024
7faa0ab
fixup windows build tests
bpkroth Jul 2, 2024
1db8351
Merge branch 'pyproject-toml-build-changes' into prepare-isort-black-…
bpkroth Jul 2, 2024
4d7bb2a
Merge branch 'main' into prepare-isort-black-formatters-and-checks
bpkroth Jul 2, 2024
7c096bd
Merge branch 'main' into prepare-isort-black-formatters-and-checks
bpkroth Jul 3, 2024
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
Prev Previous commit
Next Next commit
Prepare isort and black formatters and checks, but don't enable them …
…yet.
  • Loading branch information
bpkroth committed Jun 28, 2024
commit b9767d99b242ab345a79d78265f860694f497ee7
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
"lextudio.restructuredtext",
"matangover.mypy",
"ms-azuretools.vscode-docker",
"ms-python.autopep8",
"ms-python.flake8",
// TODO: Enable additional formatter extensions:
//"ms-python.black-formatter",
//"ms-python.isort",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
Expand Down
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"lextudio.restructuredtext",
"matangover.mypy",
"ms-azuretools.vscode-docker",
"ms-python.autopep8",
"ms-python.flake8",
// TODO: Enable additional formatter extensions:
//"ms-python.black-formatter",
//"ms-python.isort",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
Expand Down
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@
"--experimental"
],
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications"
// TODO: Enable black formatter
//"editor.defaultFormatter": "ms-python.black-formatter",
//"editor.formatOnSave": true,
//"editor.formatOnSaveMode": "modifications"
},
// See Also .vscode/launch.json for environment variable args to pytest during debug sessions.
// For the rest, see setup.cfg
Expand Down
113 changes: 111 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ ifneq (,$(filter format,$(MAKECMDGOALS)))
endif

build/format.${CONDA_ENV_NAME}.build-stamp: build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
# TODO: add isort and black formatters
# TODO: enable isort and black formatters
#build/format.${CONDA_ENV_NAME}.build-stamp: build/isort.${CONDA_ENV_NAME}.build-stamp
#build/format.${CONDA_ENV_NAME}.build-stamp: build/black.${CONDA_ENV_NAME}.build-stamp
build/format.${CONDA_ENV_NAME}.build-stamp:
touch $@

Expand All @@ -93,10 +95,117 @@ build/licenseheaders.${CONDA_ENV_NAME}.build-stamp:
-x mlos_bench/setup.py mlos_core/setup.py mlos_viz/setup.py
touch $@

.PHONY: isort
isort: build/isort.${CONDA_ENV_NAME}.build-stamp

ifneq (,$(filter isort,$(MAKECMDGOALS)))
FORMAT_PREREQS += build/isort.${CONDA_ENV_NAME}.build-stamp
endif

build/isort.${CONDA_ENV_NAME}.build-stamp: build/isort.mlos_core.${CONDA_ENV_NAME}.build-stamp
build/isort.${CONDA_ENV_NAME}.build-stamp: build/isort.mlos_bench.${CONDA_ENV_NAME}.build-stamp
build/isort.${CONDA_ENV_NAME}.build-stamp: build/isort.mlos_viz.${CONDA_ENV_NAME}.build-stamp
build/isort.${CONDA_ENV_NAME}.build-stamp:
touch $@

# NOTE: when using pattern rules (involving %) we can only add one line of
# prerequisities, so we use this pattern to compose the list as variables.

# Both isort and licenseheaders alter files, so only run one at a time, by
# making licenseheaders an order-only prerequisite.
ISORT_COMMON_PREREQS :=
ifneq (,$(filter format licenseheaders,$(MAKECMDGOALS)))
ISORT_COMMON_PREREQS += build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
endif
ISORT_COMMON_PREREQS += build/conda-env.${CONDA_ENV_NAME}.build-stamp
ISORT_COMMON_PREREQS += $(MLOS_GLOBAL_CONF_FILES)

build/isort.mlos_core.${CONDA_ENV_NAME}.build-stamp: $(MLOS_CORE_PYTHON_FILES)
build/isort.mlos_bench.${CONDA_ENV_NAME}.build-stamp: $(MLOS_BENCH_PYTHON_FILES)
build/isort.mlos_viz.${CONDA_ENV_NAME}.build-stamp: $(MLOS_VIZ_PYTHON_FILES)

build/isort.%.${CONDA_ENV_NAME}.build-stamp: $(ISORT_COMMON_PREREQS)
# Reformat python file imports with isort.
conda run -n ${CONDA_ENV_NAME} isort --verbose --only-modified --atomic -j0 $(filter %.py,$?)
touch $@

.PHONY: black
black: build/black.${CONDA_ENV_NAME}.build-stamp

ifneq (,$(filter black,$(MAKECMDGOALS)))
FORMAT_PREREQS += build/black.${CONDA_ENV_NAME}.build-stamp
endif

build/black.${CONDA_ENV_NAME}.build-stamp: build/black.mlos_core.${CONDA_ENV_NAME}.build-stamp
build/black.${CONDA_ENV_NAME}.build-stamp: build/black.mlos_bench.${CONDA_ENV_NAME}.build-stamp
build/black.${CONDA_ENV_NAME}.build-stamp: build/black.mlos_viz.${CONDA_ENV_NAME}.build-stamp
build/black.${CONDA_ENV_NAME}.build-stamp:
touch $@

# Both black, licenseheaders, and isort all alter files, so only run one at a time, by
# making licenseheaders and isort an order-only prerequisite.
BLACK_COMMON_PREREQS :=
ifneq (,$(filter format licenseheaders,$(MAKECMDGOALS)))
BLACK_COMMON_PREREQS += build/licenseheaders.${CONDA_ENV_NAME}.build-stamp
endif
ifneq (,$(filter format isort,$(MAKECMDGOALS)))
BLACK_COMMON_PREREQS += build/isort.${CONDA_ENV_NAME}.build-stamp
endif
BLACK_COMMON_PREREQS += build/conda-env.${CONDA_ENV_NAME}.build-stamp
BLACK_COMMON_PREREQS += $(MLOS_GLOBAL_CONF_FILES)

build/black.mlos_core.${CONDA_ENV_NAME}.build-stamp: $(MLOS_CORE_PYTHON_FILES)
build/black.mlos_bench.${CONDA_ENV_NAME}.build-stamp: $(MLOS_BENCH_PYTHON_FILES)
build/black.mlos_viz.${CONDA_ENV_NAME}.build-stamp: $(MLOS_VIZ_PYTHON_FILES)

build/black.%.${CONDA_ENV_NAME}.build-stamp: $(BLACK_COMMON_PREREQS)
# Reformat python files with black.
conda run -n ${CONDA_ENV_NAME} black $(filter %.py,$?)
touch $@

.PHONY: check
check: pycodestyle pydocstyle pylint mypy # cspell markdown-link-check
# TODO: add isort and black checks
# TODO: Enable isort and black checks
#check: isort-check black-check pycodestyle pydocstyle pylint mypy # cspell markdown-link-check

.PHONY: black-check
black-check: build/black-check.mlos_core.${CONDA_ENV_NAME}.build-stamp
black-check: build/black-check.mlos_bench.${CONDA_ENV_NAME}.build-stamp
black-check: build/black-check.mlos_viz.${CONDA_ENV_NAME}.build-stamp

# Make sure black format rules run before black-check rules.
build/black-check.mlos_core.${CONDA_ENV_NAME}.build-stamp: $(MLOS_CORE_PYTHON_FILES)
build/black-check.mlos_bench.${CONDA_ENV_NAME}.build-stamp: $(MLOS_BENCH_PYTHON_FILES)
build/black-check.mlos_viz.${CONDA_ENV_NAME}.build-stamp: $(MLOS_VIZ_PYTHON_FILES)

BLACK_CHECK_COMMON_PREREQS := build/conda-env.${CONDA_ENV_NAME}.build-stamp
BLACK_CHECK_COMMON_PREREQS += $(FORMAT_PREREQS)
BLACK_CHECK_COMMON_PREREQS += $(MLOS_GLOBAL_CONF_FILES)

build/black-check.%.${CONDA_ENV_NAME}.build-stamp: $(BLACK_CHECK_COMMON_PREREQS)
# Check for import sort order.
# Note: if this fails use "make format" or "make black" to fix it.
conda run -n ${CONDA_ENV_NAME} black --verbose --check --diff $(filter %.py,$?)
touch $@

.PHONY: isort-check
isort-check: build/isort-check.mlos_core.${CONDA_ENV_NAME}.build-stamp
isort-check: build/isort-check.mlos_bench.${CONDA_ENV_NAME}.build-stamp
isort-check: build/isort-check.mlos_viz.${CONDA_ENV_NAME}.build-stamp

# Make sure isort format rules run before isort-check rules.
build/isort-check.mlos_core.${CONDA_ENV_NAME}.build-stamp: $(MLOS_CORE_PYTHON_FILES)
build/isort-check.mlos_bench.${CONDA_ENV_NAME}.build-stamp: $(MLOS_BENCH_PYTHON_FILES)
build/isort-check.mlos_viz.${CONDA_ENV_NAME}.build-stamp: $(MLOS_VIZ_PYTHON_FILES)

ISORT_CHECK_COMMON_PREREQS := build/conda-env.${CONDA_ENV_NAME}.build-stamp
ISORT_CHECK_COMMON_PREREQS += $(FORMAT_PREREQS)
ISORT_CHECK_COMMON_PREREQS += $(MLOS_GLOBAL_CONF_FILES)

build/isort-check.%.${CONDA_ENV_NAME}.build-stamp: $(ISORT_CHECK_COMMON_PREREQS)
# Note: if this fails use "make format" or "make isort" to fix it.
conda run -n ${CONDA_ENV_NAME} isort --only-modified --check --diff -j0 $(filter %.py,$?)
touch $@

.PHONY: pycodestyle
pycodestyle: build/pycodestyle.mlos_core.${CONDA_ENV_NAME}.build-stamp
Expand Down
2 changes: 2 additions & 0 deletions conda-envs/mlos-3.10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -27,6 +28,7 @@ dependencies:
- autopep8>=1.7.0
- bump2version
- check-jsonschema
- isort
- licenseheaders
- mypy
- pandas-stubs
Expand Down
2 changes: 2 additions & 0 deletions conda-envs/mlos-3.11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -27,6 +28,7 @@ dependencies:
- autopep8>=1.7.0
- bump2version
- check-jsonschema
- isort
- licenseheaders
- mypy
- pandas-stubs
Expand Down
2 changes: 2 additions & 0 deletions conda-envs/mlos-3.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -27,6 +28,7 @@ dependencies:
- autopep8>=1.7.0
- bump2version
- check-jsonschema
- isort
- licenseheaders
- mypy
- pandas-stubs
Expand Down
2 changes: 2 additions & 0 deletions conda-envs/mlos-3.9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -27,6 +28,7 @@ dependencies:
- autopep8>=1.7.0
- bump2version
- check-jsonschema
- isort
- licenseheaders
- mypy
- pandas-stubs
Expand Down
2 changes: 2 additions & 0 deletions conda-envs/mlos-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -30,6 +31,7 @@ dependencies:
- autopep8>=1.7.0
- bump2version
- check-jsonschema
- isort
- licenseheaders
- mypy
- pandas-stubs
Expand Down
2 changes: 2 additions & 0 deletions conda-envs/mlos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
# All other dependencies for the mlos modules come from pip.
- pip
- pylint
- black
- pycodestyle
- pydocstyle
- flake8
Expand All @@ -26,6 +27,7 @@ dependencies:
- autopep8>=1.7.0
- bump2version
- check-jsonschema
- isort
- licenseheaders
- mypy
- pandas-stubs
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.black]
line-length = 88
target-version = ["py38", "py39", "py310", "py311", "py312"]
include = '\.pyi?$'

[tool.isort]
profile = "black"
py_version = 311
src_paths = ["mlos_core", "mlos_bench", "mlos_viz"]