Skip to content

Commit

Permalink
Merge pull request #8 from znd4/get-build-working
Browse files Browse the repository at this point in the history
Attempt to get pdm build working
  • Loading branch information
znd4 committed Nov 13, 2023
2 parents 00bb167 + 98a5dcb commit f371c26
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1,479 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
with:
# cache to runner
path: hatch-cache
key: ${{ hashFiles('pyproject.toml') }}
key: ${{ hashFiles('pyproject.toml') }}-${{ matrix.python-version }}
- name: Install dependencies
run: pip install hatch
- name: Run Tests
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ repos:
rev: v1.6.1
hooks:
- id: mypy
additional_dependencies:
- types-toml
1,475 changes: 0 additions & 1,475 deletions pdm.lock

This file was deleted.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ Homepage = "https://github.com/zdog234/pdm-dotenv"
source = "vcs"

[tool.hatch.envs.default]
dependencies = ["pytest>=6.1", "pdm[pytest]>=2.5.2", "pytest-cov>=4.0.0"]
dependencies = [
"pytest>=6.1",
"pdm[pytest]>=2.5.2",
"pytest-cov>=4.0.0",
"python-dotenv[cli]",
"toml",
]

scripts.test = "pytest {args:tests}"
scripts.test-cov = "pytest --cov=src {args:tests}"
Expand Down
4 changes: 2 additions & 2 deletions src/pdm_dotenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any
import dotenv
from pdm.project import ConfigItem, Project
from pdm.signals import pre_run
from pdm.signals import pre_invoke
from pdm.core import Core


Expand All @@ -23,4 +23,4 @@ def plugin(core: Core) -> None:
"dotenv.path",
ConfigItem("Path to your .env file", ".env", env_var="PDM_DOTENV_PATH"),
)
pre_run.connect(load_dotenv)
pre_invoke.connect(load_dotenv)
41 changes: 41 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pdm.cli.actions import textwrap
from pdm.project import Project
from typing import TYPE_CHECKING
import toml

if TYPE_CHECKING:
from pdm.pytest import PDMCallable
Expand All @@ -21,12 +22,52 @@ def check_env(project: Project, pdm: "PDMCallable") -> None:
"""
),
],
strict=True,
obj=project,
)

assert (project.root / "foo.txt").read_text().strip() == "hello", result.outputs


def test_build(project: Project, pdm: "PDMCallable") -> None:
"""
pdm build should pick up and use environment variable
e.g. PDM_BUILD_ISOLATION
desc: Isolate the build environment from the project environment
default: True
"""
exp_ver = "1.2.3"
(project.root / ".env").write_text(f"PDM_BUILD_ISOLATION=false\nVERSION={exp_ver}")
# setup.py that includes environment variable FOO_BAR in the package
(project.root / "setup.py").write_text(
textwrap.dedent(
"""
import os
from setuptools import setup
version = os.environ.get("VERSION", "0.0.1")
setup(
name="foo",
version=version,
)
"""
)
)
pyproject_toml = toml.loads((project.root / "pyproject.toml").read_text())
del pyproject_toml["project"]
pyproject_toml["build-system"] = {
"requires": ["setuptools", "wheel"],
"build-backend": "setuptools.build_meta",
}
(project.root / "pyproject.toml").write_text(toml.dumps(pyproject_toml))

pdm(
["build"],
strict=True,
obj=project,
)
assert (project.root / "dist" / f"foo-{exp_ver}-py3-none-any.whl").exists()


def test_happy_path(project: Project, pdm: "PDMCallable") -> None:
(project.root / ".env").write_text("FOO_BAR_BAZ=hello")

Expand Down

0 comments on commit f371c26

Please sign in to comment.