Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support noxfile being a symlink #829

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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: 16 additions & 11 deletions nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,21 @@ def load_nox_module(global_config: Namespace) -> types.ModuleType | int:
Returns:
module: The module designated by the Noxfile path.
"""
try:
# Save the absolute path to the Noxfile.
# This will inoculate it if Nox changes paths because of an implicit
# or explicit chdir (like the one below).
global_config.noxfile = os.path.realpath(
# Be sure to expand variables
os.path.expandvars(global_config.noxfile)
)
noxfile_parent_dir = os.path.realpath(os.path.dirname(global_config.noxfile))

# Be sure to expand variables
global_config_noxfile = os.path.expandvars(global_config.noxfile)

# Make sure we only expand the parent dir just in case the noxfile is a symlink
noxfile_parent_dir = os.path.realpath(os.path.dirname(global_config_noxfile))

# Save the absolute path to the Noxfile.
# This will inoculate it if Nox changes paths because of an implicit
# or explicit chdir (like the one below).
global_config.noxfile = os.path.join(
noxfile_parent_dir, os.path.basename(global_config_noxfile)
)

try:
# Check ``nox.needs_version`` by parsing the AST.
check_nox_version(global_config.noxfile)

Expand All @@ -110,8 +115,8 @@ def load_nox_module(global_config: Namespace) -> types.ModuleType | int:
except OSError:
logger.exception(f"Failed to load Noxfile {global_config.noxfile}")
return 2
else:
return _load_and_exec_nox_module(global_config)

return _load_and_exec_nox_module(global_config)


def merge_noxfile_options(
Expand Down
Loading