diff --git setuptools/command/easy_install.py setuptools/command/easy_install.py
index fb0f997..76f4e72 100644
|
|
file, or visit the `EasyInstall home page`__. |
10 | 10 | __ http://packages.python.org/distribute/easy_install.html |
11 | 11 | |
12 | 12 | """ |
13 | | import sys, os.path, zipimport, shutil, tempfile, zipfile, re, stat, random |
| 13 | import sys, os.path, zipimport, shutil, tempfile, \ |
| 14 | zipfile, re, stat, random, fcntl |
14 | 15 | from glob import glob |
15 | 16 | from setuptools import Command, _dont_write_bytecode |
16 | 17 | from setuptools.sandbox import run_setup |
… |
… |
class PthDistributions(Environment): |
1492 | 1493 | def __init__(self, filename, sitedirs=()): |
1493 | 1494 | self.filename = filename; self.sitedirs=map(normalize_path, sitedirs) |
1494 | 1495 | self.basedir = normalize_path(os.path.dirname(self.filename)) |
1495 | | self._load(); Environment.__init__(self, [], None, None) |
1496 | | for path in yield_lines(self.paths): |
1497 | | map(self.add, find_distributions(path, True)) |
| 1496 | self.paths = []; self.dist_dict = {} |
| 1497 | Environment.__init__(self, [], None, None); self._load() |
1498 | 1498 | |
1499 | 1499 | def _load(self): |
| 1500 | old_paths = list(yield_lines(self.paths)) |
1500 | 1501 | self.paths = [] |
1501 | 1502 | saw_import = False |
1502 | 1503 | seen = dict.fromkeys(self.sitedirs) |
1503 | 1504 | if os.path.isfile(self.filename): |
1504 | 1505 | f = open(self.filename,'rt') |
| 1506 | fcntl.flock(f, fcntl.LOCK_SH) |
1505 | 1507 | for line in f: |
1506 | 1508 | if line.startswith('import'): |
1507 | 1509 | saw_import = True |
… |
… |
class PthDistributions(Environment): |
1520 | 1522 | self.dirty = True # we cleaned up, so we're dirty now :) |
1521 | 1523 | continue |
1522 | 1524 | seen[path] = 1 |
| 1525 | fcntl.flock(f, fcntl.LOCK_UN) |
1523 | 1526 | f.close() |
1524 | 1527 | |
1525 | 1528 | if self.paths and not saw_import: |
1526 | 1529 | self.dirty = True # ensure anything we touch has import wrappers |
1527 | 1530 | while self.paths and not self.paths[-1].strip(): |
1528 | 1531 | self.paths.pop() |
| 1532 | for path in old_paths: |
| 1533 | if not os.path.exists(path): |
| 1534 | map(self.remove, self.dist_dict[path]) |
| 1535 | elif path not in self.paths: |
| 1536 | self.paths.append(path) |
| 1537 | self.dirty = True |
| 1538 | new_paths = (path for path in self.paths if path not in old_paths) |
| 1539 | for path in yield_lines(new_paths): |
| 1540 | self.dist_dict[path] = find_distributions(path, True) |
| 1541 | map(self.add, self.dist_dict[path]) |
1529 | 1542 | |
1530 | 1543 | def save(self): |
1531 | 1544 | """Write changed .pth file back to disk""" |
| 1545 | f = open(self.filename,'r+t') |
| 1546 | fcntl.flock(f, fcntl.LOCK_SH) |
| 1547 | self._load() |
1532 | 1548 | if not self.dirty: |
| 1549 | f.close() |
| 1550 | fcntl.flock(f, fcntl.LOCK_UN) |
1533 | 1551 | return |
1534 | 1552 | |
1535 | 1553 | data = '\n'.join(map(self.make_relative,self.paths)) |
… |
… |
class PthDistributions(Environment): |
1544 | 1562 | " sys.__egginsert = p+len(new)\n" |
1545 | 1563 | ) % data |
1546 | 1564 | |
1547 | | if os.path.islink(self.filename): |
1548 | | os.unlink(self.filename) |
1549 | | f = open(self.filename,'wt') |
1550 | | f.write(data); f.close() |
| 1565 | # overwrite anything extra with whitespace |
| 1566 | data += ' '*(len(open(self.filename,'rt').read())-len(data)) |
1551 | 1567 | |
1552 | | elif os.path.exists(self.filename): |
1553 | | log.debug("Deleting empty %s", self.filename) |
1554 | | os.unlink(self.filename) |
| 1568 | fcntl.flock(f, fcntl.LOCK_EX) |
| 1569 | f.write(data) |
| 1570 | fcntl.flock(f, fcntl.LOCK_UN) |
| 1571 | f.close() |
1555 | 1572 | |
1556 | 1573 | self.dirty = False |
1557 | 1574 | |
… |
… |
class PthDistributions(Environment): |
1562 | 1579 | dist.location == os.getcwd() #account for '.' being in PYTHONPATH |
1563 | 1580 | )): |
1564 | 1581 | self.paths.append(dist.location) |
| 1582 | self.dist_dict[dist.location] = [dist] |
1565 | 1583 | self.dirty = True |
1566 | 1584 | Environment.add(self,dist) |
1567 | 1585 | |
… |
… |
class PthDistributions(Environment): |
1569 | 1587 | """Remove `dist` from the distribution map""" |
1570 | 1588 | while dist.location in self.paths: |
1571 | 1589 | self.paths.remove(dist.location); self.dirty = True |
| 1590 | if dist.location in self.dist_paths: |
| 1591 | self.dist_dict[dist.location] = None |
1572 | 1592 | Environment.remove(self,dist) |
1573 | 1593 | |
1574 | 1594 | |