Skip to content

Commit 6d7521a

Browse files
Merge pull request #170 from ChrisNeedham24/switchToUserSitePackages
Adjusted pip installs to install to the user site.
2 parents 14e8ab5 + 6149d97 commit 6d7521a

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ Additionally, only x86 architectures are supported.
4242

4343
## Play from package
4444

45-
1. Run `pip install microcosm-4x`
45+
1. Run `pip install --user microcosm-4x`
4646
2. Run `microcosm`
47-
1. Note: if this doesn't work, make sure Python's scripts directory is on your PATH.
48-
See [here](https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-to-the-user-site) for instructions for Windows
49-
(this is not usually a problems on other operating systems).
47+
1. Note: if this doesn't work, make sure Python's user scripts directory is on your PATH.
48+
See [here](https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-to-the-user-site) for instructions.
5049

5150
## Play from source
5251

‎source/networking/event_listener.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import socketserver
88
import time
99
from itertools import chain
10-
from site import getsitepackages
10+
from site import getusersitepackages
1111
from threading import Thread
1212
from typing import Dict, List, Optional, Set, Tuple, Callable
1313

@@ -22,8 +22,7 @@
2222
# However, clients playing via a pip install or from source will need to load the DLL manually.
2323
except FileNotFoundError:
2424
if "microcosm" in sys.modules:
25-
site_packages_path: str = next(path for path in getsitepackages() if path.endswith("site-packages"))
26-
cdll.LoadLibrary(f"{site_packages_path}/microcosm/source/resources/dll/miniupnpc.dll")
25+
cdll.LoadLibrary(f"{getusersitepackages()}/microcosm/source/resources/dll/miniupnpc.dll")
2726
else:
2827
cdll.LoadLibrary("source/resources/dll/miniupnpc.dll")
2928
# We need to disable a lint rule for the miniupnpc import because it doesn't actually declare UPnP in its module. This

‎source/tests/test_event_listener.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ def setUp(self, _: MagicMock):
101101
self.request_handler: RequestHandler = RequestHandler((self.TEST_EVENT_BYTES, self.mock_socket),
102102
(self.TEST_HOST, self.TEST_PORT), self.mock_server)
103103

104-
@patch("site.getsitepackages")
104+
@patch("site.getusersitepackages")
105105
@patch("ctypes.cdll.LoadLibrary")
106106
@patch("ctypes.CDLL")
107107
@patch("platform.system", return_value="Windows")
108108
def test_windows_dll_verification(self,
109109
_: MagicMock,
110110
cdll_construction_mock: MagicMock,
111111
cdll_load_mock: MagicMock,
112-
site_packages_mock: MagicMock):
112+
user_site_packages_mock: MagicMock):
113113
"""
114114
Ensure that the miniupnpc DLL is correctly manually loaded or not manually loaded, depending on whether it has
115115
already been automatically loaded.
@@ -129,16 +129,16 @@ def test_windows_dll_verification(self,
129129
# manually loaded from source.
130130
cdll_construction_mock.assert_called_with("miniupnpc.dll")
131131
cdll_load_mock.assert_called_with("source/resources/dll/miniupnpc.dll")
132-
# Simulate the package case by mocking out the site-packages path and sys.modules.
133-
site_packages_path: str = "/tmp/site-packages"
134-
site_packages_mock.return_value = [site_packages_path]
132+
# Simulate the package case by mocking out the user site-packages path and sys.modules.
133+
user_site_packages_path: str = "/tmp/site-packages"
134+
user_site_packages_mock.return_value = user_site_packages_path
135135
# This mock is definitely not normal, but it does serve our purpose by defining the key against a real module.
136136
sys.modules["microcosm"] = event_listener
137137
importlib.reload(event_listener)
138138
# In this case, we also expect an attempt to be made to construct the DLL object, but this time we expect the
139-
# DLL to be manually loaded from site-packages.
139+
# DLL to be manually loaded from user site-packages.
140140
cdll_construction_mock.assert_called_with("miniupnpc.dll")
141-
cdll_load_mock.assert_called_with(f"{site_packages_path}/microcosm/source/resources/dll/miniupnpc.dll")
141+
cdll_load_mock.assert_called_with(f"{user_site_packages_path}/microcosm/source/resources/dll/miniupnpc.dll")
142142

143143
def test_handle(self):
144144
"""

0 commit comments

Comments
 (0)