Skip to content

Commit

Permalink
Fixed #113 (removed link & unlink commands)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubik committed Aug 16, 2011
1 parent 7efd103 commit 40afc20
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 67 deletions.
3 changes: 0 additions & 3 deletions pyg/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ class ArgsManager(object):
'no_info': False,
'file': None
},
'unlink': {
'all': True
},
'download': {
'unpack': False,
'download_dir': '.',
Expand Down
12 changes: 10 additions & 2 deletions pyg/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _gen_executable(req_name, code):

class Packer(object):

EMPTY, INI, CAT, SCAT, MERGE = range(5)
EMPTY, INI, CAT, SCAT, MERGE, PACKAGES = range(6)
REQ = 42

EGG_FILES = {
Expand All @@ -79,6 +79,7 @@ class Packer(object):
'requires.txt': EMPTY,
'SOURCES.txt': SCAT,
'top_level.txt': SCAT,
'packages.txt': PACKAGES,
'spec/depend': """metadata_version = '1.1'
name = {req!r}
version = {req_version!r}
Expand Down Expand Up @@ -108,6 +109,11 @@ def _bundle_callback(self, req, sdist):
sdist._name, sdist._version = req.name, req.version
self.bundled[sdist.name.replace('-', '_')] = sdist

def packages(self, spaces=True, commas=True):
s = ' ' if spaces else ''
c = ',' if commas else ''
return (c + '\n' + s).join('{0.name} {0.version}'.format(dist) for dist in self.bundled.values())

def _fill_metadata(self):
content = self.EGG_FILES['spec/depend']
req_version = self.req.version
Expand All @@ -125,7 +131,7 @@ def _fill_metadata(self):
arch=platform.machine(),
platform=sys.platform,
python_version='.'.join(map(str, sys.version_info[:2])),
packages=',\n '.join('{0.name} {0.version}'.format(dist) for dist in self.bundled.values())
packages=self.packages()
)

def _safe_readlines(self, dist, filename):
Expand All @@ -147,6 +153,8 @@ def _mk_egg_info(self, egg_info_dir):
deps = dict((name, self._safe_readlines(dist, mfile)) for name, dist in self.bundled.iteritems())
if data == self.EMPTY:
content = ''
elif data == self.PACKAGES:
content = self.packages(False, False)
elif data == self.INI:
ini_file = {}
for dep, content in deps.iteritems():
Expand Down
15 changes: 1 addition & 14 deletions pyg/parser/_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from pyg.freeze import freeze, list_releases, site_info
from pyg.core import PygError, Version, args_manager
from pyg.inst import Installer, Uninstaller, Updater, Bundler
from pyg.locations import PYG_LINKS
from pyg.utils import TempDir, is_installed, link, unlink, unpack
from pyg.utils import TempDir, is_installed, unpack
from pyg.web import ReqManager


Expand Down Expand Up @@ -121,18 +120,6 @@ def remove_func(packname, req_file, yes, info, local):
except PygError:
continue

def link_func(path):
return link(path)

def unlink_func(path, all):
if all:
try:
os.remove(PYG_LINKS)
except OSError:
pass
return
return unlink(path)

def check_func(name, info=False):
INFO = '{0.project_name} - {0.version}\nInstalled in {0.location}'
if not info:
Expand Down
22 changes: 1 addition & 21 deletions pyg/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

ITERABLE_T = (list, tuple)
COMMANDS = set(['install', 'remove', 'bundle', 'pack', 'download', 'update',
'search', 'list', 'site', 'check', 'link', 'unlink', 'shell',
'completion', 'help'])
'search', 'list', 'site', 'check', 'shell', 'completion', 'help'])


def load_options():
Expand Down Expand Up @@ -151,25 +150,6 @@ def site(args):
args_manager['site']['no_info'], args_manager['site']['file']
opts.site_func(count, no_info, file)

@command
def link(path):
'''
Add a directory to PYTHONPATH
'''

opts.link_func(path)

@arg('path', nargs='?')
@arg('-a', '--all', action='store_true', help='Remove all links')
def unlink(args):
'''
Remove a previously added directory (with link) from PYTHONPATH
'''

if args.all:
args_manager['unlink']['all'] = True
opts.unlink_func(args)

@arg('query', nargs='+')
@arg('-i', '--index-url', default='http://pypi.python.org', metavar='<url>', help='Base URL of Python Package Index (default to %(default)s)')
@arg('-e', '--exact', action='store_true', help='List only exact hits')
Expand Down
27 changes: 0 additions & 27 deletions pyg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,6 @@ def version_egg(eggname):
eggv = re.compile(r'py(\d\.\d)')
return eggv.search(eggname).group(1)

def link(path):
path = os.path.abspath(path)
if not os.path.exists(path):
logger.error('{0} does not exist', path)
if not os.path.exists(PYG_LINKS):
if not os.path.exists(os.path.dirname(PYG_LINKS)):
os.makedirs(os.path.dirname(PYG_LINKS))
open(PYG_LINKS, 'w').close()
path = os.path.abspath(path)
logger.info('Linking {0} in {1}...', path, PYG_LINKS)
if path in open(PYG_LINKS, 'r').read():
logger.warn('{0} is already linked, exiting now...', path)
with open(PYG_LINKS, 'a') as f:
f.write(path)
f.write('\n')

def unlink(path):
path = os.path.abspath(path)
with open(PYG_LINKS) as f:
lines = f.readlines()
with open(PYG_LINKS, 'w') as f:
for line in lines:
if line.strip() == path:
logger.info('Removing {0} from {1}...', path, PYG_LINKS)
continue
f.write(line)

def call_subprocess(args, cwd=None):
'''
Call subprocess with the given argument and return the tuple
Expand Down
1 change: 1 addition & 0 deletions tests/features/help.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Scenario Outline: Version
Given I execute pyg <cmd>
Then one line matches 0.8a
Then the return code is 0

Examples
| cmd |
| -v |
Expand Down

0 comments on commit 40afc20

Please sign in to comment.