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

include stage1_config.json in package #1752

Merged
merged 9 commits into from
Aug 3, 2021

Conversation

nbiederbeck
Copy link
Contributor

I included the stage1_config.json in ctapipe/examples, so the tests can use the packaged one. However, I am not sure about the naming of the directory.

This will fix #1750

@nbiederbeck nbiederbeck changed the title Importlib resources include stage1_config.json in package Jun 25, 2021
Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

This is great, thanks.

Two points:

a) I would probably just add the json file into a resources directory in ctapipe/tools/tests/resources. It is in this case not really an example, but a non-code file needed for the tests.
b) wee need to add importlib_resources to the required packages for python < 3.9.

@nbiederbeck
Copy link
Contributor Author

nbiederbeck commented Jun 25, 2021

a) I would probably just add the json file into a resources directory in ctapipe/tools/tests/resources. It is in this case not really an example, but a non-code file needed for the tests.

Yes, that is what I meant. Not really an example in this case anymore. But should we keep this also in the top-level examples? So that it is twice in the repo, but once in the package?

b) wee need to add importlib_resources to the required packages for python < 3.9.

Is it possible to require this only if python < 3.9 ? I just put it into tests_require for now

@codecov
Copy link

codecov bot commented Jun 25, 2021

Codecov Report

Merging #1752 (1ab8661) into master (cdd2fe5) will decrease coverage by 0.25%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1752      +/-   ##
==========================================
- Coverage   92.04%   91.78%   -0.26%     
==========================================
  Files         187      187              
  Lines       14696    14706      +10     
==========================================
- Hits        13527    13498      -29     
- Misses       1169     1208      +39     
Impacted Files Coverage Δ
ctapipe/tools/tests/test_merge.py 100.00% <100.00%> (ø)
ctapipe/tools/tests/test_process.py 95.29% <100.00%> (+0.17%) ⬆️
ctapipe/tools/fileinfo.py 18.36% <0.00%> (-71.43%) ⬇️
ctapipe/tools/utils.py 80.00% <0.00%> (-13.34%) ⬇️
ctapipe/conftest.py 95.41% <0.00%> (ø)
ctapipe/tools/process.py 95.45% <0.00%> (ø)
ctapipe/image/image_processor.py 100.00% <0.00%> (ø)
ctapipe/image/tests/test_image_processor.py 100.00% <0.00%> (ø)
ctapipe/reco/tests/test_shower_processor.py 100.00% <0.00%> (ø)
ctapipe/io/eventsource.py 94.00% <0.00%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cdd2fe5...1ab8661. Read the comment docs.

@nbiederbeck
Copy link
Contributor Author

Is it possible to require this only if python < 3.9 ? I just put it into tests_require for now

for future reference: yes you can, with environment markers from pep 508

setup.py Outdated Show resolved Hide resolved
Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

I needed to add "resouces/*" to package data to make setuptools include a json file in ctapipe/tools/tests/resources/ to the wheels / source dists:

 81 ⋮ 81 │    ],
 82 ⋮ 82 │    zip_safe=False,
 83 ⋮ 83 │    entry_points=entry_points,
 84 ⋮    │    package_data={"": ["tools/bokeh/*.yaml", "tools/bokeh/templates/*.html"]},
    ⋮ 84 │    package_data={
    ⋮ 85 │        "": [
    ⋮ 86 │            "tools/bokeh/*.yaml",
    ⋮ 87 │            "tools/bokeh/templates/*.html",
    ⋮ 88 │            "resources/*",
    ⋮ 89 │        ]
    ⋮ 90 │    },
 85 ⋮ 91 │)

@nbiederbeck
Copy link
Contributor Author

I can reproduce that issue, after cleaning up (rm -rf build *.egg-info)

weird, that the tests still pass ..

kosack
kosack previously approved these changes Jun 28, 2021
maxnoe
maxnoe previously approved these changes Jun 28, 2021
@maxnoe
Copy link
Member

maxnoe commented Jun 28, 2021

Maybe it would be worth to use this setup in the CI to make sure it works.

So I'd suggest to remove the -e in the pip install and use pytest --pyargs ctapipe to run the tests.

@kosack
Copy link
Contributor

kosack commented Jun 28, 2021

It may be worth waiting for #1726 since that introduces several more "standard" config files that need to be used for testing. I only haven't had time to write the tests.

Of course, we eventually need to create a configuration repo in the CTA-GitLab to keep track of real (non-testing) configurations.

Which reminds me, it may be nice to allow configurations from a git repo rather than only as local files, using the same URL scheme that we use for other files. That way we can specify a path like --config git:// with the filename and version tag. See #1754

@maxnoe
Copy link
Member

maxnoe commented Jun 28, 2021

Wouldn't it make sense to do it the other way around? Merge this here first and then you can just add those new config files to the ctapipe/tools/tests/resources folder in the other PR?

@kosack
Copy link
Contributor

kosack commented Jun 28, 2021

Wouldn't it make sense to do it the other way around? Merge this here first and then you can just add those new config files to the ctapipe/tools/tests/resources folder in the other PR?

Yes that's also ok. It has just been hard to maintain that branch with all the changes

kosack
kosack previously approved these changes Jul 22, 2021
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@nbiederbeck
Copy link
Contributor Author

ouch, it seems like I need to review how to do git

@nbiederbeck nbiederbeck force-pushed the importlib-resources branch from c0f480d to d88c8e7 Compare August 3, 2021 14:20
@nbiederbeck nbiederbeck changed the title include stage1_config.json in package Draft: include stage1_config.json in package Aug 3, 2021
@nbiederbeck nbiederbeck marked this pull request as draft August 3, 2021 14:21
@nbiederbeck nbiederbeck removed the request for review from HealthyPear August 3, 2021 14:21
@nbiederbeck nbiederbeck marked this pull request as ready for review August 3, 2021 14:47
@nbiederbeck nbiederbeck changed the title Draft: include stage1_config.json in package include stage1_config.json in package Aug 3, 2021
@nbiederbeck
Copy link
Contributor Author

sorry if anyone was notified unnecessarily.

I now added the resources for the ProcessorTool and resolved the conflicts that were shown

@nbiederbeck nbiederbeck requested review from maxnoe and kosack August 3, 2021 14:49
@kosack
Copy link
Contributor

kosack commented Aug 3, 2021

The only issue I have here is that these configs really are examples, that the user may want to take and modify, not just used for testing. They are supposed to define the reference analysis. So perhaps we should keep two copies of them? One for tests, and one for examples? Otherwise they are now hard to find.

Or perhaps better yet: we could make a Tool that sets up a directory for user analysis (ctapipe-quickstart or something), that writes a copy of the standard configs to a user-specified directory with a README. It could even fetch some example files. Essentially, it would set up a working directory with templates for the configs. For now, it could be simple, but later it could have some more options. There is also ProcessorTool().generate_config_file() (a feature from trailets.config that generates a commented config file, but only in Python format).

To start it could be really simple: it has no options other than --directory which defaults to ".". A user would just run:

% ls

% ctapipe-quickstart 
% ls 
stage1_config.json  stage2_config.json  training_config.json

And it would internally get the files using the package resources and writes them to the directory.

@kosack
Copy link
Contributor

kosack commented Aug 3, 2021

By the way, could we not just put these configs on the datatserver in the latest version of ctapipe-extra like we do with all other testing files? Thatt would make this PR unneeded, since you could just use get_dataset_path("stage1_config.json") ? Then we could still use a quickstart tool to download them from the command-line, but the test would work automatically

@maxnoe
Copy link
Member

maxnoe commented Aug 3, 2021

By the way, could we not just put these configs on the datatserver in the latest version of ctapipe-extra like we do with all other testing files?

I guess that these files will need updates more often than data files. Which makes putting them on the data server really suboptimal, since only very limited number of people have access to them and somebody preparing a PR that needs configs to be adjusted cannot do it while developing. Also, these are small text files, so are well suited for git.

Copy link
Contributor

@kosack kosack left a comment

Choose a reason for hiding this comment

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

Ok let's merge this then, and I'll open a PR for a tool to extract them for users,.

@kosack kosack merged commit 54fa679 into cta-observatory:master Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Relative path to config file in tests
3 participants