Skip to content

Commit

Permalink
Merge pull request #24 from mxstack/path
Browse files Browse the repository at this point in the history
Set path and remove usage of MXENV_PATH and related
  • Loading branch information
jensens authored Feb 23, 2024
2 parents 1fbf391 + d097b27 commit 9690a88
Show file tree
Hide file tree
Showing 31 changed files with 84 additions and 130 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 1.0a4 (unreleased)

- Export `PATH` with virtual environment and node modules bin folders.

- Get rid of `MXENV_PATH`.

- Rename `PYTHON_BIN` to `PRIMARY_PYTHON` in `mxenv` domain.

- Use `python -m pip` all over the place instead of `pip` executable.
Expand Down
38 changes: 18 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ endif

# determine the executable path
ifeq ("$(VENV_ENABLED)", "true")
MXENV_PATH=$(VENV_FOLDER)/bin/
MXENV_PYTHON=$(MXENV_PATH)python
export PATH:=$(shell pwd)/$(VENV_FOLDER)/bin/:$(PATH)
export VIRTUAL_ENV=$(VENV_FOLDER)
MXENV_PYTHON=python
else
MXENV_PATH=
MXENV_PYTHON=$(PRIMARY_PYTHON)
endif

Expand Down Expand Up @@ -249,12 +249,12 @@ $(RUFF_TARGET): $(MXENV_TARGET)
.PHONY: ruff-check
ruff-check: $(RUFF_TARGET)
@echo "Run ruff check"
@$(MXENV_PATH)ruff check $(RUFF_SRC)
@ruff check $(RUFF_SRC)

.PHONY: ruff-format
ruff-format: $(RUFF_TARGET)
@echo "Run ruff format"
@$(MXENV_PATH)ruff format $(RUFF_SRC)
@ruff format $(RUFF_SRC)

.PHONY: ruff-dirty
ruff-dirty:
Expand Down Expand Up @@ -284,12 +284,12 @@ $(ISORT_TARGET): $(MXENV_TARGET)
.PHONY: isort-check
isort-check: $(ISORT_TARGET)
@echo "Run isort check"
@$(MXENV_PATH)isort --check $(ISORT_SRC)
@isort --check $(ISORT_SRC)

.PHONY: isort-format
isort-format: $(ISORT_TARGET)
@echo "Run isort format"
@$(MXENV_PATH)isort $(ISORT_SRC)
@isort $(ISORT_SRC)

.PHONY: isort-dirty
isort-dirty:
Expand All @@ -312,8 +312,8 @@ CLEAN_TARGETS+=isort-clean
# additional targets required for building docs.
DOCS_TARGETS+=

SPHINX_BIN=$(MXENV_PATH)sphinx-build
SPHINX_AUTOBUILD_BIN=$(MXENV_PATH)sphinx-autobuild
SPHINX_BIN=sphinx-build
SPHINX_AUTOBUILD_BIN=sphinx-autobuild

DOCS_TARGET:=$(SENTINEL_FOLDER)/sphinx.sentinel
$(DOCS_TARGET): $(MXENV_TARGET)
Expand Down Expand Up @@ -357,13 +357,11 @@ MXMAKE_FILES?=$(MXMAKE_FOLDER)/files

# set environment variables for mxmake
define set_mxfiles_env
@export MXMAKE_MXENV_PATH=$(1)
@export MXMAKE_FILES=$(2)
@export MXMAKE_FILES=$(1)
endef

# unset environment variables for mxmake
define unset_mxfiles_env
@unset MXMAKE_MXENV_PATH
@unset MXMAKE_FILES
endef

Expand All @@ -380,9 +378,9 @@ FILES_TARGET:=requirements-mxdev.txt
$(FILES_TARGET): $(PROJECT_CONFIG) $(MXENV_TARGET) $(SOURCES_TARGET) $(LOCAL_PACKAGE_FILES)
@echo "Create project files"
@mkdir -p $(MXMAKE_FILES)
$(call set_mxfiles_env,$(MXENV_PATH),$(MXMAKE_FILES))
@$(MXENV_PATH)mxdev -n -c $(PROJECT_CONFIG)
$(call unset_mxfiles_env,$(MXENV_PATH),$(MXMAKE_FILES))
$(call set_mxfiles_env,$(MXMAKE_FILES))
@mxdev -n -c $(PROJECT_CONFIG)
$(call unset_mxfiles_env)
@test -e $(MXMAKE_FILES)/pip.conf && cp $(MXMAKE_FILES)/pip.conf $(VENV_FOLDER)/pip.conf || :
@touch $(FILES_TARGET)

Expand Down Expand Up @@ -508,7 +506,7 @@ $(MYPY_TARGET): $(MXENV_TARGET)
.PHONY: mypy
mypy: $(PACKAGES_TARGET) $(MYPY_TARGET)
@echo "Run mypy"
@$(MXENV_PATH)mypy $(MYPY_SRC)
@mypy $(MYPY_SRC)

.PHONY: mypy-dirty
mypy-dirty:
Expand Down Expand Up @@ -537,22 +535,22 @@ $(ZEST_RELEASER_TARGET): $(MXENV_TARGET)
.PHONY: zest-releaser-prerelease
zest-releaser-prerelease: $(ZEST_RELEASER_TARGET)
@echo "Run prerelease"
@$(MXENV_PATH)prerelease
@prerelease

.PHONY: zest-releaser-release
zest-releaser-release: $(ZEST_RELEASER_TARGET)
@echo "Run release"
@$(MXENV_PATH)release
@release

.PHONY: zest-releaser-postrelease
zest-releaser-postrelease: $(ZEST_RELEASER_TARGET)
@echo "Run postrelease"
@$(MXENV_PATH)postrelease
@postrelease

.PHONY: zest-releaser-fullrelease
zest-releaser-fullrelease: $(ZEST_RELEASER_TARGET)
@echo "Run fullrelease"
@$(MXENV_PATH)fullrelease
@fullrelease

.PHONY: zest-releaser-dirty
zest-releaser-dirty:
Expand Down
2 changes: 0 additions & 2 deletions src/mxmake/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from mxmake.topics import Domain
from mxmake.topics import load_topics
from mxmake.utils import gh_actions_path
from mxmake.utils import mxenv_path
from mxmake.utils import mxmake_files
from mxmake.utils import ns_name

Expand Down Expand Up @@ -158,7 +157,6 @@ def template_variables(self) -> typing.Dict[str, typing.Any]:
return dict(
description=self.description,
env=self.env,
mxenv_path=mxenv_path(),
testpaths=self.package_paths(ns_name("test-path")),
)

Expand Down
6 changes: 3 additions & 3 deletions src/mxmake/templates/pytest-run-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ omits=$(printf ",%s" "${omits[@]}")
omits=${omits:1}
{%- endif %}

{{ mxenv_path }}coverage run \
coverage run \
--source=$sources \
{% if omitpaths %}
--omit=$omits \
Expand All @@ -32,6 +32,6 @@ omits=${omits:1}

{% endfor %}

{{ mxenv_path }}coverage report
{{ mxenv_path }}coverage html
coverage report
coverage html
{% endblock %}
2 changes: 1 addition & 1 deletion src/mxmake/templates/pytest-run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "env.sh" %}

{% block env_content %}
{{ mxenv_path }}pytest \
pytest \
{% for path in testpaths %}
{{ path }}{% if not loop.last %} \{% endif %}

Expand Down
6 changes: 3 additions & 3 deletions src/mxmake/templates/zope-testrunner-run-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ omits=$(printf ",%s" "${omits[@]}")
omits=${omits:1}
{%- endif %}

{{ mxenv_path }}coverage run \
coverage run \
--source=$sources \
{% if omitpaths %}
--omit=$omits \
Expand All @@ -32,6 +32,6 @@ omits=${omits:1}

{% endfor %}

{{ mxenv_path }}coverage report
{{ mxenv_path }}coverage html
coverage report
coverage html
{% endblock %}
2 changes: 1 addition & 1 deletion src/mxmake/templates/zope-testrunner-run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "env.sh" %}

{% block env_content %}
{{ mxenv_path }}zope-testrunner --auto-color --auto-progress \
zope-testrunner --auto-color --auto-progress \
{% for path in testpaths %}
--test-path={{ path }} \
{% endfor %}
Expand Down
2 changes: 0 additions & 2 deletions src/mxmake/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def __call__(self, fn: typing.Callable):
def wrapper(*a):
tempdir = tempfile.mkdtemp()
os.environ["MXMAKE_FILES"] = tempdir
os.environ["MXMAKE_MXENV_PATH"] = tempdir
os.environ["MXMAKE_GH_ACTIONS_PATH"] = tempdir
try:
if self.reset_registry:
Expand All @@ -51,7 +50,6 @@ def wrapper(*a):
finally:
shutil.rmtree(tempdir)
del os.environ["MXMAKE_FILES"]
del os.environ["MXMAKE_MXENV_PATH"]
del os.environ["MXMAKE_GH_ACTIONS_PATH"]

return wrapper
Expand Down
41 changes: 17 additions & 24 deletions src/mxmake/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def test_TestScript(self, tempdir):
"description": "Run tests",
"env": {"ENV_PARAM": "env_value"},
"testpaths": ["sources/package/src", "src"],
"mxenv_path": tempdir + os.path.sep,
},
)
self.assertEqual(template.package_paths("inexistent"), [])
Expand Down Expand Up @@ -181,14 +180,11 @@ def test_TestScript(self, tempdir):
trap unsetenv ERR INT
setenv
/.../zope-testrunner --auto-color --auto-progress \\
zope-testrunner --auto-color --auto-progress \\
--test-path=sources/package/src \\
--test-path=src \\
--module=$1
unsetenv
exit 0
""",
f.read(),
Expand Down Expand Up @@ -217,7 +213,7 @@ def test_TestScript(self, tempdir):
# Run tests
set -e
/.../zope-testrunner --auto-color --auto-progress \\
zope-testrunner --auto-color --auto-progress \\
--test-path=sources/package/src \\
--module=$1
Expand Down Expand Up @@ -249,7 +245,7 @@ def test_TestScript(self, tempdir):
# Run tests
set -e
/.../pytest \\
pytest \\
sources/package/src
exit 0
Expand Down Expand Up @@ -303,7 +299,6 @@ def test_CoverageScript(self, tempdir):
"src/local/file1.py",
"src/local/file2.py",
],
"mxenv_path": tempdir + os.path.sep,
},
)
self.assertEqual(template.package_paths("inexistent"), [])
Expand Down Expand Up @@ -348,7 +343,6 @@ def test_CoverageScript(self, tempdir):
trap unsetenv ERR INT
setenv
sources=(
sources/package/src/package
src/local
Expand All @@ -366,19 +360,16 @@ def test_CoverageScript(self, tempdir):
omits=$(printf ",%s" "${omits[@]}")
omits=${omits:1}
/.../coverage run \\
coverage run \\
--source=$sources \\
--omit=$omits \\
-m zope.testrunner --auto-color --auto-progress \\
--test-path=sources/package/src \\
--test-path=src
/.../coverage report
/.../coverage html
coverage report
coverage html
unsetenv
exit 0
""",
f.read(),
Expand Down Expand Up @@ -415,13 +406,14 @@ def test_CoverageScript(self, tempdir):
sources=$(printf ",%s" "${sources[@]}")
sources=${sources:1}
/.../coverage run \\
coverage run \\
--source=$sources \\
-m zope.testrunner --auto-color --auto-progress \\
--test-path=sources/package/src
/.../coverage report
/.../coverage html
coverage report
coverage html
exit 0
""",
Expand Down Expand Up @@ -459,13 +451,14 @@ def test_CoverageScript(self, tempdir):
sources=$(printf ",%s" "${sources[@]}")
sources=${sources:1}
/.../coverage run \\
coverage run \\
--source=$sources \\
-m pytest \\
sources/package/src
/.../coverage report
/.../coverage html
coverage report
coverage html
exit 0
""",
Expand Down Expand Up @@ -665,10 +658,10 @@ def test_Makefile(self, tempdir):
# determine the executable path
ifeq ("$(VENV_ENABLED)", "true")
MXENV_PATH=$(VENV_FOLDER)/bin/
MXENV_PYTHON=$(MXENV_PATH)python
export PATH:=$(shell pwd)/$(VENV_FOLDER)/bin/:$(PATH)
export VIRTUAL_ENV=$(VENV_FOLDER)
MXENV_PYTHON=python
else
MXENV_PATH=
MXENV_PYTHON=$(PRIMARY_PYTHON)
endif
Expand Down
8 changes: 0 additions & 8 deletions src/mxmake/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ class TestUtils(unittest.TestCase):
def test_namespace(self):
self.assertEqual(utils.NAMESPACE, "mxmake-")

def test_mxenv_path(self):
self.assertEqual(utils.mxenv_path(), os.path.join("venv", "bin") + os.path.sep)
os.environ["MXMAKE_MXENV_PATH"] = "other"
self.assertEqual(utils.mxenv_path(), "other" + os.path.sep)
os.environ["MXMAKE_MXENV_PATH"] = ""
self.assertEqual(utils.mxenv_path(), "")
del os.environ["MXMAKE_MXENV_PATH"]

def test_mxmake_files(self):
self.assertEqual(utils.mxmake_files(), os.path.join(".mxmake", "files"))
os.environ["MXMAKE_FILES"] = "other"
Expand Down
2 changes: 1 addition & 1 deletion src/mxmake/topics/applications/twisted.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $(TWISTED_TARGET): $(MXENV_TARGET)
.PHONY: twisted-start
twisted-start: $(TWISTED_TARGET)
@echo "Run Twisted"
@$(MXENV_PATH)twistd $(TWISTED_TWISTD_OPTIONS) $(TWISTED_TAC_FILE)
@twistd $(TWISTED_TWISTD_OPTIONS) $(TWISTED_TAC_FILE)

.PHONY: twisted-dirty
twisted-dirty:
Expand Down
8 changes: 4 additions & 4 deletions src/mxmake/topics/applications/zest-releaser.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ $(ZEST_RELEASER_TARGET): $(MXENV_TARGET)
.PHONY: zest-releaser-prerelease
zest-releaser-prerelease: $(ZEST_RELEASER_TARGET)
@echo "Run prerelease"
@$(MXENV_PATH)prerelease
@prerelease

.PHONY: zest-releaser-release
zest-releaser-release: $(ZEST_RELEASER_TARGET)
@echo "Run release"
@$(MXENV_PATH)release
@release

.PHONY: zest-releaser-postrelease
zest-releaser-postrelease: $(ZEST_RELEASER_TARGET)
@echo "Run postrelease"
@$(MXENV_PATH)postrelease
@postrelease

.PHONY: zest-releaser-fullrelease
zest-releaser-fullrelease: $(ZEST_RELEASER_TARGET)
@echo "Run fullrelease"
@$(MXENV_PATH)fullrelease
@fullrelease

.PHONY: zest-releaser-dirty
zest-releaser-dirty:
Expand Down
Loading

0 comments on commit 9690a88

Please sign in to comment.