Skip to content

Commit ff68105

Browse files
authored
Merge pull request #73 from flimsyhat/build-issues
Build and dependency updates
2 parents 033eeab + f905b9b commit ff68105

5 files changed

Lines changed: 94 additions & 43 deletions

File tree

.github/workflows/test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
id: repo
1616
uses: actions/checkout@v3
1717

18-
- name: Build PyPI Package
19-
run: |
20-
python3 setup.py test
18+
- name: Add missing setuptools
19+
run: brew install python-setuptools
20+
21+
- name: Run tests
22+
run: python3 setup.py test

deps/frameworks/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ FRAMEWORK_REPO = https://github.com/gregneagle/relocatable-python.git
33
BUILD_OPTS = --os-version=11 --python-version=$(PYTHON_VERSION) --upgrade-pip --pip-requirements=requirements.txt
44
BIN = ./Python.framework/Versions/Current/bin
55

6+
# Use PIP_NO_CACHE_DIR from environment if set, otherwise empty
7+
PIP_ENV = $(if $(PIP_NO_CACHE_DIR),PIP_NO_CACHE_DIR=1,)
8+
69
all: Python.framework
7-
$(BIN)/pip3 install --upgrade ../..
10+
$(PIP_ENV) $(BIN)/pip3 install --upgrade ../..
811

912
Python.framework: relocatable-python
10-
python3 ./relocatable-python/make_relocatable_python_framework.py $(BUILD_OPTS)
13+
PYTHONNOUSERSITE=1 $(PIP_ENV) python3 ./relocatable-python/make_relocatable_python_framework.py $(BUILD_OPTS)
1114
$(BIN)/python3 config.py ../../app/python.xcconfig
1215

1316
relocatable-python:

deps/frameworks/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# --no-binary :all:
22
xattr
3-
cachecontrol
3+
cachecontrol[filecache]
44
cffi
5-
lockfile
6-
pyobjc
5+
pyobjc==8.5
76
requests
87
six

plotdevice/util/readers.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# files & io
66
from io import open, StringIO, BytesIO
7-
from os.path import abspath, dirname, exists, join, splitext
7+
from os.path import abspath, dirname, exists, join, splitext, expanduser
88
from plotdevice import DeviceError, INTERNAL
99

1010
# data formats
@@ -190,13 +190,25 @@ def csv_dialect(fd):
190190

191191
### HTTP utils ###
192192

193-
import requests
194-
from cachecontrol import CacheControl, CacheControlAdapter
195-
from cachecontrol.caches import FileCache
196-
from cachecontrol.heuristics import LastModified
193+
HTTP = None
197194

198-
cache_dir = '%s/Library/Caches/PlotDevice'%os.environ['HOME']
199-
HTTP = CacheControl(requests.Session(), cache=FileCache(cache_dir), heuristic=LastModified())
195+
def get_http_session():
196+
"""Returns a cached HTTP session (creating it if necessary)"""
197+
global HTTP
198+
if HTTP is None:
199+
try:
200+
from cachecontrol import CacheControl
201+
from cachecontrol.caches import FileCache
202+
from cachecontrol.heuristics import LastModified
203+
import requests
204+
205+
cache_dir = join(expanduser('~'), 'Library/Caches/PlotDevice')
206+
HTTP = CacheControl(requests.Session(),
207+
cache=FileCache(cache_dir),
208+
heuristic=LastModified())
209+
except ImportError as e:
210+
raise ImportError("HTTP dependencies not available. Install with: pip install requests cachecontrol[filecache]") from e
211+
return HTTP
200212

201213
def binaryish(content, format):
202214
bin_types = ('pdf','eps','png','jpg','jpeg','heic','gif','tiff','tif','zip','tar','gz')
@@ -244,7 +256,8 @@ def read(pth, format=None, encoding=None, cols=None, **kwargs):
244256
"""
245257

246258
if re.match(r'https?:', pth):
247-
resp = HTTP.get(pth)
259+
session = get_http_session() # Get the session only when needed
260+
resp = session.get(pth)
248261
resp.raise_for_status()
249262

250263
extension_type = splitext(urlparse(pth).path)[-1]

setup.py

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"Intended Audience :: Developers",
4848
"Intended Audience :: Education",
4949
"Intended Audience :: End Users/Desktop",
50-
"License :: OSI Approved :: MIT License",
5150
"Operating System :: MacOS :: MacOS X",
5251
"Programming Language :: Python :: 3",
5352
"Programming Language :: Python :: 3.6",
@@ -182,33 +181,63 @@ def stale(dst, src):
182181
## Build Commands ##
183182

184183
class CleanCommand(Command):
185-
description = "wipe out the ./build & ./dist dirs and other setup-generated files"
186-
user_options = []
184+
description = "wipe out generated files and build artifacts"
185+
user_options = [
186+
('dist', None, 'also remove Python.framework and local dependencies'),
187+
]
188+
187189
def initialize_options(self):
188-
pass
190+
self.dist = None
191+
189192
def finalize_options(self):
190193
pass
194+
191195
def run(self):
192-
os.system('rm -rf ./build ./dist')
193-
os.system('rm -rf plotdevice.egg-info MANIFEST.in PKG')
194-
os.system('rm -rf ./tests/_out ./tests/_diff ./details.html')
195-
os.system('rm -f ./_plotdevice.*.so')
196-
os.system('cd deps/extensions/svg && make clean')
197-
os.system('find plotdevice -name .DS_Store -exec rm {} \;')
198-
os.system('find plotdevice -name \*.pyc -exec rm {} \;')
199-
os.system('find plotdevice -name __pycache__ -type d -prune -exec rmdir {} \;')
200-
201-
class DistCleanCommand(Command):
196+
paths = [
197+
'build',
198+
'dist',
199+
'*.egg',
200+
'*.egg-info',
201+
'.eggs',
202+
'MANIFEST.in',
203+
'PKG',
204+
'tests/_out',
205+
'tests/_diff',
206+
'details.html',
207+
'_plotdevice.*.so',
208+
'**/*.pyc',
209+
'**/__pycache__',
210+
'**/.DS_Store',
211+
]
212+
213+
# Add framework paths if --dist flag is used
214+
if self.dist:
215+
paths.extend([
216+
'deps/local',
217+
'deps/frameworks/Python.framework',
218+
'deps/frameworks/relocatable-python',
219+
])
220+
221+
for path_pattern in paths:
222+
for path in glob(path_pattern, recursive=True):
223+
if exists(path):
224+
print('removing %s'%path)
225+
if os.path.isdir(path):
226+
rmtree(path)
227+
else:
228+
os.unlink(path)
229+
230+
# Run make clean in svg extensions dir
231+
if exists('deps/extensions/svg'):
232+
os.system('cd deps/extensions/svg && make clean')
233+
234+
class DistCleanCommand(CleanCommand):
235+
"""Alias for `clean --dist` for backward compatibility"""
202236
description = "delete Python.framework, local pypi dependencies, and all generated files"
203-
user_options = []
237+
204238
def initialize_options(self):
205-
pass
206-
def finalize_options(self):
207-
pass
208-
def run(self):
209-
self.run_command('clean')
210-
os.system('rm -rf ./deps/local')
211-
os.system('rm -rf ./deps/frameworks/*.framework')
239+
super().initialize_options()
240+
self.dist = True # always do a deep clean
212241

213242
class LocalDevCommand(Command):
214243
description = "set up environment to allow for running `python -m plotdevice` within the repo"
@@ -308,14 +337,20 @@ def run(self):
308337

309338
class BuildAppCommand(Command):
310339
description = "Build PlotDevice.app with xcode"
311-
user_options = []
340+
user_options = [
341+
('no-cache', None, 'do not use pip cache when installing dependencies'),
342+
]
343+
312344
def initialize_options(self):
313-
pass
345+
self.no_cache = None
314346

315347
def finalize_options(self):
316348
# make sure the embedded framework exists (and has updated app/python.xcconfig)
317349
print("Set up Python.framework for app build")
318-
call('cd deps/frameworks && make', shell=True)
350+
env = os.environ.copy()
351+
if self.no_cache:
352+
env['PIP_NO_CACHE_DIR'] = '1'
353+
call('cd deps/frameworks && make', shell=True, env=env)
319354

320355
def run(self):
321356
self.spawn(['xcodebuild', '-configuration', 'Release'])
@@ -470,8 +505,7 @@ def codesign(root, name=None, exec=False, entitlement=False):
470505
)],
471506
install_requires = [
472507
'requests',
473-
'cachecontrol',
474-
'lockfile',
508+
'cachecontrol[filecache]',
475509
'pyobjc-core==8.5',
476510
'pyobjc-framework-Quartz==8.5',
477511
'pyobjc-framework-LaunchServices==8.5',

0 commit comments

Comments
 (0)