Skip to content

Commit

Permalink
feat: update build system
Browse files Browse the repository at this point in the history
  • Loading branch information
kuisathaverat committed Feb 16, 2024
1 parent ff8b459 commit ab1060a
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 216 deletions.
91 changes: 27 additions & 64 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,11 @@ OTEL_SERVICE_NAME ?= "pytest_otel_test"
OTEL_EXPORTER_OTLP_INSECURE ?= True
OTEL_EXPORTER_OTLP_HEADERS ?=
TRACEPARENT ?=
REPO_URL ?= https://upload.pypi.org/legacy/
DEMO_DIR ?= docs/demos

VENV ?= .venv
PYTHON ?= python3
PIP ?= pip3
GH_VERSION = 1.0.0

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS_FLAG := linux
endif
ifeq ($(UNAME_S),Darwin)
OS_FLAG := macOS
endif
UNAME_P := $(shell uname -m)
ifeq ($(UNAME_P),x86_64)
ARCH_FLAG := amd64
endif
ifneq ($(filter %86,$(UNAME_P)),)
ARCH_FLAG := i386
endif
GH_BINARY = gh_$(GH_VERSION)_$(OS_FLAG)_$(ARCH_FLAG)
GH = $(CURDIR)/bin/gh

export UID=$(shell id -u)
export GID=$(shell id -g)

SHELL = /bin/bash
.SILENT:
Expand All @@ -43,55 +21,44 @@ help:
@echo ""
@grep '^## @help' Makefile|cut -d ":" -f 2-3|( (sort|column -s ":" -t) || (sort|tr ":" "\t") || (tr ":" "\t"))

bin:
mkdir bin

bin/gh: bin
curl -sSfL https://github.com/cli/cli/releases/download/v$(GH_VERSION)/$(GH_BINARY).tar.gz|tar xz
mv $(GH_BINARY)/bin/gh bin/gh
rm -fr $(GH_BINARY)

## @help:virtualenv:Create a Python virtual environment.
.PHONY: virtualenv
virtualenv:
$(PYTHON) --version
test -d $(VENV) || $(PYTHON) -m venv $(VENV);\
source $(VENV)/bin/activate;\
$(PIP) install -q -r requirements.txt;

## @help:install:Install APM CLI in a Python virtual environment.
.PHONY: install
install: virtualenv
source $(VENV)/bin/activate;\
$(PIP) install .;
source $(VENV)/bin/activate; \
$(PIP) install ".[test]";

## @help:test:Run the test.
.PHONY: test
test: virtualenv install
test: virtualenv
source $(VENV)/bin/activate;\
pytest --capture=no -p pytester --runpytest=subprocess \
$(PYTHON) -m pytest --capture=no -p pytester --runpytest=subprocess \
--junitxml $(CURDIR)/junit-test_pytest_otel.xml \
tests/test_pytest_otel.py;

## @help:test:Run the test.
.PHONY: test
it-test: virtualenv install
it-test: virtualenv
set -e;\
source $(VENV)/bin/activate;\
for test in tests/it/test_*.py; \
do \
pytest --capture=no -p pytester --runpytest=subprocess \
$(PYTHON) -m pytest --capture=no -p pytester --runpytest=subprocess \
--junitxml $(CURDIR)/junit-$$(basename $${test}).xml \
$${test}; \
done;
#pytest --capture=no -p pytester --runpytest=subprocess tests/it/test_*.py;

## @help:coverage:Report coverage.
.PHONY: coverage
coverage: virtualenv
## @help:format:Format the code.
format: virtualenv
source $(VENV)/bin/activate;\
$(PYTHON) -m black src/pytest_otel tests;

## @help:test-coverage:Report coverage.
.PHONY: test-coverage
test-coverage: virtualenv
source $(VENV)/bin/activate;\
coverage run --source=otel -m pytest; \
coverage report -m;
pytest --cov=pytest_otel --capture=no -p pytester --runpytest=subprocess tests/test_pytest_otel.py;

## @precomit:pre-commit:Run precommit hooks.
lint: virtualenv
Expand All @@ -107,13 +74,12 @@ clean:
@find . -type f -name "*.py[co]" -delete
@find . -type d -name "__pycache__" -delete
@find . -name '*~' -delete
-@rm -fr src/pytest_otel.egg-info *.egg-info build dist $(VENV) bin .tox .mypy_cache .pytest_cache otel-traces-file-output.json test_spans.json temp junit-*.xml
-@rm -fr src/pytest_otel.egg-info *.egg-info build dist $(VENV) bin .tox .mypy_cache .pytest_cache otel-traces-file-output.json test_spans.json temp junit-*.xml .coverage*

package: virtualenv
## @help:build:Build the Python project package.
build: virtualenv
source $(VENV)/bin/activate;\
set +xe; \
pip install wheel; \
$(PYTHON) setup.py sdist bdist_wheel
$(PYTHON) -m build

## @help:run-otel-collector:Run OpenTelemetry collector in debug mode.
.PHONY: run-otel-collector
Expand All @@ -125,31 +91,28 @@ run-otel-collector:
--name otelcol otel/opentelemetry-collector \
--config otel-config.yaml; \

#https://upload.pypi.org/legacy/
#https://test.pypi.org/legacy/
#secret/observability-team/ci/apm-agent-python-pypi-test
#secret/observability-team/ci/apm-agent-python-pypi-prod
# https://upload.pypi.org/legacy/
# https://test.pypi.org/legacy/
## @help:publish REPO_URL=${REPO_URL} TWINE_USER=${TWINE_USER} TWINE_PASSWORD=${TWINE_PASSWORD}:Publish the Python project in a PyPI repository.
.PHONY: publish
publish: package
publish: build
set +xe; \
source $(VENV)/bin/activate;\
$(PYTHON) -m pip install twine;\
echo "Uploading to $${REPO_URL} with user $${TWINE_USER}";\
python -m twine upload --username "$${TWINE_USER}" --password "$${TWINE_PASSWORD}" --skip-existing --repository-url $${REPO_URL} dist/*.tar.gz;\
python -m twine upload --username "$${TWINE_USER}" --password "$${TWINE_PASSWORD}" --skip-existing --repository-url $${REPO_URL} dist/*.whl
echo "Uploading to $${REPO_URL}";\
$(PYTHON) -m twine upload --username "$${TWINE_USER}" --password "$${TWINE_PASSWORD}" --skip-existing --repository-url $${REPO_URL} dist/*.tar.gz;\
$(PYTHON) -m twine upload --username "$${TWINE_USER}" --password "$${TWINE_PASSWORD}" --skip-existing --repository-url $${REPO_URL} dist/*.whl

## @help:demo-start-DEMO_NAME:Starts the demo from the demo folder, DEMO_NAME is the name of the demo type folder in the docs/demos folder (jaeger, elastic).
.PHONY: demo-start-%
demo-start-%: virtualenv install
demo-start-%: virtualenv
$(MAKE) demo-stop-$*
mkdir -p $(DEMO_DIR)/$*/build
touch $(DEMO_DIR)/$*/build/tests.json
docker-compose -f $(DEMO_DIR)/$*/docker-compose.yml up -d
. $(DEMO_DIR)/$*/demo.env;\
env | grep OTEL;\
source $(VENV)/bin/activate;\
pytest --capture=no docs/demos/test/test_demo.py || echo "Demo execution finished you can access to http://localhost:5601 to check the traces, the user is 'admin' and the password 'changeme'";
$(PYTHON) -m pytest --capture=no docs/demos/test/test_demo.py || echo "Demo execution finished you can access to http://localhost:5601 to check the traces, the user is 'admin' and the password 'changeme'";

## @help:demo-stop-DEMO_NAME:Stops the demo from the demo folder, DEMO_NAME is the name of the demo type folder in the docs/demos folder (jaeger, elastic).
.PHONY: demo-stop-%
Expand Down
18 changes: 0 additions & 18 deletions mypy.ini

This file was deleted.

131 changes: 124 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,92 @@
[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "pytest_otel"
dynamic = ["version"]
description = "OpenTelemetry plugin for Pytest"
readme = {file = "README.md", content-type = "text/markdown"}
authors = [
{name = "Ivan Fernandez Calvo (kuisathaverat)"}
]
dependencies = [
"opentelemetry-api==1.15.0",
"opentelemetry-exporter-otlp==1.15.0",
"opentelemetry-sdk==1.15.0",
"pytest==7.1.3",
"opentelemetry-api==1.15.0",
"opentelemetry-exporter-otlp==1.15.0",
"opentelemetry-sdk==1.15.0",
"pytest==7.1.3",
]
requires-python = ">= 3.8"
license = {file = "LICENSE"}
keywords = ["pytest", "otel", "opentelemetry", "debug"]
classifiers = [
"Environment :: Plugins",
"Framework :: Pytest",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
]
[project_urls]
Homepage = "https://github.com/kuisathaverat/pytest_otel"
Documentation = "https://github.com/kuisathaverat/pytest_otel/blob/main/README.md"
Repository = "https://github.com/kuisathaverat/pytest_otel.git"
Issues = "https://github.com/kuisathaverat/pytest_otel/issues"
Changelog = "https://github.com/kuisathaverat/pytest_otel/releases"

[build-system]
requires = ["setuptools >= 44.0.0", "wheel >= 0.30"]
build-backend = "setuptools.build_meta"
[project.optional-dependencies]
test = [
"pytest-cov==4.1.0",
"pre-commit==3.6.1",
"pytest-docker==3.1.1",
"mypy==1.8.0",
"black==24.2.0",
"flake8==7.0.0",
"build==1.0.3",
"twine==5.0.0",
]

[tool.setuptools.dynamic]
version = {attr = "pytest_otel.__version__"}

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
pytest_otel = ["py.typed"]

[project.entry-points.pytest11]
pytest_otel = "pytest_otel"

[tool.pytest]
addopts = "-ra --showlocals -vv"
testpaths = "tests"
xfail_strict = true
junit_family = "xunit2"

[tool.distutils.bdist_wheel]
universal = true

[tool.flake8]
max-line-length = "120"
ignore = [
"F401", "H301", "E203", "SC200", "SC100", "W503",
]
exclude = [
".venv",
".git",
"__pycache__",
".tox",
".mypy_cache",
]

[tool.black]
line-length = 120
Expand All @@ -24,3 +103,41 @@ exclude = '''
| tests/data
)/
'''

[tool.coverage.run]
source = [ "src", "tests" ]
parallel = true
branch = true
dynamic_context = "test_function"

[tool.coverage.report]
fail_under = "100"
skip_covered = true
show_missing = true

[tool.coverage.html]
show_contexts = true
skip_covered = false
skip_empty = false

[tool.coverage.paths]
source = [ "src" ]

[tool.mypy]
python_version = "3.8"
allow_untyped_defs = true
allow_untyped_calls = true
disallow_any_generics = true
disallow_subclassing_any = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
show_error_codes = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = false
warn_no_return = true
warn_return_any = true
implicit_reexport = false
strict_equality = true
warn_unused_configs = true
pretty = true
Loading

0 comments on commit ab1060a

Please sign in to comment.