Skip to content

Use native namespace package #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,3 @@ To use this solver (backend) with [`MixedIntegerLinearProgram`](http://doc.sagem
sage: M.get_backend()
<sage_numerical_backends_coin.coin_backend.CoinBackend object at 0x7fb72c2c7868>

Setting it as the default backend for `MixedIntegerLinearProgram`, as of SageMath 9.0.beta10, requires some trickery:

sage: import sage_numerical_backends_coin.coin_backend as coin_backend, sage.numerical.backends as backends, sys
sage: sys.modules['sage.numerical.backends.coin_backend'] = backends.coin_backend = coin_backend
sage: default_mip_solver('Coin')

To patch this in permanently (at your own risk):

$ sage -c 'import os; import sage.numerical.backends as dm; import sage_numerical_backends_coin.coin_backend as sm; s = sm.__file__; f = os.path.basename(s); d = os.path.join(dm.__path__[0], f); (os.path.exists(d) or os.path.lexists(d)) and os.remove(d); os.symlink(s, d);'

Or use the script [`patch_into_sage_module.py`](patch_into_sage_module.py) in the source distribution that does the same:

$ sage -c 'load("patch_into_sage_module.py")'
Success: Patched in the module as sage.numerical.backends.coin_backend

Verify with [`check_get_solver_with_name.py`](check_get_solver_with_name.py) that the patching script has worked:

$ sage -c 'load("check_get_solver_with_name.py")'
Success: get_solver(solver='coin') gives <sage_numerical_backends_coin.coin_backend.CoinBackend object at 0x7f8f20218528>
2 changes: 1 addition & 1 deletion check_get_solver_with_name.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import print_function
# Check that the backend can be obtained by passing solver='coin' to get_solver.
from sage.numerical.backends.generic_backend import get_solver
from sage_numerical_backends_coin.coin_backend import CoinBackend
from sage.numerical.backends.coin_backend import CoinBackend
b = get_solver(solver='coin')
assert type(b) == CoinBackend, "get_solver(solver='coin') does not give an instance of sage_numerical_backends_coin.coin_backend.CoinBackend"
print("Success: get_solver(solver='coin') gives {}".format(b))
1 change: 0 additions & 1 deletion sage_numerical_backends_coin/__init__.py

This file was deleted.

11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def readfile(filename):
cbc_include_dirs = cbc_pc['include_dirs']


ext_modules = [Extension('sage_numerical_backends_coin.coin_backend',
sources=[os.path.join('sage_numerical_backends_coin',
ext_modules = [Extension('sage.numerical.backends.coin_backend',
sources=[os.path.join('sage/numerical/backends',
'coin_backend.pyx')],
libraries=cbc_libs,
include_dirs=sage_include_directories() + cbc_include_dirs,
Expand Down Expand Up @@ -81,7 +81,7 @@ def readfile(filename):
print("Using compile_time_env: {}".format(compile_time_env), file=sys.stderr)

setup(
name="sage_numerical_backends_coin",
name="sage.numerical.backends.coin_backend",
version=readfile("VERSION").strip(),
description="COIN-OR backend for Sage MixedIntegerLinearProgram",
long_description = readfile("README.md"), # get the long description from the README
Expand Down Expand Up @@ -109,9 +109,8 @@ def readfile(filename):
compile_time_env=compile_time_env),
cmdclass = {'test': SageTest}, # adding a special setup command for tests
keywords=['milp', 'linear-programming', 'optimization'],
packages=['sage_numerical_backends_coin'],
package_dir={'sage_numerical_backends_coin': 'sage_numerical_backends_coin'},
package_data={'sage_numerical_backends_coin': ['*.pxd']},
packages=['sage.numerical.backends'],
package_data={'sage.numerical.backends': ['*.pxd']},
install_requires = [# 'sage>=8', ### On too many distributions, sage is actually not known as a pip package
'sphinx'],
setup_requires = ['pkgconfig'],
Expand Down