Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Bintray Package Info #2

Merged
merged 61 commits into from
Jan 29, 2019

Conversation

uilianries
Copy link
Member

Hi!

This PR is about a plugin to update Bintray package page.

For each new package created, we need to fill manually Bintray page, but all needed data could be extract from the recipe.

Related issue: bincrafters/community#476

@danimtb
Copy link
Member

danimtb commented Oct 11, 2018

I really like the idea of this new plugin as Bintray still does not fill metadata automatically, but we will have to wait to make a decision on how plugins will be managed for installation, versioning and activation and what will be the long-term purpose of repository. Please, keep the PR open and I will try to discuss it with the team. Many thanks!!!

@jgsogo
Copy link
Contributor

jgsogo commented Jan 2, 2019

We have added Travis and AppVeyor CI to this repo and an example test for the attribute_checker hook. We need to merge master into this PR (to get CI) and then implement some tests to check that the hook is working (it should be easy to mock requests.get function, but ping me if you need help).

Thanks!

@uilianries
Copy link
Member Author

@jgsogo the bintray hook is updated!

Since it requires bintray api and interface validation I would prefer to create a fake package to validate all steps:

https://bintray.com/conan-community/test-distribution/foo%3Abar

You will need to set CONAN_LOGIN_USERNAME_VIRTUAL and CONAN_PASSWORD_VIRTUAL. Both values are the same used for conan community login.

TIL: If you need to get an environment variable when running tox, just use passenv instead of spending 2h trying all kind of workaround ...

@uilianries
Copy link
Member Author

Ops!

ERROR: [HOOK - conan-center.py] post_build(): 'settings.os' doesn't exist
'settings' possible configurations are ['arch_build', 'os_build']
Traceback (most recent call last):
  File "/opt/miniconda3/lib/python3.6/site-packages/conans/client/hook_manager.py", line 56, in execute
    method(output, **kwargs)
  File "/home/uilian/.conan/hooks/conan-center.py", line 121, in post_build
    if not _files_match_settings(conanfile, conanfile.build_folder):
  File "/home/uilian/.conan/hooks/conan-center.py", line 209, in _files_match_settings
    if conanfile.settings.os == "Windows":
  File "/opt/miniconda3/lib/python3.6/site-packages/conans/model/settings.py", line 257, in __getattr__
    self._check_field(field)
  File "/opt/miniconda3/lib/python3.6/site-packages/conans/model/settings.py", line 253, in _check_field
    raise undefined_field(self._name, field, self.fields, self._parent_value)
conans.errors.ConanException: 'settings.os' doesn't exist
'settings' possible configurations are ['arch_build', 'os_build']

I need to support installer packages too.

Copy link
Contributor

@jgsogo jgsogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes related to the renaming from plugins to hooks.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
hooks/bintray-update.py Outdated Show resolved Hide resolved
@jgsogo
Copy link
Contributor

jgsogo commented Jan 8, 2019

Having a look at this PR I have some doubts about the test suite. Do you think it is ok to call Conan CLI or shall we just test the hook function with mocked arguments?

In the beginning, I thought that it would be ok to use Conan CLI, this way we can test our hooks against different versions of Conan itself (it is what I did with the attribute_checker hook), but now I see that this approach has several drawbacks in order to mock functions: as we are running an external tool through command line, this is no longer our program and we cannot mock function calls :/, so:

  1. we can use conan_api (undocumented, not stable) to avoid using CLI, or
  2. we can test just the hook function using fake arguments.

Each approach has pros and cons:

  1. conan_api is not stable and it might be modified, we can encapsulate these modifications inside a helper conan client that we will need to maintain and it will get more and more confusing; but we will be sure that all the Conan workflow will be taken into account for our hooks.

    We will need to run all tests against all (supported) versions of Conan, like it is implemented now.

  2. Faster, easier and safer, nothing external to the hook itself will affect the tests. But to keep consistency and check that every Conan version will work, we would need some extra tests, calling the Conan CLI to check that the parameters that get to the hooks functions are the expected ones (the ones we will be mocking in the actual tests).

    No need to run the tests related to the hooks against different Conan versions, only the tests which check that the arguments that reach the hooks functions are the expected ones.

In any case, I think that we should mock the calls to external services, we can store sample json responses (also failing ones) and our test suite won't rely on Bintray status.
What about if Bintray changes its API? Well, I suppose it won't happen too often, but we can run tests against Bintray API and check our stored jsons against the returned ones, this way we will know if a failing test is due to our code or to Bintray changes.

What do you think about this dissertation?

@uilianries
Copy link
Member Author

I really appreciate your feedback! I thought in both ideas before.

I've Conan API used for many scripts and Bincrafters' projects, but as you said, it will be changed often.

I like the second option, add mocks, sounds more "clean", but I don't know how to make it correctly. This hook needs to make requests to Bintray, change all metadata and check the results. If we are trying to make an integration test, so we couldn't not change the client side I think, we should be able to mock bintray side only. However, we would need to create fake answers based on Bintray and Conan REST API, but it sounds like creating a framework just to check a small piece of code.

Maybe, instead to run requests directly, we could use some part of Conan base code (Uploader class, just a guess), with an well known mock supported from Conan tests.

@jgsogo
Copy link
Contributor

jgsogo commented Jan 8, 2019

Talking about second option: testing just the hook function with mocked arguments

  • we can mock requests.get function with something like (this is not going to work, I haven't tested it):

    from mock import patch
    ...
    
    def side_effect(url, ...):
       # Read proper file depending on URL passed as argument
       return file_json
    
    # Prepare the arguments for the hook
    # Mock the requests object
    with patch.object("requests.get", side_effect= side_effect):
       # Run the hook function
       post_upload(arguments,...)

There are still integration tests:

  • [Required] run a single test for every conan version (like it is implemented now in the CI), using a test_framework_hook that checks that the inputs for every hook are the expected
  • [Optional] check that the json returned from Bintray and the one stored in the files that we are using to mock requests.get are equal.

uilianries added a commit to uilianries/hooks that referenced this pull request Jan 8, 2019
Signed-off-by: Uilian Ries <uilianries@gmail.com>
uilianries added a commit to uilianries/hooks that referenced this pull request Jan 8, 2019
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

@jgsogo I made some changes following your points. Thanks for the example, it helped me to understand how to mock requests 👍

Okay, the new test calls the hook directly, and all Bintray's answers are mocked up. I've tried to follow Bintray status code and messages -- All commands were executed to check Bintray's response.

uilianries added a commit to uilianries/hooks that referenced this pull request Jan 8, 2019
Signed-off-by: Uilian Ries <uilianries@gmail.com>
uilianries added a commit to uilianries/hooks that referenced this pull request Jan 8, 2019
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Copy link
Contributor

@jgsogo jgsogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks very good, just a couple of comments... and it is on my side to refactor the test suite ^^

tests/test_hooks/test_update_bintray.py Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
tests/test_hooks/test_update_bintray.py Outdated Show resolved Hide resolved
@uilianries
Copy link
Member Author

@jgsogo I've updated the unit tests, but as hooks doesn't have __init__.py, I've added hooks dir in the path: https://github.com/conan-io/hooks/pull/2/files#diff-8eebc7307c1e61c5efaea1449796443cR19

hooks/bintray_update.py Show resolved Hide resolved
hooks/bintray_update.py Outdated Show resolved Hide resolved
hooks/bintray_update.py Outdated Show resolved Hide resolved
hooks/bintray_update.py Outdated Show resolved Hide resolved
hooks/conan-center.py Outdated Show resolved Hide resolved
hooks/bintray_update.py Show resolved Hide resolved
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
- Topics read from Bintray are not sorted

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
@uilianries
Copy link
Member Author

Up! Should we wait for #16 before to merge this PR?

@jgsogo
Copy link
Contributor

jgsogo commented Jan 16, 2019

yes, #16 is the top priority now in this repo. I don't if #16 will get merged, but that discussion should be resolved before merging anything else (tests could be completely different)

@jgsogo
Copy link
Contributor

jgsogo commented Jan 28, 2019

Hi @uilianries, we really want to start promoting hooks and this one can be very interesting. Although I think that testing will follow the approach in #17 (more or less like it is now) maybe it is better to split this PR into two: the hook itself (to be merged as soon as possible), and the testing part (so we can comment about it).

Also, please add a little documentation in the README.md, we are not sure if that will be the final place for documentation, but at least it will be the first place.

Thanks

@uilianries
Copy link
Member Author

Understood, I gonna do it today 😸

.travis.yml Show resolved Hide resolved
Copy link
Contributor

@jgsogo jgsogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

README.md Outdated Show resolved Hide resolved
tests/utils/test_cases/conan_client.py Outdated Show resolved Hide resolved
Signed-off-by: Uilian Ries <uilianries@gmail.com>
Signed-off-by: Uilian Ries <uilianries@gmail.com>
tox.ini Outdated Show resolved Hide resolved
Copy link
Contributor

@jgsogo jgsogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Waiting for CI

@jgsogo jgsogo requested a review from danimtb January 28, 2019 16:38
@jgsogo jgsogo added the enhancement New feature or request label Jan 28, 2019
@uilianries
Copy link
Member Author

Thanks Javi!

@uilianries
Copy link
Member Author

@jgsogo All green!

@jgsogo
Copy link
Contributor

jgsogo commented Jan 29, 2019

Waiting for @danimtb to merge it.

@danimtb danimtb merged commit b42d22c into conan-io:master Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants