Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: fix problems with windows commands#942

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
codejedi365 merged 11 commits intopython-semantic-release:masterfromJCHacking:fix_windows_build_command
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
0befe0e
fix: problems with windows commands
JCHackingMay 30, 2024
c91bad6
test: add windows environment variables in tests
JCHackingJun 1, 2024
b7ff364
docs: add windows environment variables in documentation
JCHackingJun 1, 2024
1c7bf76
refactor: extract get windows environment variables
JCHackingJun 2, 2024
556cb9e
chore: add all variables documented
JCHackingJun 2, 2024
508f182
chore: only add windows environment variables in windows systems
JCHackingJun 2, 2024
cec24a9
docs: add windows environment variables in documentation
jmencianaranjo-ionosJun 3, 2024
397ae60
style: apply style in version.py
jmencianaranjo-ionosJun 3, 2024
d5247d5
test: add tests for run command with windows
jmencianaranjo-ionosJun 3, 2024
242f87e
chore: use patched_os_environment and formated with ruff
jmencianaranjo-ionosJun 4, 2024
f5cbef6
chore: use patched_os_environment and formated with ruff
jmencianaranjo-ionosJun 4, 2024
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
27 changes: 27 additions & 0 deletionsdocs/configuration.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -207,6 +207,33 @@ PSR_DOCKER_GITHUB_ACTION Pass-through ``true`` if exists in process env, unset
VIRTUAL_ENV Pass-through ``VIRTUAL_ENV`` if exists in process env, unset otherwise
======================== ======================================================================

In addition, on windows systems these environment variables are passed:
======================== ======================================================================
Variable Name Description
======================== ======================================================================
ALLUSERSAPPDATA Pass-through ``ALLUSERAPPDATA`` if exists in process env, unset otherwise
ALLUSERSPROFILE Pass-through ``ALLUSERSPPPROFILE`` if exists in process env, unset otherwise
APPDATA Pass-through ``APPDATA`` if exists in process env, unset otherwise
COMMONPROGRAMFILES Pass-through ``COMMONPROGRAMFILES`` if exists in process env, unset otherwise
COMMONPROGRAMFILES(x86) Pass-through ``COMMONPROGRAMFILES(x86)`` if exists in process env, unset otherwise
DEFAULTUSERPROFILE Pass-through ``DEFAULTUSERPROFILE`` if exists in process env, unset otherwise
HOMEPATH Pass-through ``HOMEPATH`` if exists in process env, unset otherwise
PATHEXT Pass-through ``PATHEXT`` if exists in process env, unset otherwise
PROFILESFOLDER Pass-through ``PROFILESFOLDER`` if exists in process env, unset otherwise
PROGRAMFILES Pass-through ``PROGRAMFILES`` if exists in process env, unset otherwise
PROGRAMFILES(x86) Pass-through ``PROGRAMFILES(x86)`` if exists in process env, unset otherwise
SYSTEM Pass-through ``SYSTEM`` if exists in process env, unset otherwise
SYSTEM16 Pass-through ``SYSTEM16`` if exists in process env, unset otherwise
SYSTEM32 Pass-through ``SYSTEM32`` if exists in process env, unset otherwise
SYSTEMDRIVE Pass-through ``SYSTEMDRIVE`` if exists in process env, unset otherwise
SYSTEMROOT Pass-through ``SYSTEMROOT`` if exists in process env, unset otherwise
TEMP Pass-through ``TEMP`` if exists in process env, unset otherwise
TMP Pass-through ``TMP`` if exists in process env, unset otherwise
USERPROFILE Pass-through ``USERPROFILE`` if exists in process env, unset otherwise
USERSID Pass-through ``USERSID`` if exists in process env, unset otherwise
WINDIR Pass-through ``WINDIR`` if exists in process env, unset otherwise
======================== ======================================================================

**Default:** ``None`` (not specified)

----
Expand Down
37 changes: 37 additions & 0 deletionssemantic_release/cli/commands/version.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import logging
import os
import subprocess
import sys
from contextlib import nullcontext
from datetime import datetime
from typing import TYPE_CHECKING
Expand DownExpand Up@@ -156,6 +157,40 @@ def shell(
)


def is_windows() -> bool:
return sys.platform == "win32"


def get_windows_env() -> Mapping[str, str | None]:
return {
environment_variable: os.getenv(environment_variable, None)
for environment_variable in (
"ALLUSERSAPPDATA",
"ALLUSERSPROFILE",
"APPDATA",
"COMMONPROGRAMFILES",
"COMMONPROGRAMFILES(x86)",
"DEFAULTUSERPROFILE",
"HOMEPATH",
"PATHEXT",
"PROFILESFOLDER",
"PROGRAMFILES",
"PROGRAMFILES(x86)",
"SYSTEM",
"SYSTEM16",
"SYSTEM32",
"SYSTEMDRIVE",
"SYSTEMPROFILE",
"SYSTEMROOT",
"TEMP",
"TMP",
"USERPROFILE",
"USERSID",
"WINDIR",
)
}


@click.command(
short_help="Detect and apply a new version",
context_settings={
Expand DownExpand Up@@ -522,6 +557,8 @@ def version( # noqa: C901
"PATH": os.getenv("PATH", ""),
"HOME": os.getenv("HOME", None),
"VIRTUAL_ENV": os.getenv("VIRTUAL_ENV", None),
# Windows environment variables
**(get_windows_env() if is_windows() else {}),
# affects build decisions
"CI": os.getenv("CI", None),
# Identifies which CI environment
Expand Down
128 changes: 127 additions & 1 deletiontests/command_line/test_version.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -619,14 +619,38 @@ def test_version_runs_build_command(
"GITEA_ACTIONS": "true",
"BITBUCKET_REPO_FULL_NAME": "python-semantic-release/python-semantic-release.git",
"PSR_DOCKER_GITHUB_ACTION": "true",
# Windows
"ALLUSERSAPPDATA": "C:\\ProgramData",
"ALLUSERSPROFILE": "C:\\ProgramData",
"APPDATA": "C:\\Users\\Username\\AppData\\Roaming",
"COMMONPROGRAMFILES": "C:\\Program Files\\Common Files",
"COMMONPROGRAMFILES(x86)": "C:\\Program Files (x86)\\Common Files",
"DEFAULTUSERPROFILE": "C:\\Users\\Default",
"HOMEPATH": "\\Users\\Username",
"PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC",
"PROFILESFOLDER": "C:\\Users",
"PROGRAMFILES": "C:\\Program Files",
"PROGRAMFILES(x86)": "C:\\Program Files (x86)",
"SYSTEM": "C:\\Windows\\System32",
"SYSTEM16": "C:\\Windows\\System16",
"SYSTEM32": "C:\\Windows\\System32",
"SYSTEMDRIVE": "C:",
"SYSTEMROOT": "C:\\Windows",
"TEMP": "C:\\Users\\Username\\AppData\\Local\\Temp",
"TMP": "C:\\Users\\Username\\AppData\\Local\\Temp",
"USERPROFILE": "C:\\Users\\Username",
"USERSID": "S-1-5-21-1234567890-123456789-123456789-1234",
"WINDIR": "C:\\Windows",
}

# Mock out subprocess.run
with mock.patch(
"subprocess.run", return_value=CompletedProcess(args=(), returncode=0)
) as patched_subprocess_run, mock.patch(
"shellingham.detect_shell", return_value=(exe, shell)
), mock.patch.dict("os.environ", patched_os_environment, clear=True):
), mock.patch("sys.platform", "linux"), mock.patch.dict(
"os.environ", patched_os_environment, clear=True
):
# ACT: run & force a new version that will trigger the build command
result = cli_runner.invoke(
main, [version_subcmd or "version", "--patch", "--no-push"]
Expand All@@ -653,6 +677,108 @@ def test_version_runs_build_command(
)


@pytest.mark.parametrize("shell", ("powershell", "cmd"))
def test_version_runs_build_command_windows(
repo_with_git_flow_angular_commits: Repo,
cli_runner: CliRunner,
update_pyproject_toml: UpdatePyprojectTomlFn,
shell: str,
):
# Setup
build_command = "bash -c \"echo 'hello world'\""
update_pyproject_toml("tool.semantic_release.build_command", build_command)
exe = shell.split("/")[-1]
patched_os_environment = {
"CI": "true",
"PATH": os.getenv("PATH"),
"HOME": os.getenv("HOME"),
"VIRTUAL_ENV": os.getenv("VIRTUAL_ENV", "./.venv"),
# Simulate that all CI's are set
"GITHUB_ACTIONS": "true",
"GITLAB_CI": "true",
"GITEA_ACTIONS": "true",
"BITBUCKET_REPO_FULL_NAME": "python-semantic-release/python-semantic-release.git",
"PSR_DOCKER_GITHUB_ACTION": "true",
# Windows
"ALLUSERSAPPDATA": "C:\\ProgramData",
"ALLUSERSPROFILE": "C:\\ProgramData",
"APPDATA": "C:\\Users\\Username\\AppData\\Roaming",
"COMMONPROGRAMFILES": "C:\\Program Files\\Common Files",
"COMMONPROGRAMFILES(x86)": "C:\\Program Files (x86)\\Common Files",
"DEFAULTUSERPROFILE": "C:\\Users\\Default",
"HOMEPATH": "\\Users\\Username",
"PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC",
"PROFILESFOLDER": "C:\\Users",
"PROGRAMFILES": "C:\\Program Files",
"PROGRAMFILES(x86)": "C:\\Program Files (x86)",
"SYSTEM": "C:\\Windows\\System32",
"SYSTEM16": "C:\\Windows\\System16",
"SYSTEM32": "C:\\Windows\\System32",
"SYSTEMDRIVE": "C:",
"SYSTEMROOT": "C:\\Windows",
"TEMP": "C:\\Users\\Username\\AppData\\Local\\Temp",
"TMP": "C:\\Users\\Username\\AppData\\Local\\Temp",
"USERPROFILE": "C:\\Users\\Username",
"USERSID": "S-1-5-21-1234567890-123456789-123456789-1234",
"WINDIR": "C:\\Windows",
}

# Mock out subprocess.run
with mock.patch(
"subprocess.run", return_value=CompletedProcess(args=(), returncode=0)
) as patched_subprocess_run, mock.patch(
"shellingham.detect_shell", return_value=(exe, shell)
), mock.patch("sys.platform", "win32"), mock.patch.dict(
"os.environ", patched_os_environment, clear=True
):
# ACT: run & force a new version that will trigger the build command
result = cli_runner.invoke(
main, [version_subcmd or "version", "--patch", "--no-push"]
)
assert result.exit_code == 0

patched_subprocess_run.assert_called_once_with(
[exe, "-c" if shell != "cmd" else "/c", build_command],
check=True,
env={
"NEW_VERSION": "1.2.1", # injected into environment
"CI": patched_os_environment["CI"],
"BITBUCKET_CI": "true", # Converted
"GITHUB_ACTIONS": patched_os_environment["GITHUB_ACTIONS"],
"GITEA_ACTIONS": patched_os_environment["GITEA_ACTIONS"],
"GITLAB_CI": patched_os_environment["GITLAB_CI"],
"HOME": patched_os_environment["HOME"],
"PATH": patched_os_environment["PATH"],
"VIRTUAL_ENV": patched_os_environment["VIRTUAL_ENV"],
"PSR_DOCKER_GITHUB_ACTION": patched_os_environment[
"PSR_DOCKER_GITHUB_ACTION"
],
# Windows
"ALLUSERSAPPDATA": patched_os_environment["ALLUSERSAPPDATA"],
"ALLUSERSPROFILE": patched_os_environment["ALLUSERSPROFILE"],
"APPDATA": patched_os_environment["APPDATA"],
"COMMONPROGRAMFILES": patched_os_environment["COMMONPROGRAMFILES"],
"COMMONPROGRAMFILES(x86)": patched_os_environment["COMMONPROGRAMFILES(x86)"],
"DEFAULTUSERPROFILE": patched_os_environment["DEFAULTUSERPROFILE"],
"HOMEPATH": patched_os_environment["HOMEPATH"],
"PATHEXT": patched_os_environment["PATHEXT"],
"PROFILESFOLDER": patched_os_environment["PROFILESFOLDER"],
"PROGRAMFILES": patched_os_environment["PROGRAMFILES"],
"PROGRAMFILES(x86)": patched_os_environment["PROGRAMFILES(x86)"],
"SYSTEM": patched_os_environment["SYSTEM"],
"SYSTEM16": patched_os_environment["SYSTEM16"],
"SYSTEM32": patched_os_environment["SYSTEM32"],
"SYSTEMDRIVE": patched_os_environment["SYSTEMDRIVE"],
"SYSTEMROOT": patched_os_environment["SYSTEMROOT"],
"TEMP": patched_os_environment["TEMP"],
"TMP": patched_os_environment["TMP"],
"USERPROFILE": patched_os_environment["USERPROFILE"],
"USERSID": patched_os_environment["USERSID"],
"WINDIR": patched_os_environment["WINDIR"],
},
)


def test_version_runs_build_command_w_user_env(
repo_with_git_flow_angular_commits: Repo,
cli_runner: CliRunner,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp