Skip to content

Commit

Permalink
Working on #23: moved requirements into setup.py; remove pip dependency
Browse files Browse the repository at this point in the history
pip removed all APIs in version 10 so pip.download and pip.main are not allowed.
It's impractical to support pykern being installed automatically so packages
will have to install pykern before they run setup.py if they refer to
pykern in setup.py (e.g. using pksetup). For RadiaSoft, this isn't a
problem, because we install from known environments setup by our curl
installers (usually inside vagrant or docker). For others, it's a design
flaw that you can't use a library in setup.py that is not in base python.
To get projex_test.py to work with tox, added some code inside pksetup.py
that supports looking for the right python version.
Removed extras_require, because I don't think that's necessary any more
to build jupyterhub.
  • Loading branch information
robnagler committed May 19, 2018
1 parent 01f0199 commit c41c95d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 71 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ branches:
- master
#TODO: this script could be pulled dynamically
install:
- pip install setuptools==32.1.3
- pip install -U pip tox
- pip install -r requirements.txt
script:
- python setup.py pkdeploy
1 change: 0 additions & 1 deletion pykern/package_data/projex/requirements.txt.jinja

This file was deleted.

14 changes: 4 additions & 10 deletions pykern/package_data/projex/setup.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@ u"""{{ name }} setup script

{{ copyright_license_rst }}
"""
# All imports (except __future__) must come after this block.
# setuptools, in particular, caches data about the current state
# of modules so it has to be imported after the pykern import.
try:
from pykern import pksetup
except ImportError:
import pip
pip.main(['install', 'pykern'])
from pykern import pksetup

from pykern import pksetup

pksetup.setup(
name='{{ name }}',
author='{{ author }}',
author_email='{{ author_email }}',
description='{{ description }}',
install_requires=[
'pykern',
],
license='{{ license }}',
url='{{ url }}',
classifiers=[
Expand Down
30 changes: 20 additions & 10 deletions pykern/pksetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class is provided by this module.
import locale
import os
import os.path
import pip
import pip.download
import pip.req
import pkg_resources
import re
import setuptools
Expand Down Expand Up @@ -120,6 +117,7 @@ class PKDeploy(NullCommand):
def run(self):
if self.distribution.dry_run:
raise ValueError('--dry-run not supported')
assert 0
self.__env = {}
# We assert these values before git clean, which would be a nasty
# surprise if executed in an ordinary development environ
Expand Down Expand Up @@ -259,17 +257,31 @@ def run(self, *args, **kwargs):
tox_ini = '''# OVERWRITTEN by pykern.pksetup every "python setup.py tox" run
[tox]
envlist={pyenv}
sitepackages=True
[testenv]
passenv=PKSETUP_PKDEPLOY_IS_DEV CFLAGS CPPFLAGS LDFLAGS TRAVIS
deps=-rrequirements.txt
deps={deps}
commands=python setup.py build test
[testenv:docs]
basepython=python
changedir=docs
commands=sphinx-build -b html -d {{envtmpdir}}/doctrees . {{envtmpdir}}/html
'''
try:
_write(TOX_INI_FILE, tox_ini.format(pyenv=self._pyenv(params)))
deps = 'pykern'
d = os.path.dirname(os.path.dirname(__file__))
if os.path.exists(os.path.join(d, 'setup.py')):
# use local copy of pykern
deps = '-e' + d
if os.path.exists('requirements.txt'):
deps += ' -rrequirements.txt '
_write(
TOX_INI_FILE,
tox_ini.format(
deps=deps,
pyenv=self._pyenv(params),
),
)
subprocess.check_call(['tox'])
finally:
_remove(TOX_INI_FILE)
Expand Down Expand Up @@ -304,11 +316,9 @@ def install_requires():
Returns:
dict: parsed requirements.txt
"""
reqs = pip.req.parse_requirements(
'requirements.txt', session=pip.download.PipSession())
# the conditional on i.req avoids the error:
# distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('None')
install_requires = [str(i.req) for i in reqs if i.req]
import requirements
with open('requirements.txt', 'r') as f:
install_requires = [str(i.line) for i in requirements.parse(f) if i.name]
return install_requires


Expand Down
28 changes: 0 additions & 28 deletions requirements.txt

This file was deleted.

38 changes: 23 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Install PyKern
:copyright: Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.
:copyright: Copyright (c) 2015-2018 RadiaSoft LLC. All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from pykern.pksetup import setup
Expand All @@ -11,22 +11,30 @@
description='Python application support',
author='RadiaSoft LLC',
author_email='[email protected]',
install_requires=[
'argh>=0.26',
'future>=0.14',
'github3.py>=1.1',
'jinja2>=2.7',
'py-cpuinfo>=0.2',
'py>=1.4',
# capsys may not be working right in 3.3
'pytest>=2.7,<=3.2.3',
'pytest-forked>=0.2',
'pytz>=2015.4',
'pyyaml>=3.0',
'requests>=2.7',
'requirements-parser>=0.2.0',
'setuptools>=20.3',
'six>=1.9',
'sphinx>=1.3.5',
'twine>=1.9',
'tox>=1.9',
'path.py>=7.7.1',
'python-dateutil>=2.4.2',
],
license='http://www.apache.org/licenses/LICENSE-2.0.html',
url='http://pykern.org',
extras_require={
'jupyterhub': [
# Really want git versions, but this fmt is invalid:
# git+git://github.com/jupyterhub/jupyterhub
# git+git://github.com/jupyterhub/dockerspawner
# git+git://github.com/jupyterhub/oauthenticator
'jupyterhub',
'dockerspawner',
'oauthenticator',
],
},
# entry_points={
# 'pytest11': ['pykern = pykern.pytest_plugin'],
# },
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand Down
8 changes: 3 additions & 5 deletions tests/pkcli/projex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def test_init_tree():
('docs/_static/.gitignore', ''),
('docs/_templates/.gitignore', ''),
('docs/index.rst', name),
('requirements.txt', 'pykern'),
('setup.py', "author='zauthor'"),
('setup.py', r':copyright:.*zauthor\.'),
('tests/.gitignore', '_work'),
Expand All @@ -79,9 +78,8 @@ def test_init_tree():
'{} should exist and match "{}"'.format(expect_fn, expect_re)
subprocess.check_call(['git', 'commit', '-m', 'initial'])
# Do not install from PyPI
pkio.write_text(
'requirements.txt',
'-e ' + str(py.path.local(__file__).dirpath().dirpath().dirpath()),
);
pykern_path = py.path.local(__file__).dirpath().dirpath().dirpath()
# pykern must be installed for setup.py to be able to be called
subprocess.check_call(['pip', 'install', '-e', str(pykern_path)])
subprocess.check_call(['python', 'setup.py', 'test'])
subprocess.check_call(['python', 'setup.py', 'tox'])

0 comments on commit c41c95d

Please sign in to comment.