Skip to content

Commit

Permalink
Switch project to an src/ based layout
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Mar 29, 2021
1 parent 7326243 commit 1daf13f
Show file tree
Hide file tree
Showing 56 changed files with 96 additions and 63 deletions.
9 changes: 2 additions & 7 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ relative_files = True
omit =
.nox/*
setup.py
saltfactories/__init__.py
saltfactories/version.py
saltfactories/utils/compat.py

[report]
# Regexes for lines to exclude from consideration
Expand All @@ -33,15 +30,13 @@ exclude_lines =
omit =
.nox/*
setup.py
saltfactories/__init__.py
saltfactories/version.py
saltfactories/utils/compat.py


ignore_errors = True

[paths]
source =
saltfactories/
src/saltfactories
**/site-packages/saltfactories
testsuite =
tests/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ salt-checkout/
artifacts/

# Ignore the setuptools_scm generated version file
saltfactories/version.py
src/saltfactories/version.py
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,37 @@ repos:
files: ^\.pylint-spelling-words$

- repo: https://github.com/asottile/pyupgrade
rev: v2.10.0
rev: v2.11.0
hooks:
- id: pyupgrade
name: Rewrite Code to be Py3.5+
args: [--py3-plus]
exclude: (^saltfactories/utils/salt/.*\.py)
exclude: (^src/saltfactories/utils/salt/.*\.py)

- repo: https://github.com/hakancelik96/unimport
rev: "31cc123640880e385159c719d2f12b5cf8586495"
hooks:
- id: unimport
name: Remove unused imports
args: [--remove]
exclude: ^(docs/.*\.py|saltfactories/factories/(cli|daemons)/__init__\.py)$
exclude: ^(docs/.*\.py|src/saltfactories/factories/(cli|daemons)/__init__\.py)$

- repo: https://github.com/asottile/reorder_python_imports
rev: v2.4.0
hooks:
- id: reorder-python-imports
args: [
--py3-plus,
--application-directories=.:src
]
exclude: saltfactories/version.py
exclude: src/saltfactories/version.py

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
args: [-l 100]
exclude: saltfactories/version.py
exclude: src/saltfactories/version.py

- repo: https://github.com/asottile/blacken-docs
rev: v1.7.0
Expand All @@ -68,7 +69,7 @@ repos:
- id: pylint
name: PyLint
args: [--output-format=parseable, --rcfile=.pylintrc]
exclude: saltfactories/version.py
exclude: src/saltfactories/version.py
additional_dependencies:
- saltpylint
- pyenchant
Expand Down
1 change: 1 addition & 0 deletions changelog/41.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch project to an ``src/`` based layout
20 changes: 12 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
#
import datetime
import os
import pathlib
import sys

try:
from importlib.metadata import version as pkg_version
except ImportError:
from importlib_metadata import version as pkg_version

import pytest
import sphinx_material_saltstack

Expand All @@ -23,21 +29,19 @@
pytest.helpers = HelpersRegistry()

try:
docs_basepath = os.path.abspath(os.path.dirname(__file__))
docs_basepath = pathlib.Path(__file__).resolve().parent
except NameError:
# sphinx-intl and six execute some code which will raise this NameError
# assume we're in the doc/ directory
docs_basepath = os.path.abspath(os.path.dirname("."))
docs_basepath = pathlib.Path(".").resolve().parent

addtl_paths = (
os.pardir, # saltfactories itself (for autodoc)
"_ext", # custom Sphinx extensions
docs_basepath / "_ext", # custom Sphinx extensions
docs_basepath.parent / "src", # saltfactories itself (for autodoc)
)

for addtl_path in addtl_paths:
sys.path.insert(0, os.path.abspath(os.path.join(docs_basepath, addtl_path)))

import saltfactories
sys.path.insert(0, addtl_path)


# -- Project information -----------------------------------------------------
Expand All @@ -51,7 +55,7 @@
author = "SaltStack, Inc."

# The full version, including alpha/beta/rc tags
release = saltfactories.__version__
release = pkg_version("pytest-salt-factories")


# Variables to pass into the docs from sitevars.rst for rst substitution
Expand Down
11 changes: 7 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# Change current directory to REPO_ROOT
os.chdir(str(REPO_ROOT))

SITECUSTOMIZE_DIR = str(REPO_ROOT / "saltfactories" / "utils" / "coverage")
SITECUSTOMIZE_DIR = str(REPO_ROOT / "src" / "saltfactories" / "utils" / "coverage")
ARTIFACTS_DIR = REPO_ROOT / "artifacts"
# Make sure the artifacts directory exists
ARTIFACTS_DIR.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -182,19 +182,19 @@ def tests(session):
"-o",
str(COVERAGE_REPORT_SALTFACTORIES),
"--omit=tests/*",
"--include=saltfactories/*",
"--include=src/saltfactories/*",
)
# Generate report for tests code coverage
session.run(
"coverage",
"xml",
"-o",
str(COVERAGE_REPORT_TESTS),
"--omit=saltfactories/*",
"--omit=src/saltfactories/*",
"--include=tests/*",
)
try:
cmdline = ["coverage", "report", "--show-missing", "--include=saltfactories/*,tests/*"]
cmdline = ["coverage", "report", "--show-missing", "--include=src/saltfactories/*,tests/*"]
if system_install is False:
cmdline.append("--fail-under={}".format(COVERAGE_FAIL_UNDER_PERCENT))
session.run(*cmdline)
Expand Down Expand Up @@ -279,6 +279,7 @@ def docs(session):
os.path.join("requirements", "docs.txt"),
silent=PIP_INSTALL_SILENT,
)
session.install("-e", ".", silent=PIP_INSTALL_SILENT)
os.chdir("docs/")
session.run("make", "clean", external=True)
session.run("make", "linkcheck", "SPHINXOPTS=-W", external=True)
Expand All @@ -304,6 +305,7 @@ def docs_crosslink_info(session):
os.path.join("requirements", "docs.txt"),
silent=PIP_INSTALL_SILENT,
)
session.install("-e", ".", silent=PIP_INSTALL_SILENT)
os.chdir("docs/")
intersphinx_mapping = json.loads(
session.run(
Expand Down Expand Up @@ -345,5 +347,6 @@ def gen_api_docs(session):
os.path.join("requirements", "docs.txt"),
silent=PIP_INSTALL_SILENT,
)
session.install("-e", ".", silent=PIP_INSTALL_SILENT)
shutil.rmtree("docs/ref")
session.run("sphinx-apidoc", "--module-first", "-o", "docs/ref/", "saltfactories/")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ requires = ["setuptools>=50.3.2", "wheel", "setuptools-declarative-requirements"
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "saltfactories/version.py"
write_to = "src/saltfactories/version.py"
write_to_template = "__version__ = \"{version}\""
36 changes: 0 additions & 36 deletions saltfactories/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ platforms = unix, linux, osx, cygwin, win32
[options]
zip_safe = False
include_package_data = True
package_dir =
=src
packages = find:
python_requires = >= 3.5
setup_requires =
Expand All @@ -36,6 +38,7 @@ setup_requires =
setuptools-declarative-requirements

[options.packages.find]
where = src
exclude =
tests*

Expand Down
62 changes: 62 additions & 0 deletions src/saltfactories/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
NG PyTest Salt Plugin
"""
# pragma: nocover
import pathlib
import re
import sys

try:
from .version import __version__
except ImportError:
__version__ = "0.0.0.not-installed"
try:
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("pytest-salt-factories")
except PackageNotFoundError:
# package is not installed
pass
except ImportError:
try:
from importlib_metadata import version, PackageNotFoundError

try:
__version__ = version("pytest-salt-factories")
except PackageNotFoundError:
# package is not installed
pass
except ImportError:
try:
from pkg_resources import get_distribution, DistributionNotFound

try:
__version__ = get_distribution("pytest-salt-factories").version
except DistributionNotFound:
# package is not installed
pass
except ImportError:
# pkg resources isn't even available?!
pass


# Define __version_info__ attribute
VERSION_INFO_REGEX = re.compile(
r"(?P<major>[\d]+)\.(?P<minor>[\d]+)\.(?P<patch>[\d]+)"
r"(?:\.dev(?P<commits>[\d]+)\+g(?P<sha>[a-z0-9]+)\.d(?P<date>[\d]+))?"
)
try:
__version_info__ = tuple(
[int(p) if p.isdigit() else p for p in VERSION_INFO_REGEX.match(__version__).groups() if p]
)
except AttributeError:
__version_info__ = (-1, -1, -1)
finally:
del VERSION_INFO_REGEX


# Define some constants
CODE_ROOT_DIR = pathlib.Path(__file__).resolve().parent
IS_WINDOWS = sys.platform.startswith("win")
IS_DARWIN = IS_OSX = sys.platform.startswith("darwin")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 1daf13f

Please sign in to comment.