Skip to content

Commit

Permalink
Switched from using setup.py to pyproject.toml
Browse files Browse the repository at this point in the history
Added build dependency to setuptools_scm
Use setuptools_scm to set the version
  • Loading branch information
tcezard committed Jul 17, 2024
1 parent bc047ac commit d118030
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python setup.py install
python -m pip install .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json

# PyCharm
.idea/

#setuptools_scm version file
_version.py
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ RUN curl -L "https://github.com/nextflow-io/nextflow/releases/download/v${NXF_VE

COPY . /opt/

RUN pip install .
RUN python -m pip install .
13 changes: 11 additions & 2 deletions eva_sub_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
ETC_DIR = os.path.join(PACKAGE_DIR, 'etc')
LSRI_CLIENT_ID = "aa0fcc42-096a-4f9d-b871-aceb1a97d174"

__version__ = open(os.path.join(PACKAGE_DIR, 'VERSION')).read().strip()

SUB_CLI_CONFIG_FILE = ".eva_sub_cli_config.yml"

# Environment variable
SUBMISSION_WS_VAR = 'SUBMISSION_WS_URL'
ENA_WEBIN_ACCOUNT_VAR = 'ENA_WEBIN_ACCOUNT'
ENA_WEBIN_PASSWORD_VAR = 'ENA_WEBIN_PASSWORD'


try:
# If setuptools_scm is installed we can get the version directly from it
from setuptools_scm import get_version
__version__ = get_version(root='..', relative_to=__file__)
del get_version
except:
# otherwise assume that we're working in a deployed instance which should have the _version file
from ._version import version as __version__


Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

import argparse
import gzip
import hashlib
Expand Down Expand Up @@ -186,6 +184,3 @@ def main():
results = assess_fasta(args.input_fasta, analyses, metadata_insdc)
write_result_yaml(args.output_yaml, results)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ def main():
checker = SemanticMetadataChecker(metadata)
checker.check_all()
checker.write_result_yaml(args.output_yaml)


if __name__ == "__main__":
main()
12 changes: 3 additions & 9 deletions bin/eva-sub-cli.py → eva_sub_cli/executables/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
import sys

import eva_sub_cli
from eva_sub_cli.exceptions.submission_not_found_exception import SubmissionNotFoundException
from eva_sub_cli.exceptions.submission_status_exception import SubmissionStatusException

Expand Down Expand Up @@ -36,15 +36,9 @@ def validate_command_line_arguments(args, argparser):
sys.exit(1)


def get_version():
base_dir = os.path.abspath(os.path.dirname(main.__file__))
version = open(os.path.join(base_dir, 'VERSION')).read().strip()
return f'{version}'


if __name__ == "__main__":
def main():
argparser = ArgumentParser(prog='eva-sub-cli', description='EVA Submission CLI - validate and submit data to EVA')
argparser.add_argument('--version', action='version', version=f'%(prog)s {get_version()}')
argparser.add_argument('--version', action='version', version=f'%(prog)s {eva_sub_cli.__version__}')
argparser.add_argument('--submission_dir', required=True, type=str,
help='Full path to the directory where all processing will be done '
'and submission info is/will be stored')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
import argparse
import gzip
import json
Expand Down Expand Up @@ -149,7 +148,3 @@ def main():
args = arg_parser.parse_args()
logging_config.add_stdout_handler()
check_sample_name_concordance(args.metadata_json, args.vcf_files, args.output_yaml)


if __name__ == "__main__":
main()
5 changes: 0 additions & 5 deletions bin/xlsx2json.py → eva_sub_cli/executables/xlsx2json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
import argparse
import datetime
import json
Expand Down Expand Up @@ -368,7 +367,3 @@ def main():
parser.add_error(e)
finally:
parser.save_errors(args.errors_yaml)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions eva_sub_cli/jinja_templates/html_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</div>
<div class="title">
<h1>Validation Report</h1>
<h6>eva-sub-cli v{{cli_version}}</h6>
</div>
</header>

Expand Down
3 changes: 3 additions & 0 deletions eva_sub_cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from jinja2 import Environment, FileSystemLoader

import eva_sub_cli

current_dir = os.path.dirname(__file__)


Expand All @@ -22,6 +24,7 @@ def generate_html_report(validation_results, validation_date, submission_dir, vc
loader=FileSystemLoader(os.path.join(current_dir, 'jinja_templates'))
).get_template('html_report.html')
rendered_template = template.render(
cli_version=eva_sub_cli.__version__,
logo_data=get_logo_data(),
project_title=project_title,
validation_date=validation_date,
Expand Down
1 change: 0 additions & 1 deletion eva_sub_cli/validators/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ def get_vcf_fasta_analysis_mapping(self):
else:
self.error('Error building validation report : Metadata file not present')


def create_reports(self):
report_html = generate_html_report(self.results, self.validation_date, self.submission_dir,
self.get_vcf_fasta_analysis_mapping(), self.project_title)
Expand Down
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[build-system]
requires = [
"setuptools >= 64",
"setuptools_scm[toml] >= 8",
"setuptools_scm_git_archive",
"wheel >= 0.29.0",
]
build-backend = 'setuptools.build_meta'

[project]
name = 'eva_sub_cli'
description = 'EBI EVA - validation and submission command line tool'
dynamic = ["version", 'requires-python']
readme = 'README.md'
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Communications :: File Sharing',
'License :: OSI Approved :: Apache',
]
[project.scripts]
'eva-sub-cli.py'='eva_sub_cli.executables.cli:main'
'check_fasta_insdc.py'='eva_sub_cli.executables.check_fasta_insdc:main'
'check_metadata_semantics.py'='eva_sub_cli.executables.check_metadata_semantics:main'
'samples_checker.py'='eva_sub_cli.executables.samples_checker:main'
'xlsx2json.py'='eva_sub_cli.executables.xlsx2json:main'

[tool.setuptools]
packages = ['eva_sub_cli', 'eva_sub_cli.executables']

[tool.setuptools.package-data]
'eva_sub_cli'=['nextflow/*', 'etc/*', 'jinja_templates/*']

[tool.setuptools.dynamic]
dependencies = {file = 'requirements.txt'}


[tool.setuptools_scm]
write_to = 'eva_sub_cli/_version.py'

10 changes: 8 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[metadata]
description-file = README.md

[zest.releaser]
tag-format = v{version}
Expand All @@ -12,3 +10,11 @@ ignore =
tests/*/*/*/*
.gitlab-ci.yml

[options]
zip_safe = False
platforms = any
include_package_data = True
python_requires = >=3.6
setup_requires =
setuptools_scm

56 changes: 31 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import glob
from distutils.core import setup
from os.path import join, abspath, dirname
from setuptools import find_packages

base_dir = abspath(dirname(__file__))
requirements_txt = join(base_dir, 'requirements.txt')
requirements = [l.strip() for l in open(requirements_txt) if l and not l.startswith('#')]

version = open(join(base_dir, 'eva_sub_cli', 'VERSION')).read().strip()
import setuptools
from setuptools import find_packages
#
# base_dir = abspath(dirname(__file__))
# requirements_txt = join(base_dir, 'requirements.txt')
# requirements = [l.strip() for l in open(requirements_txt) if l and not l.startswith('#')]
#
# version = open(join(base_dir, 'eva_sub_cli', 'VERSION')).read().strip()
#
# setup(
# name='eva_sub_cli',
# packages=find_packages(),
# package_data={'eva_sub_cli': ['nextflow/*', 'etc/*', 'VERSION', 'jinja_templates/*']},
# use_scm_version={'write_to': 'eva_sub_cli/_version.py'},
# license='Apache',
# description='EBI EVA - validation and submission command line tool',
# url='https://github.com/EBIvariation/eva-sub-cli',
# keywords=['ebi', 'eva', 'python', 'submission', 'validation'],
# install_requires=requirements,
# setup_requires=['setuptools_scm'],
# classifiers=[
# 'Development Status :: 5 - Production/Stable',
# 'Intended Audience :: Science/Research',
# 'Topic :: Communications :: File Sharing',
# 'License :: OSI Approved :: Apache Software License',
# 'Programming Language :: Python :: 3'
# ],
# scripts=glob.glob(join(dirname(__file__), 'bin', '*.py'))
# )

setup(
name='eva_sub_cli',
packages=find_packages(),
package_data={'eva_sub_cli': ['nextflow/*', 'etc/*', 'VERSION', 'jinja_templates/*']},
version=version,
license='Apache',
description='EBI EVA - validation and submission command line tool',
url='https://github.com/EBIvariation/eva-sub-cli',
keywords=['ebi', 'eva', 'python', 'submission', 'validation'],
install_requires=requirements,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'Topic :: Communications :: File Sharing',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3'
],
scripts=glob.glob(join(dirname(__file__), 'bin', '*.py'))
)
if __name__ == "__main__":
setuptools.setup()
2 changes: 1 addition & 1 deletion tests/resources/validation_reports/expected_report.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions tests/test_check_fasta_insdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import requests as requests

from bin.check_fasta_insdc import assess_fasta, get_analyses_and_reference_genome_from_metadata
from eva_sub_cli.executables.check_fasta_insdc import assess_fasta, get_analyses_and_reference_genome_from_metadata


class TestFastaChecker(TestCase):
Expand All @@ -20,8 +20,8 @@ def test_get_analysis_and_reference_genome_from_metadata(self):

def test_assess_fasta_is_insdc(self):
input_fasta = os.path.join(self.resource_dir, 'fasta_files', 'Saccharomyces_cerevisiae_I.fa')
with patch('bin.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('bin.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
with patch('eva_sub_cli.executables.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('eva_sub_cli.executables.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
m_get_refget.return_value = {'sequence_name': 'chr1'}
m_get_assemblies.return_value = {'GCA_000146045.2'}
results = assess_fasta(input_fasta, ['analysis'], None)
Expand All @@ -30,8 +30,8 @@ def test_assess_fasta_is_insdc(self):
'sequences': [{'sequence_name': 'I', 'sequence_md5': '6681ac2f62509cfc220d78751b8dc524', 'insdc': True}],
'possible_assemblies': {'GCA_000146045.2'}
}
with patch('bin.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('bin.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
with patch('eva_sub_cli.executables.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('eva_sub_cli.executables.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
m_get_refget.return_value = None
m_get_assemblies.return_value = set()
results = assess_fasta(input_fasta, ['analysis'], None)
Expand All @@ -42,8 +42,8 @@ def test_assess_fasta_is_insdc(self):

def test_assess_fasta_matches_metadata(self):
input_fasta = os.path.join(self.resource_dir, 'fasta_files', 'Saccharomyces_cerevisiae_I.fa')
with patch('bin.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('bin.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
with patch('eva_sub_cli.executables.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('eva_sub_cli.executables.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
m_get_refget.return_value = {'sequence_name': 'I'}
m_get_assemblies.return_value = {'GCA_000146045.2'}
results = assess_fasta(input_fasta, ['analysis'], 'GCA_000146045.2')
Expand All @@ -69,8 +69,8 @@ def test_assess_fasta_matches_metadata(self):

def test_assess_fasta_http_error(self):
input_fasta = os.path.join(self.resource_dir, 'fasta_files', 'Saccharomyces_cerevisiae_I.fa')
with patch('bin.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('bin.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
with patch('eva_sub_cli.executables.check_fasta_insdc.get_refget_metadata', autospec=True) as m_get_refget, \
patch('eva_sub_cli.executables.check_fasta_insdc._get_containing_assemblies_paged', autospec=True) as m_get_assemblies:
m_get_refget.return_value = {'sequence_name': 'I'}
m_get_assemblies.side_effect = requests.HTTPError('500 Internal Server Error')
results = assess_fasta(input_fasta, ['analysis'], None)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
from unittest import TestCase

import eva_sub_cli
from eva_sub_cli.report import generate_html_report

validation_results = {
Expand Down Expand Up @@ -190,7 +191,10 @@ def test_generate_html_report(self):
open_file.write(report)

with open(self.expected_report) as open_html:
assert report == open_html.read()
expected_report_text = open_html.read()
# Inject the version in the expected report
expected_report_text = expected_report_text.replace('cligeneratedversion', eva_sub_cli.__version__)
assert report == expected_report_text

# Remove output file if assert passes
if os.path.exists('report.html'):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_samples_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import yaml

from bin.samples_checker import check_sample_name_concordance
from eva_sub_cli.executables.samples_checker import check_sample_name_concordance


class TestSampleChecker(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xlsx2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import yaml

from eva_sub_cli import ETC_DIR
from bin.xlsx2json import XlsxParser, create_xls_template_from_yaml
from eva_sub_cli.executables.xlsx2json import XlsxParser, create_xls_template_from_yaml


class TestXlsReader(TestCase):
Expand Down

0 comments on commit d118030

Please sign in to comment.