Skip to content

Commit

Permalink
protcur setup.py more data file tweaks
Browse files Browse the repository at this point in the history
add more possible locations for the units and tags folders
  • Loading branch information
tgbugs committed Oct 30, 2019
1 parent afe3a64 commit 4997e48
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
4 changes: 2 additions & 2 deletions protcur/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
recursive-include test *
recursive-include units *.rkt
recursive-include resources *.rkt
include README.org
exclude MANIFEST.in
exclude units/parsing.rkt
exclude resources/units/parsing.rkt
recursive-exclude *.egg-info *
recursive-exclude * *.pyc
recursive-exclude * *.swp
Expand Down
34 changes: 33 additions & 1 deletion protcur/protcur/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import sys
from pathlib import Path

__script_folder__ = Path(__file__).resolve().parent

# units
__units_folder__ = Path(__script_folder__, '../../protc-lib/protc/units')

if not __units_folder__.exists():
__units_folder__ = Path('/usr/share')
_attempts = [
Path(__script_folder__, '../resources/units'),
Path(sys.prefix, 'share', 'protcur', 'units'),
]
for attempt in _attempts:
if attempt.exists():
__units_folder__ = attempt
break
else:
raise FileNotFoundError('no units folder was found at any of\n'
f'{[__units_folder__] + _attempts}')

__units_test_folder__ = __units_folder__ / 'test'
__units_test_params__ = __units_test_folder__ / 'params.rkt'

# tags
__tags_folder__ = Path(__script_folder__, '../../.')
if not (__tags_folder__ / 'protc-tags.rkt').exists():
_attempts = [
Path(__script_folder__, '../resources'),
Path(sys.prefix, 'share', 'protcur'),
]
for attempt in _attempts:
if (attempt / 'protc-tags.rkt').exists():
__tags_folder__ = attempt
break
else:
raise FileNotFoundError('no tags folder was found at any of\n'
f'{[__tags_folder__] + _attempts}')

__anno_tags__ = __tags_folder__ / 'anno-tags.rkt'
__protc_tags__ = __tags_folder__ / 'protc-tags.rkt'
7 changes: 4 additions & 3 deletions protcur/protcur/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from hyputils.handlers import helperSyncHandler, filterHandler
from pysercomb.parsers import racket
from pyontutils.utils import anyMembers, makeSimpleLogger
from protcur.config import __script_folder__
from protcur.config import __anno_tags__ as anno_tags
from protcur.config import __protc_tags__ as protc_tags

log = makeSimpleLogger('protcur')
logd = log.getChild('data')
Expand Down Expand Up @@ -174,9 +175,9 @@ def addDocLinks(base_url, doc):


def readTagDocs():
with open(f'{__script_folder__}/../../protc-tags.rkt', 'rt') as f:
with open(protc_tags, 'rt') as f:
text = f.read()
with open(f'{__script_folder__}/../../anno-tags.rkt', 'rt') as f:
with open(anno_tags, 'rt') as f:
text += f.read()
success, docs, rest = racket.tag_docs(text)
if rest:
Expand Down
27 changes: 21 additions & 6 deletions protcur/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ def find_version(filename):
RELEASE = '--release' in sys.argv
if RELEASE:
sys.argv.remove('--release')
from protcur.config import __anno_tags__, __protc_tags__
from protcur.config import __units_folder__, __units_test_folder__

units = [p.name for p in __units_folder__.iterdir()
if p.is_file() and p.name != 'parsing.rkt' and p.suffix == '.rkt']
units_test = [p.parent.name + '/' + p.name
units_test = [p.parent.parent.name + '/' + p.parent.name + '/' + p.name
for p in __units_test_folder__.iterdir()
if p.is_file() and p.suffix == '.rkt']
shutil.copytree(__units_folder__, 'units')
data_files=[('protcur/units', units),
('protcur/units/test', units_test)]

shutil.copytree(__units_folder__, 'resources/units')
shutil.copy(__anno_tags__, 'resources')
shutil.copy(__protc_tags__, 'resources')

ru = Path('resources', 'units')
if ru.exists(): # release or running from sdist not in git
data_files = [
('share/protcur', ['resources/anno-tags.rkt',
'resources/protc-tags.rkt']),
('share/protcur/units', [p.as_posix() for p in ru.glob('*.rkt')
if p.name != 'parsing.rkt']),
('share/protcur/units/test', [p.as_posix() for p in (ru / 'test').glob('*.rkt')]),]
else:
data_files = []

Expand All @@ -40,7 +52,7 @@ def find_version(filename):
try:
setup(name='protcur',
version=__version__,
description='A dashboard for web annotation workflows for protocol curation.',
description='Web annotation workflows for protocol curation.',
long_description=long_description,
long_description_content_type='text/plain',
url='https://github.com/tgbugs/protc/tree/master/protcur',
Expand All @@ -65,6 +77,7 @@ def find_version(filename):
},
entry_points={
'console_scripts': [
'protcur=protcur.cli:main',
'protcur-server=protcur.server:main',
'protcur-analysis=protcur.analysis:main',
],
Expand All @@ -73,4 +86,6 @@ def find_version(filename):
)
finally:
if RELEASE:
shutil.rmtree('units')
shutil.rmtree('resources/units')
Path('resources', __anno_tags__.name).unlink()
Path('resources', __protc_tags__.name).unlink()
6 changes: 6 additions & 0 deletions protcur/test/test_data_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ def test_exists_units(self):
def test_exists_test_params(self):
from protcur.config import __units_test_params__ as test_params
assert test_params.exists(), test_params

def test_exists_tags(self):
from protcur.config import __anno_tags__ as anno_tags
from protcur.config import __protc_tags__ as protc_tags
assert anno_tags.exists()
assert protc_tags.exists()

0 comments on commit 4997e48

Please sign in to comment.