Skip to content

Commit

Permalink
Avoid extra entries in conandata.
Browse files Browse the repository at this point in the history
When export with conan export it will include all data in it, including
that of all other package versions. That dirties all packages when a
new version is added. This change resolves that issue by injecting
a hook at export time that cleans the conandata to only include the
relevant version fields.

fixes bfgroup/barbarian#16
  • Loading branch information
grafikrobot committed Nov 10, 2021
1 parent ad4322f commit 9b2917f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import setup, find_namespace_packages
import os

VERSION = '0.1.2'
VERSION = '0.2.0'

print("TEST_VERSION:", os.getenv('TEST_VERSION'))
if os.getenv('GHA_TEST_VERSION'):
Expand Down
15 changes: 14 additions & 1 deletion src/barbarians/barbarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from argparse import ArgumentParser, Action
from os import environ, getcwd, chdir, listdir
from shutil import rmtree, copytree
from shutil import rmtree, copytree, copy
from subprocess import run, PIPE, CalledProcessError
import hashlib
import json
Expand Down Expand Up @@ -303,7 +303,18 @@ def conan_api(self):
if not self._conan_api:
self._conan_api = conans.client.conan_api.Conan(
cache_folder=os.path.join(self.root_dir, '.conan'))
# Create local conan config, if needed.
self._conan_api.config_init()
# Barbarian only works with recipe revisions.
self._conan_api.config_set("general.revisions_enabled", "True")
# Install hooks for manipulating and checking packages.
hooks_dir_src = os.path.join(os.path.dirname(
os.path.abspath(__file__)), "hooks")
hooks_dir_dst = os.path.join(self.root_dir, '.conan', 'hooks')
for name in os.listdir(hooks_dir_src):
if name.endswith('.py'):
copy(os.path.join(hooks_dir_src, name),
os.path.join(hooks_dir_dst, name))
return self._conan_api

def have_branch(self, branch):
Expand Down Expand Up @@ -378,6 +389,8 @@ def command_export(self, args):
if not '/.conan/' in gitignore:
gitignore = "/.conan/\n" + gitignore
tools.save(gitignore_path, gitignore)
# Enable needed hooks.
self.conan_api.config_set('hooks.barbarian_clean_conandata_yml', "")
# Do the basic export.
self.conan_api.export(
args.path,
Expand Down
30 changes: 30 additions & 0 deletions src/barbarians/hooks/barbarian_clean_conandata_yml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021 René Ferdinand Rivera Morell
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or http://www.boost.org/LICENSE_1_0.txt)

'''
Hook to clean the conandata.yml information for Barbarian style packages.
'''

import os.path
import yaml
import conans.tools


def post_export(output, conanfile, conanfile_path, reference, **args):
conandata_yml_path = os.path.join(
os.path.dirname(conanfile_path), "conandata.yml")
if not os.path.exists(conandata_yml_path):
return
conandata_yml_in = yaml.safe_load(conans.tools.load(conandata_yml_path))
conandata_yml_out = {}
# Filter the data to only keep the sections and subkeys that match the
# exported version.
version = str(conanfile.version)
for section in conandata_yml_in:
if version in conandata_yml_in[section]:
conandata_yml_out[section] = {
version: conandata_yml_in[section][version]
}
# Overwrite out the conandata.yml with the updated info.
conans.tools.save(conandata_yml_path, yaml.safe_dump(conandata_yml_out))

0 comments on commit 9b2917f

Please sign in to comment.