move data files to package directory

- The former location of the data files, /usr/local/share/mmgen, is no longer
  used and may be safely deleted.
This commit is contained in:
The MMGen Project 2021-09-23 21:15:32 +00:00
commit ea81d466a8
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 20 additions and 38 deletions

View file

@ -1,3 +1,5 @@
include mmgen/data/*
include README.md SIGNING_KEYS.pub LICENSE INSTALL
include doc/wiki/using-mmgen/*

View file

@ -187,12 +187,24 @@ class CfgFileSampleSys(CfgFileSample):
desc = 'system sample configuration file'
test_fn_subdir = 'usr.local.share'
@property
def fn_dir(self):
def __init__(self):
if os.getenv('MMGEN_TEST_SUITE_CFGTEST'):
return os.path.join(g.data_dir_root,self.test_fn_subdir)
self.fn = os.path.join(g.data_dir_root,self.test_fn_subdir,self.fn_base)
self.data = open(self.fn).read().splitlines()
else:
return g.shared_data_path
# self.fn is used for error msgs only, so file need not exist on filesystem
self.fn = os.path.join(os.path.dirname(__file__),'data',self.fn_base)
# Resource will be unpacked and then cleaned up if necessary, see:
# https://docs.python.org/3/library/importlib.html:
# Note: This module provides functionality similar to pkg_resources Basic
# Resource Access without the performance overhead of that package.
# https://importlib-resources.readthedocs.io/en/latest/migration.html
# https://setuptools.readthedocs.io/en/latest/pkg_resources.html
try:
from importlib.resources import files # Python 3.9
except ImportError:
from importlib_resources import files
self.data = files('mmgen').joinpath('data',self.fn_base).read_text().splitlines()
def make_metadata(self):
return ['# Version {} {}'.format(self.cur_ver,self.computed_chksum)]

View file

@ -145,14 +145,6 @@ class GlobalContext(Lockable):
else:
die(2,'$HOME is not set! Unable to determine home directory')
# https://wiki.debian.org/Python:
# Debian (Ubuntu) sys.prefix is '/usr' rather than '/usr/local, so add 'local'
# This must match the configuration in setup.py
shared_data_path = os.path.join(
sys.prefix,
*(['local','share'] if platform == 'linux' else ['share']),
proj_name.lower()
)
data_dir_root,data_dir,cfg_file = None,None,None
daemon_data_dir = '' # set by user
daemon_id = ''

View file

@ -66,12 +66,6 @@ def link_or_copy(tdir,a,b):
copy_owner(a,b)
os.chdir(cwd)
class my_install(install):
def run(self):
for f in 'mmgen.cfg','mnemonic.py','mn_wordlist.c':
os.chmod(os.path.join('data_files',f),0o644) # required if user has non-standard umask
install.run(self)
class my_build_py(build_py):
def run(self):
link_or_copy('test','start-coin-daemons.py','stop-coin-daemons.py')
@ -100,19 +94,12 @@ setup(
platforms = 'Linux, Debian, Ubuntu, Arch Linux, MS Windows, Raspberry Pi/Raspbian, Orange Pi/Armbian, Rock Pi/Armbian',
keywords = g.keywords,
cmdclass = {
'install': my_install,
'build_py': my_build_py,
'build_ext': my_build_ext,
},
ext_modules = [module1],
# TODO:
# https://setuptools.readthedocs.io/en/latest/references/keywords.html:
# data_files is deprecated. It does not work with wheels, so it should be avoided.
data_files = [('share/mmgen', [
'data_files/mmgen.cfg', # source files must have 0644 mode
'data_files/mn_wordlist.c',
'data_files/mnemonic.py'
]),],
packages = ['mmgen'],
include_package_data = True,
py_modules = [
'mmgen.__init__',
'mmgen.addr',

View file

@ -24,7 +24,6 @@ class TestSuiteCfg(TestSuiteBase):
color = True
cmd_group = (
('nosysfile', (40,'init with missing system cfg sample file', [])),
('sysfile', (40,'init with system cfg sample file in place', [])),
('no_metadata_sample', (40,'init with unversioned cfg sample file', [])),
('altered_sample', (40,'init with user-modified cfg sample file', [])),
@ -56,16 +55,6 @@ class TestSuiteCfg(TestSuiteBase):
'sample': '{}/data_dir/mmgen.cfg.sample'.format(self.tmpdir),
}[id_str]
def nosysfile(self):
t = self.spawn_test()
errstr = CfgFile.file_not_found_fs.format(CfgFileSampleSys.desc,self.path('shared_data')+'/mmgen.cfg')
t.expect(errstr)
for k in ('usr','sys','sample'):
t.expect('{} cfg file:\s+{}'.format(capfirst(k),self.path(k)),regex=True)
assert not os.path.exists(self.path(k)), self.path(k)
t.read()
return t
def copy_sys_sample(self):
os.makedirs(self.path('shared_data'),exist_ok=True)
shutil.copy2(self.path('ref'),self.path('sys'))