Esempio n. 1
0
    def save(self, pypi_version, current_time):
        # type: (str, datetime.datetime) -> None
        # If we do not have a path to cache in, don't bother saving.
        if not self.statefile_path:
            return

        # Check to make sure that we own the directory
        if not check_path_owner(os.path.dirname(self.statefile_path)):
            return

        # Now that we've ensured the directory is owned by this user, we'll go
        # ahead and make sure that all our directories are created.
        ensure_dir(os.path.dirname(self.statefile_path))

        # Attempt to write out our version check file
        with lockfile.LockFile(self.statefile_path):
            if os.path.exists(self.statefile_path):
                with open(self.statefile_path) as statefile:
                    state = json.load(statefile)
            else:
                state = {}

            state[sys.prefix] = {
                "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
                "pypi_version": pypi_version,
            }

            with open(self.statefile_path, "w") as statefile:
                json.dump(state,
                          statefile,
                          sort_keys=True,
                          separators=(",", ":"))
Esempio n. 2
0
    def save(self, pypi_version, current_time):
        # Check to make sure that we own the directory
        if not check_path_owner(os.path.dirname(self.statefile_path)):
            return

        # Now that we've ensured the directory is owned by this user, we'll go
        # ahead and make sure that all our directories are created.
        try:
            os.makedirs(os.path.dirname(self.statefile_path))
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise

        # Attempt to write out our version check file
        with lockfile.LockFile(self.statefile_path):
            with open(self.statefile_path) as statefile:
                state = json.load(statefile)

            state[sys.prefix] = {
                "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
                "pypi_version": pypi_version,
            }

            with open(self.statefile_path, "w") as statefile:
                json.dump(state,
                          statefile,
                          sort_keys=True,
                          separators=(",", ":"))
Esempio n. 3
0
    def save(self, pypi_version, current_time):
        # type: (str, datetime.datetime) -> None
        # If we do not have a path to cache in, don't bother saving.
        if not self.statefile_path:
            return

        # Check to make sure that we own the directory
        if not check_path_owner(os.path.dirname(self.statefile_path)):
            return

        # Now that we've ensured the directory is owned by this user, we'll go
        # ahead and make sure that all our directories are created.
        ensure_dir(os.path.dirname(self.statefile_path))

        state = {
            # Include the key so it's easy to tell which pip wrote the
            # file.
            "key": self.key,
            "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
            "pypi_version": pypi_version,
        }

        text = json.dumps(state, sort_keys=True, separators=(",", ":"))

        # Attempt to write out our version check file
        with lockfile.LockFile(self.statefile_path):
            # Since we have a prefix-specific state file, we can just
            # overwrite whatever is there, no need to check.
            with open(self.statefile_path, "w") as statefile:
                statefile.write(text)
Esempio n. 4
0
    def save(self, pypi_version, current_time):
        # Attempt to write out our version check file
        with lockfile.LockFile(self.statefile_path):
            with open(self.statefile_path) as statefile:
                state = json.load(statefile)

            state[sys.prefix] = {
                "last_check": current_time.strftime(SELFCHECK_DATE_FMT),
                "pypi_version": pypi_version,
            }

            with open(self.statefile_path, "w") as statefile:
                json.dump(state,
                          statefile,
                          sort_keys=True,
                          separators=(",", ":"))
Esempio n. 5
0
def hada_pairs_core_threadsafe(emb, gender, filename, pair, label):

    count1, count = 0, 0
    outer_arr = []
    for u1, u2 in pair:

        u1_vector = emb.loc[emb.uid == u1, range(1, emb.shape[1])]
        u2_vector = emb.loc[emb.uid == u2, range(1, emb.shape[1])]

        try:
            val = HADAMARD(u1_vector, u2_vector)

            if gender[u1] == 0:
                if gender[u2] == 0:
                    group = 0
                elif gender[u2] == 1:
                    group = 1
            elif gender[u1] == 1:
                if gender[u2] == 0:
                    group = 2
                elif gender[u2] == 1:
                    group = 3

            in_arr = [u1, u2, label, group]

            for i in range(0, emb.shape[1] - 1):
                in_arr.append(val[0][i])

            outer_arr.append(in_arr)

        except Exception:
            print u1, u2
            count += 1
    df = pd.DataFrame(outer_arr)
    with lockfile.LockFile(filename):
        df.to_csv(filename, index=False, header=None, mode='a')
    print len(outer_arr), "rows"
    print count, " pairs failed"