Skip to content

Commit

Permalink
Make shorter Environment hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
vinisalazar committed Apr 24, 2021
1 parent 1a46320 commit 7961dcb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Improve reserved aminoacid characters [x]
* Add `SeqFile.max_seq` and `.min_seq` properties [x]
* Patch `Project` deserializer to improve BioProvDocument creation [x]
* Make shorter Environment hashes [x]

### v0.1.22
* Simplify `bp.load_project()` function [x]
Expand Down
8 changes: 5 additions & 3 deletions bioprov/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,15 @@ def __init__(self):
Class constructor. All attributes are empty and are initialized with self.update()
"""
self.env_hash = None
self.env_hash_long = None
self.env_dict = None
self.user = None
self.env_namespace = None
self.update()
self._actedOnBehalfOf = False

def __repr__(self):
return self.env_hash
return f"BioProvEnvironment{self.env_hash}"

@property
def actedOnBehalfOf(self):
Expand All @@ -294,9 +295,10 @@ def update(self):
"""
env_dict = dict(os.environ.items())
env_hash = dict_to_sha256(env_dict)
if env_hash != self.env_hash:
if env_hash != self.env_hash_long:
self.env_dict = env_dict
self.env_hash = env_hash
self.env_hash = env_hash[:7]
self.env_hash_long = env_hash

# this is only to prevent build errors
try:
Expand Down
4 changes: 2 additions & 2 deletions bioprov/src/prov.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ def _create_program_entities(self, sample, kind="Sample"):
):
if self.add_attributes:
self._agents[_env_hash] = _user_bundle.agent(
f"envs:{_env}",
f"envs:{_env_hash}",
other_attributes=build_prov_attributes(
_env.env_dict, _env.env_namespace
),
)
else:
self._agents[_env_hash] = _user_bundle.agent(
f"envs:{_env}"
f"envs:{_env_hash}"
)
if not _env.actedOnBehalfOf:
_user_bundle.actedOnBehalfOf(
Expand Down
4 changes: 3 additions & 1 deletion bioprov/tests/test_src_prov.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def test_EnvProv():
:return:
"""
env = Environment()
sh = dict_to_sha256(env.env_dict)
for statement in (
env.env_dict == dict(environ.items()),
env.env_hash == dict_to_sha256(env.env_dict),
env.env_hash_long == sh,
env.env_hash == sh[:7],
):
assert statement

Expand Down

0 comments on commit 7961dcb

Please sign in to comment.