Skip to content

Commit

Permalink
⚓️ Resolve paths in a hacky way for Windows venvs
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Jan 2, 2024
1 parent bf1d2bf commit 72d3b9b
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions python_hugo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# On installing from a wheel, the binary is in the venv/binaries, but the package
# is in venv/lib/python3.X/site-packages, so we need to go up two directories and
# then down into binaries
# Note: on Windows, this is venv\Lib\site-packages (instead of venv/lib/python3.X/site-packages)
# therefore we need to go up to the venv directory and then down into the data files
try:
hugo_executable = os.path.join(
os.path.dirname(__file__),
Expand All @@ -28,24 +30,38 @@
if not os.path.exists(hugo_executable):
raise FileNotFoundError
except FileNotFoundError:
hugo_executable = os.path.join(
# Go up into the venv directory and down into the data files
os.path.dirname(
if sys.platform == "win32":
PATH_TO_SEARCH = os.path.join(
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.dirname(__file__)
)
)
),
"binaries"
) # four times instead of five
else:
# five times instead of four
PATH_TO_SEARCH = os.path.join(
os.path.dirname(
os.path.dirname(__file__)
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.dirname(__file__)
)
)
)
),
"binaries"
)
),
"binaries",
f"hugo-{HUGO_VERSION}" + FILE_EXT,
)

# Go up into the venv directory and down into the data files
hugo_executable = os.path.join(PATH_TO_SEARCH, f"hugo-{HUGO_VERSION}" + FILE_EXT)
if not os.path.exists(hugo_executable):
raise FileNotFoundError
raise FileNotFoundError from None
except Exception as e:
print(f"Error: {e}")
sys.exit(f"Error: {e}")

def __call():
"""
Expand Down

0 comments on commit 72d3b9b

Please sign in to comment.