FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add `setup.py dev` command to run from repo · plotdevice/plotdevice@d77cc68 · GitHub

Repository navigation

Commit d77cc68

Browse files
committed
add setup.py dev command to run from repo
- invoked on import by the `run` module if it can't find pyobjc, otherwise it adds the existing dev environment to sys.path - the other remaining piece of path hackery is mapping in the rsrc dir from the build directory in .util/__init__
1 parent d3ef0b5 commit d77cc68

7 files changed

Lines changed: 47 additions & 60 deletions

File tree

‎plotdevice/lib/__init__.py‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import sys
2-
from os.path import abspath, dirname, exists, join
3-
from glob import glob
4-
5-
try:
6-
import _plotdevice # make sure the c-extensions are accessible
7-
except ImportError:
8-
setup_py = join(dirname(__file__), '../../setup.py')
9-
if exists(setup_py):
10-
from subprocess import call
11-
# call('{py} {setup} build_ext --inplace'.format(py=sys.executable, setup=setup_py))
12-
call([sys.executable, setup_py, 'build_ext', '--inplace'])
13-
import _plotdevice
2+
import _plotdevice # make sure the c-extensions are accessible for the submodules
143

154
# allow Libraries to request a _ctx reference
165
def register(module):

‎plotdevice/lib/foundry.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from ..util import numlike
1111

1212
from plotdevice import DeviceError
13-
import _plotdevice
1413

1514
__all__ = ["font_family", "font_encoding", "font_face", "best_face",
1615
"family_names", "family_members", "family_name", "standardized", "sanitized",

‎plotdevice/lib/io.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import objc, os, re
2-
import _plotdevice
32

43
for cls in ["AnimatedGif", "Pages", "SysAdmin", "Video"]:
54
globals()[cls] = objc.lookUpClass(cls)

‎plotdevice/run/__init__.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import sys, site
2+
import platform
23
from os.path import abspath, dirname, exists, join
3-
from subprocess import call, getoutput
4+
from subprocess import call
45

56
try:
67
# test the sys.path by attempting to load a PyObjC submodule...
78
from Foundation import *
89
except ImportError:
9-
setup_py = join(dirname(__file__), '../../setup.py')
10+
# detect whether we're being run from the repository and set up a local env if so
11+
repo = abspath(join(dirname(__file__), '../..'))
12+
setup_py = '%s/setup.py' % repo
1013
if exists(setup_py):
11-
# if run from the sdist, install pyobjc et al. in a venv at app/deps/local
12-
site_path = getoutput('{py} {setup} -q env'.format(py=sys.executable, setup=setup_py))
13-
site.addsitedir(site_path)
14+
local_libs = '%s/app/deps/local/%s/libs' % (repo, platform.python_version())
15+
if not exists(local_libs):
16+
call([sys.executable, setup_py, 'dev'])
17+
site.addsitedir(local_libs)
1418
from Foundation import *
1519
else:
1620
from pprint import pformat

‎plotdevice/util/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def rsrc_path(resource=None):
318318
rsrc_root = abspath(pth)
319319
break
320320
else:
321-
notfound = "Couldn't locate resources directory (try running `python setup.py build` before running from the source dist)."
321+
notfound = "Couldn't locate resources directory (try running `python setup.py dev` before running from the source dist)."
322322
raise RuntimeError(notfound)
323323
if resource:
324324
return join(rsrc_root, resource)

‎plotdevice/util/readers.py‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,13 @@ def csv_dialect(fd):
190190

191191
### HTTP utils ###
192192

193-
try:
194-
import requests
195-
from cachecontrol import CacheControl, CacheControlAdapter
196-
from cachecontrol.caches import FileCache
197-
from cachecontrol.heuristics import LastModified
198-
199-
cache_dir = '%s/Library/Caches/PlotDevice'%os.environ['HOME']
200-
HTTP = CacheControl(requests.Session(), cache=FileCache(cache_dir), heuristic=LastModified())
201-
except ImportError:
202-
class Decoy(object):
203-
def get(self, url):
204-
unsupported = 'could not find the "requests" library (try running "python setup.py build" first)'
205-
raise RuntimeError(unsupported)
206-
HTTP = Decoy()
193+
import requests
194+
from cachecontrol import CacheControl, CacheControlAdapter
195+
from cachecontrol.caches import FileCache
196+
from cachecontrol.heuristics import LastModified
197+
198+
cache_dir = '%s/Library/Caches/PlotDevice'%os.environ['HOME']
199+
HTTP = CacheControl(requests.Session(), cache=FileCache(cache_dir), heuristic=LastModified())
207200

208201
def binaryish(content, format):
209202
bin_types = ('pdf','eps','png','jpg','jpeg','heic','gif','tiff','tif','zip','tar','gz')

‎setup.py‎

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
# - cFoundry, cPathmatics, cIO, & PyObjC (included in the "app/deps" folder)
2020
# - Sparkle.framework (auto-downloaded only for `dist` builds)
2121

22-
import os, sys, json, re
22+
import os, sys, json, re, platform
23+
from glob import glob
2324
from setuptools import setup, find_packages
25+
from setuptools.extension import Extension
2426
from distutils.dir_util import remove_tree
2527
from distutils.command.build_py import build_py
2628
from pkg_resources import DistributionNotFound
@@ -47,10 +49,8 @@
4749
"Intended Audience :: End Users/Desktop",
4850
"License :: OSI Approved :: MIT License",
4951
"Operating System :: MacOS :: MacOS X",
50-
"Programming Language :: Python :: 2",
51-
"Programming Language :: Python :: 2.7",
5252
"Programming Language :: Python :: 3",
53-
"Programming Language :: Python :: 3.4",
53+
"Programming Language :: Python :: 3.8",
5454
"Topic :: Artistic Software",
5555
"Topic :: Multimedia :: Graphics",
5656
"Topic :: Multimedia :: Graphics :: Editors :: Vector-Based",
@@ -96,12 +96,10 @@
9696
9797
Requirements:
9898
99-
* Mac OS X 10.9+
100-
* Python 2.7 or 3.4+
101-
* the requests, cachecontrol, and lockfile modules
99+
* Mac OS X 11+
100+
* Python 3.8+
102101
"""
103102

104-
105103
## Basic Utils ##
106104

107105
# the sparkle updater framework will be fetched as needed
@@ -162,41 +160,48 @@ def stale(dst, src):
162160

163161
from distutils.core import Command
164162
class CleanCommand(Command):
165-
description = "wipe out the ./build ./dist and app/deps/.../build dirs"
163+
description = "wipe out the ./build ./dist and app/deps/local dirs"
166164
user_options = []
167165
def initialize_options(self):
168166
pass
169167
def finalize_options(self):
170168
pass
171169
def run(self):
172170
os.system('rm -rf ./build ./dist')
173-
os.system('rm -rf ./app/deps/*/build')
171+
os.system('rm -rf ./app/deps/local')
174172
os.system('rm -rf plotdevice.egg-info MANIFEST.in PKG')
175173
os.system('rm -rf ./tests/_out ./tests/_diff ./details.html')
174+
os.system('rm -f ./_plotdevice.*.so')
176175
os.system('find plotdevice -name .DS_Store -exec rm {} \;')
177176
os.system('find plotdevice -name \*.pyc -exec rm {} \;')
178177
os.system('find plotdevice -name __pycache__ -type d -prune -exec rmdir {} \;')
179178

180-
class LocalEnvCommand(Command):
181-
description = "set up app/deps/local env to allow for running from the sdist"
179+
class LocalDevCommand(Command):
180+
description = "set up environment to allow for running `python -m plotdevice` within the repo"
182181
user_options = []
183182
def initialize_options(self):
184183
pass
185184
def finalize_options(self):
186185
pass
187186
def run(self):
187+
# install pyobjc, requests and the other pypi dependencies in app/deps/local
188188
import platform
189189
venv_dir = join('app/deps/local', platform.python_version())
190190
if not exists(venv_dir):
191191
import venv
192192
venv.create(venv_dir, symlinks=True, with_pip=True)
193193
PIP = '%s/bin/pip3' % venv_dir
194194
call([PIP, 'install', '-q', '--upgrade', 'pip'])
195-
call([PIP, '--isolated', 'install', '-q', *config['install_requires']])
195+
call([PIP, '--isolated', 'install', '--target', join(venv_dir, 'libs'), *config['install_requires']])
196+
197+
# place the compiled c-extensions in the main repo dir
198+
build_ext = self.distribution.get_command_obj('build_ext')
199+
build_ext.inplace = 1
200+
self.run_command('build_ext')
201+
202+
# build the sdist (primarily for access to its rsrc subdir)
203+
self.run_command('build_py')
196204

197-
# use the venv's site directory
198-
site_path = getoutput('%s/bin/python3 -c "import site; print(site.getsitepackages()[0])"' % venv_dir)
199-
print(site_path)
200205

201206

202207
from setuptools.command.sdist import sdist
@@ -367,13 +372,6 @@ def run(self):
367372

368373
print("\nBuilt PlotDevice.app, %s, and release.json in ./dist" % basename(ZIP))
369374

370-
from glob import glob
371-
from setuptools.extension import Extension
372-
sources = ['app/deps/extensions/module.m', *glob('app/deps/extensions/*/*.[cm]')]
373-
frameworks = ['AppKit', 'Foundation', 'Quartz', 'Security', 'AVFoundation', 'CoreMedia', 'CoreVideo', 'CoreText']
374-
flags = sum((['-framework', fmwk] for fmwk in frameworks), [])
375-
_plotdevice = Extension('_plotdevice', sources=sources, extra_link_args=flags)
376-
377375
# common config between module and app builds
378376
config = dict(
379377
name = MODULE,
@@ -386,7 +384,13 @@ def run(self):
386384
license = LICENSE,
387385
classifiers = CLASSIFIERS,
388386
packages = find_packages(exclude=['tests']),
389-
ext_modules = [_plotdevice],
387+
ext_modules = [Extension(
388+
'_plotdevice',
389+
sources = ['app/deps/extensions/module.m', *glob('app/deps/extensions/*/*.[cm]')],
390+
extra_link_args=sum((['-framework', fmwk] for fmwk in
391+
['AppKit', 'Foundation', 'Quartz', 'Security', 'AVFoundation', 'CoreMedia', 'CoreVideo', 'CoreText']
392+
), [])
393+
)],
390394
install_requires = [
391395
'requests',
392396
'cachecontrol',
@@ -406,7 +410,7 @@ def run(self):
406410
'dist': DistCommand,
407411
'sdist': BuildDistCommand,
408412
'test': TestCommand,
409-
'env': LocalEnvCommand,
413+
'dev': LocalDevCommand,
410414
},
411415
)
412416

@@ -417,7 +421,6 @@ def run(self):
417421
# (this means the various commands don't have to play path games)
418422
os.chdir(dirname(abspath(__file__)))
419423

420-
421424
# py2app-specific config
422425
if 'py2app' in sys.argv:
423426
config.update(dict(

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL