Skip to content
Snippets Groups Projects
Commit ead472b1 authored by Françoise Conil's avatar Françoise Conil
Browse files

Base project without data files

parents
No related branches found
No related tags found
No related merge requests found
LICENSE 0 → 100644
MIT License
Copyright (c) 2022 Françoise CONIL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Test package for resources import
Inspired by the following tutorial :
- https://realpython.com/python-import/#resource-imports
Official import documentation :
- https://docs.python.org/3/library/importlib.resources.html
Packaging informations :
- https://packaging.python.org/en/latest/tutorials/packaging-projects/
- https://choosealicense.com/
[build-system]
requires = ["flit_core>=3.2"]
build-backend = "flit_core.buildapi"
[project]
name = "import-resources-example"
version = "0.0.1"
authors = [
{ name="Françoise CONIL", email="francoise.conil@cnrs.fr" },
]
description = "A small example package to test resources import"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
"Homepage" = "https://gitlab.liris.cnrs.fr/fconil-small-programs/python/bases/import-resources-example"
"Bug Tracker" = "https://gitlab.liris.cnrs.fr/fconil-small-programs/python/bases/import-resources-example/issues"
import csv
from importlib import resources
def get_oms_data():
"""
$ csvcut -n COVID19-web.27-07-2022.csv
1: TrialID
2: Last Refreshed on
3: Public title
4: Scientific title
5: Acronym
6: Primary sponsor
7: Date registration
8: Date registration3
9: Export date
10: Source Register
11: web address
12: Recruitment Status
13: other records
14: Inclusion agemin
15: Inclusion agemax
16: Inclusion gender
17: Date enrollement
18: Target size
19: Study type
20: Study design
21: Phase
22: Countries
23: Contact Firstname
24: Contact Lastname
25: Contact Address
26: Contact Email
27: Contact Tel
28: Contact Affiliation
29: Inclusion Criteria
30: Exclusion Criteria
31: Condition
32: Intervention
33: Primary outcome
34: results date posted
35: results date completed
36: results url link
37: Retrospective flag
38: Bridging flag truefalse
39: Bridged type
40: results yes no
"""
studies = []
with resources.open_text("example_package_import.data", "COVID19-web.27-07-2022.csv") as f:
rows = csv.DictReader(f)
for row in rows:
studies.append(
{
"TrialID": row["TrialID"],
"Public-title": row["Public title"],
"Date-registration": row["Date registration"],
"Source-Register": row["Source Register"],
"Recruitment-Status": row["Recruitment Status"],
"Study type": row["Study type"]
}
)
return studies
import csv
from importlib import resources
def extract_population_general_info():
general_info = {}
locations = set()
with resources.open_text("example_package_import.data", "WPP2022_TotalPopulationBySex.csv") as f:
rows = csv.DictReader(f)
for row in rows:
current_location = row["Location"]
if current_location not in locations:
locations.add(current_location)
general_info[current_location] = {
"Time": row["Time"],
"PopTotal": row["PopTotal"],
"PopDensity": row["PopDensity"]
}
return general_info
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment