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

Convert project to use a src layout #22

Merged
merged 11 commits into from
Oct 6, 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
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error_summary = true
files =
packaging/,
tests/,
propcache/
src/propcache/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdraco I concluded that it's possible to just have src/ here and then, this config can be synchronized across projects w/o needing to adjust project-specific names. Also, this list was supposed to be sorted so it'd be packaging, src, tests.


# check_untyped_defs = true

Expand Down
1 change: 1 addition & 0 deletions CHANGES/22.packaging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Converted project to use a src layout -- by :user:`bdraco`.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYXS = $(wildcard propcache/*.pyx)
PYXS = $(wildcard src/propcache/*.pyx)
SRC = propcache tests

all: test
Expand All @@ -15,8 +15,8 @@ all: test
touch .install-cython


propcache/%.c: propcache/%.pyx
python -m cython -3 -o $@ $< -I propcache
src/propcache/%.c: src/propcache/%.pyx
python -m cython -3 -o $@ $< -I src/propcache


.cythonize: .install-cython $(PYXS:.pyx=.c)
Expand All @@ -25,7 +25,7 @@ propcache/%.c: propcache/%.pyx
cythonize: .cythonize


.develop: .install-deps $(shell find propcache -type f)
.develop: .install-deps $(shell find src/propcache -type f)
@pip install -e .
@touch .develop

Expand All @@ -39,15 +39,15 @@ endif
lint: fmt

test: lint .develop
pytest ./tests ./propcache
pytest ./tests


vtest: lint .develop
pytest ./tests ./propcache -v
pytest -v ./tests


cov: lint .develop
pytest --cov propcache --cov-report html --cov-report term ./tests/ ./propcache/
pytest --cov src/propcache --cov-report html --cov-report term ./tests
@echo "open file://`pwd`/htmlcov/index.html"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdraco with .coveragerc having all the necessary configuration, the pytest invocations should just have the --cov option without any arguments, which also makes sure that other parts of the layout are measured.

This probably also causes these weird paths under /Users/ to show up, like https://app.codecov.io/gh/aio-libs/propcache/tree/master/Users%2Frunner%2Fwork%2Fpropcache%2Fpropcache%2Fsrc%2Fpropcache. And I see that .py files are displayed on the top level, while .pyx are under src/ on Codecov.

--cov corresponds to the source = setting in Coveragepy which accepts both importable identifiers and file paths, which is ambiguous. To make it cleaner, .coveragerc marks the entire project as source and specifies source_pkgs which only works with importables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. there's actually another place that is missing — .coveragerc's path mapping doesn't take into account src which is likely one of the main causes of broken path mapping. Drop in this section https://github.com/ansible/awx_plugins.interfaces/blob/fc44b24/.coveragerc#L5-L12 to fix it. It maps src to site-packages w/o using project-specific names, which makes it copy-paste-friendly too.



Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@


_docs_path = Path(__file__).parent
_version_path = _docs_path / "../propcache/__init__.py"

_version_path = _docs_path / "../src/propcache/__init__.py"

with _version_path.open() as fp:
try:
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ requote
requoting
runtimes
sdist
src
subclass
subclasses
subcomponent
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build-backend = "pep517_backend.hooks" # wraps `setuptools.build_meta`

[tool.local.cythonize]
# This attr can contain multiple globs
src = ["propcache/*.pyx"]
src = ["src/propcache/*.pyx"]

[tool.local.cythonize.env]
# Env vars provisioned during cythonize call
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ norecursedirs =

testpaths = tests/

pythonpath = src

xfail_strict = true
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ python_requires = >=3.8
# Ref:
# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#using-a-src-layout
# (`src/` layout)
# package_dir =
# = src
package_dir =
=src
packages =
propcache

# https://setuptools.pypa.io/en/latest/deprecated/zip_safe.html
zip_safe = False
include_package_data = True
Expand All @@ -71,6 +72,7 @@ include_package_data = True
# (see notes for the asterisk/`*` meaning)
* =
*.so
*.pyx

[options.exclude_package_data]
* =
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading